Example #1
0
 def step_simpyfunc():
     args = (np.copy(x),) if x is not None else ()
     y = fn(t.item(), *args) if t is not None else fn(*args)
     if output is not None:
         if y is None:  # required since Numpy turns None into NaN
             raise SimulationError(
                 "Function %r returned None" % function_name(self.fn))
         try:
             output[...] = y
         except ValueError:
             raise SimulationError("Function %r returned invalid value "
                                   "%r" % (function_name(self.fn), y))
Example #2
0
    def _label(self):
        if self.label is not None:
            return self.label

        return "from %s to %s%s" % (self.pre, self.post, " computing '%s'" %
                                    function_name(self.function)
                                    if self.function is not None else "")
Example #3
0
    def _str(self):
        if self.label is not None:
            return self.label

        desc = "" if self.function is None else " computing '%s'" % (
            function_name(self.function))
        return "from %s to %s%s" % (self.pre, self.post, desc)
Example #4
0
        def step_simpyfunc():
            args = (np.copy(x), ) if x is not None else ()
            y = fn(t.item(), *args) if t is not None else fn(*args)

            if output is not None:
                try:
                    # required since Numpy turns None into NaN
                    if y is None or not np.all(np.isfinite(y)):
                        raise SimulationError(
                            "Function %r returned non-finite value" %
                            function_name(self.fn))

                    output[...] = y

                except (TypeError, ValueError):
                    raise SimulationError("Function %r returned a value "
                                          "%r of invalid type %r" %
                                          (function_name(self.fn), y, type(y)))
Example #5
0
 def _descstr(self):
     return '%s -> %s, fn=%r' % (
         self.x, self.output, function_name(self.fn))