def get_header(self): object = self.object helpers = [] headers = [] headers.extend(get_cython_code(object.kernel)) if hasattr(object.kernel, '_get_helpers_'): helpers.extend(object.kernel._get_helpers_()) # get headers from the Equations for equation in object.all_group.equations: headers.extend(get_cython_code(equation)) if hasattr(equation, '_get_helpers_'): for helper in equation._get_helpers_(): if helper not in helpers: helpers.append(helper) headers.extend(get_helper_code(helpers)) # Kernel wrappers. cg = CythonGenerator(known_types=self.known_types) cg.parse(object.kernel) headers.append(cg.get_code()) # Equation wrappers. self.known_types['SPH_KERNEL'] = KnownType( object.kernel.__class__.__name__) headers.append(object.all_group.get_equation_wrappers( self.known_types)) return '\n'.join(headers)
def get_known_types_for_arrays(array_names): """Given all the array names from `get_all_array_names` this creates known types for each of them so that the code generators can use this type information when needed. Note that known type info is generated for both source and destination style arrays. Parameters ---------- array_names: dict A dictionary produced by `get_all_array_names`. Examples -------- A simple example would be:: >>> x = np.linspace(0, 1, 10) >>> pa = ParticleArray(name='f', x=x) >>> pa.remove_property('pid') >>> info = get_all_array_names([pa]) >>> get_known_types_for_arrays(info) {'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*")} """ result = {} for arr_type, arrays in array_names.items(): c_type = getattr(carray, arr_type)().get_c_type() for arr in arrays: known_type = KnownType(c_type + '*') result['s_' + arr] = known_type result['d_' + arr] = known_type return result