Commits

Takafumi Arakaki  committed 7d4e72c

fixed #3 so now cm.*() can take list or generator. test and sample are added

  • Participants
  • Parent commits 5f5d631

Comments (0)

Files changed (3)

File railgun/__init__.py

     """
     def cmem(*args):
         if len(args) == 1:
-            args = args[0].split(',')
+            if isinstance(args[0], basestring):
+                args = args[0].split(',')
+            else:
+                args = args[0]  # assume the first argument is iterative
         return ['%s %s' % (cdt, v.strip()) for v in args]
     func_name = funcfmt % cdt
     cmem.func_name = func_name

File samples/lode_rk4/lode_rk4.py

         'double a[d][d]',  # num_d x num_d array
         'double x[s][d]',  # num_s x num_d array
     ] + (
-        cm.double(*['k%s[d]' % s for s in '1234']) +
-        cm.double(*['x%s[d]' % s for s in '123']) +
-        cm.double(*['k%s_debug[s][d]' % s for s in '1234']) +
-        cm.double(*['x%s_debug[s][d]' % s for s in '123'])
+        cm.double('k%s[d]' % s for s in '1234') +
+        cm.double('x%s[d]' % s for s in '123') +
+        cm.double('k%s_debug[s][d]' % s for s in '1234') +
+        cm.double('x%s_debug[s][d]' % s for s in '123')
     )
     _cfuncs_ = ["x run_{mode | normal, debug}()"]
     _cmemsubsets_ = dict(

File tests/test_utils.py

+from nose.tools import eq_
+
+from railgun import cm
+
+
+def test_cm():
+    desired = ['int a', 'int b', 'int c']
+    eq_(cm.int('a', 'b', 'c'), desired)
+    eq_(cm.int('a, b, c'), desired)
+    eq_(cm['int']('a', 'b', 'c'), desired)
+
+    eq_(cm['int'](['a', 'b', 'c']), desired)
+    eq_(cm['int'](i for i in ['a', 'b', 'c']), desired)