Example #1
0
    def __init__(self, func, local, variables, param, dtype=None, **kwargs):
        self.func = func
        self.code = get_function_code(func)
        self.dtype = 'float' if dtype == np.float32 else 'double'
        self.local = local
        self.param = param
        self.variables = variables
        self.float_char = 'f' if dtype == np.float32 else ''
        self.func_globals = get_function_globals(self.func)

        self.used_variables = set()

        CodeGenerator.__init__(self, self.func, newline=';\n', offset=4, \
            ostream=StringIO())

        self.generate()
        self.generate_signature()

        fname = self.func.__name__

        self.definition = template_device_func.render(
            dtype = self.dtype,
            name = fname,
            local = self.local,
            signature = self.signature,
            used = self.used_variables,
            src = self.ostream.getvalue()
        )
        self.invocation = "{}({});".format(fname, ", ".join(self.args))
Example #2
0
    def __init__(self, model, func, dtype, **kwargs):
        self.dtype = dtype
        self.model = model
        self.func = func

        self.float_char = 'f' if self.dtype == 'float' else ''

        self.params_gdata = kwargs.pop('params_gdata', [])
        self.inputs = kwargs.pop('inputs', dict())

        self.variables = []
        self.has_random = False
        self.func_globals = get_function_globals(self.func)

        CodeGenerator.__init__(self,
                               self.func,
                               newline=';\n',
                               offset=4,
                               ostream=StringIO(),
                               **kwargs)

        _, self.signature, self.kwargs = self.extract_signature(self.func)
        self.generate()

        self.args = self.process_signature()
        self.src = self.ostream.getvalue()
Example #3
0
    def __init__(self, func, variables = None, backend=None, **kwargs):
        self.func = func
        self.code = get_function_code(func)
        self.backend = backend or None
        self.variables = variables or dict()

        CodeGenerator.__init__(self, self.func,  offset=4, ostream=StringIO())
Example #4
0
    def __init__(self, model, func, **kwargs):
        self.model = model
        self.func = func
        CodeGenerator.__init__(self, self.func, **kwargs)

        args = get_func_signature(self.func)
        signature = "def {}({}):\n".format(self.func.__name__, ", ".join(args))
        self.ostream.write(signature)
Example #5
0
    def __init__(self, model, **kwargs):
        self.model = model
        self._dependencies = set()

        _, self.signature, self.kwargs = self._extract_signature(
            self.model.ode)
        with open(os.devnull, 'w') as f:
            code = get_function_code(model.ode)
            CodeGenerator.__init__(self, code, ostream=f)
            self.variables = {}
            self.generate()
            self.generate()
        for key, val in self.variables.items():
            if val.integral is None:
                continue
            self.variables[val.integral].dependencies.update(val.dependencies)
Example #6
0
    def __init__(self, func, defaults, **kwargs):
        self.func = func
        self.code = get_function_code(func)
        self.defaults = defaults

        self.globals = get_function_globals(self.func)

        inputs = self._extract_signature(func)
        self.variables = kwargs.pop('variables', dict())
        self.locals = kwargs.pop('locals', dict())

        for key, val in inputs:
            self.variables[key] = _Variable(type='input', value=val, name=key)

        with open(os.devnull, 'w') as f:
            CodeGenerator.__init__(self, func, ostream=f)

            self.generate()
Example #7
0
 def _post_output(self):
     self.newline = ';\n'
     CodeGenerator._post_output(self)
Example #8
0
 def _post_output(self):
     self.newline = ";\n"
     CodeGenerator._post_output(self)