Exemplo n.º 1
0
 def __setstate__(self, state):
     soname = state.pop('_soname', None)
     binary = state.pop('binary', None)
     for k, v in state.items():
         setattr(self, k, v)
     # If the `sonames` don't match, there *might* be a hidden bug as the
     # unpickled Operator might be generating code that differs from that
     # generated by the pickled Operator. For example, a stupid bug that we
     # had to fix was due to rebuilding SymPy expressions which weren't
     # automatically getting the flag `evaluate=False`, thus producing x+2
     # on the unpickler instead of x+1+1).  However, different `sonames`
     # doesn't necessarily means there's a bug: if the unpickler and the
     # pickler are two distinct processes and the unpickler runs with a
     # different `configuration` dictionary, then the `sonames` might indeed
     # be different, depending on which entries in `configuration` differ.
     if soname is not None:
         if soname != self._soname:
             warning(
                 "The pickled and unpickled Operators have different .sonames; "
                 "this might be a bug, or simply a harmless difference in "
                 "`configuration`. You may check they produce the same code."
             )
         save(self._soname, binary, self._compiler)
         self._lib = load(self._soname)
         self._lib.name = self._soname
Exemplo n.º 2
0
    def cfunction(self):
        """The JIT-compiled C function as a ctypes.FuncPtr object."""
        if self._lib is None:
            self._compile()
            self._lib = load(self._soname)
            self._lib.name = self._soname

        if self._cfunction is None:
            self._cfunction = getattr(self._lib, self.name)
            # Associate a C type to each argument for runtime type check
            self._cfunction.argtypes = [i._C_ctype for i in self.parameters]

        return self._cfunction
Exemplo n.º 3
0
    def cfunction(self):
        """The JIT-compiled C function as a ctypes.FuncPtr object."""
        if self._lib is None:
            self._compile()
            self._lib = load(self._soname)
            self._lib.name = self._soname

        if self._cfunction is None:
            self._cfunction = getattr(self._lib, self.name)
            # Associate a C type to each argument for runtime type check
            self._cfunction.argtypes = [i._C_ctype for i in self.parameters]

        return self._cfunction
Exemplo n.º 4
0
    def cfunction(self):
        """Returns the JIT-compiled C function as a ctypes.FuncPtr object."""
        if self._lib is None:
            basename = self.compile
            self._lib = load(basename, configuration['compiler'])
            self._lib.name = basename

        if self._cfunction is None:
            self._cfunction = getattr(self._lib, self.name)
            argtypes = [
                c_int if isinstance(v, Dimension) else np.ctypeslib.ndpointer(
                    dtype=v.dtype, flags='C') for v in self.parameters
            ]
            self._cfunction.argtypes = argtypes

        return self._cfunction
Exemplo n.º 5
0
    def cfunction(self):
        """Returns the JIT-compiled C function as a ctypes.FuncPtr object."""
        if self._lib is None:
            basename = self.compile
            self._lib = load(basename, self._compiler)
            self._lib.name = basename

        if self._cfunction is None:
            self._cfunction = getattr(self._lib, self.name)
            # Associate a C type to each argument for runtime type check
            argtypes = []
            for i in self.parameters:
                if i.is_ScalarArgument:
                    argtypes.append(numpy_to_ctypes(i.dtype))
                elif i.is_TensorArgument:
                    argtypes.append(np.ctypeslib.ndpointer(dtype=i.dtype, flags='C'))
                else:
                    argtypes.append(ctypes.c_void_p)
            self._cfunction.argtypes = argtypes

        return self._cfunction