예제 #1
0
def get_predefined_types(precomp):
    """Return a dictionary that can be used by a CythonGenerator for
    the precomputed symbols.
    """
    result = {'dt': 0.0,
              't': 0.0,
              'dst': KnownType('object'),
              'NBRS': KnownType('unsigned int*'),
              'N_NBRS': KnownType('int'),
              'src': KnownType('ParticleArrayWrapper')}
    for sym, value in precomp.items():
        result[sym] = value.context[sym]
    return result
예제 #2
0
 def get_equation_wrappers(self, known_types={}):
     classes = defaultdict(lambda: 0)
     eqs = {}
     for equation in self.equations:
         cls = equation.__class__.__name__
         n = classes[cls]
         equation.var_name = '%s%d' % (camel_to_underscore(
             equation.name), n)
         classes[cls] += 1
         eqs[cls] = equation
     wrappers = []
     predefined = dict(get_predefined_types(self.pre_comp))
     predefined.update(known_types)
     predefined['NBRS'] = KnownType('__global unsigned int*')
     code_gen = OpenCLConverter(known_types=predefined)
     ignore = ['reduce']
     for cls in sorted(classes.keys()):
         src = code_gen.parse_instance(eqs[cls], ignore_methods=ignore)
         wrappers.append(src)
     return '\n'.join(wrappers)
예제 #3
0
    def test_that_all_types_are_detected_correctly(self):
        x = np.linspace(0, 1, 10)
        pa = ParticleArray(name='f', x=x)
        pa.remove_property('pid')
        info = get_all_array_names([pa])
        result = get_known_types_for_arrays(info)

        expect = {'d_gid': KnownType("unsigned int*"),
                  'd_tag': KnownType("int*"),
                  'd_x': KnownType("double*"),
                  's_gid': KnownType("unsigned int*"),
                  's_tag': KnownType("int*"),
                  's_x': KnownType("double*")}
        for key in expect:
            self.assertEqual(repr(result[key]), repr(expect[key]))