Exemplo n.º 1
0
 def __init__(self, py_func, signature, identity=None, cache=False,
              targetoptions={}):
     self.py_func = py_func
     self.identity = parse_identity(identity)
     self.nb_func = jit(target='npyufunc', cache=cache)(py_func)
     self.signature = signature
     self.sin, self.sout = parse_signature(signature)
     self.targetoptions = targetoptions
     self.cache = cache
     self._sigs = []
     self._cres = {}
Exemplo n.º 2
0
    def __init__(self, func, sig, identity=None, cache=False, targetoptions={}):
        if cache:
            raise TypeError("caching is not supported")
        # Allow nopython flag to be set.
        if not targetoptions.pop('nopython', True):
            raise TypeError("nopython flag must be True")
        # Are there any more target options?
        if targetoptions:
            opts = ', '.join([repr(k) for k in targetoptions.keys()])
            fmt = "The following target options are not supported: {0}"
            raise TypeError(fmt.format(opts))

        self.py_func = func
        self.identity = parse_identity(identity)
        self.signature = sig
        self.inputsig, self.outputsig = parse_signature(self.signature)
        assert len(self.outputsig) == 1, "only support 1 output"
        # { arg_dtype: (return_dtype), cudakernel }
        self.kernelmap = OrderedDict()
Exemplo n.º 3
0
    def _get_signature(self, *args):
        parsed_sig = parse_signature(self.gufunc_builder.signature)
        # ewise_types is a list of [int32, int32, int32, ...]
        ewise_types = self._get_ewise_dtypes(args)

        # first time calling the gufunc
        # generate a signature based on input arguments
        l = []
        for idx, sig_dim in enumerate(parsed_sig[0]):
            ndim = len(sig_dim)
            if ndim == 0:  # append scalar
                l.append(ewise_types[idx])
            else:
                l.append(types.Array(ewise_types[idx], ndim, 'A'))

        # add return type to signature
        retty = ewise_types[-1]
        ret_ndim = len(parsed_sig[-1][0]) or 1  # small hack to return scalar
        l.append(types.Array(retty, ret_ndim, 'A'))

        return types.none(*l)
Exemplo n.º 4
0
 def _num_args_match(self, *args):
     parsed_sig = parse_signature(self.gufunc_builder.signature)
     # parsed_sig[1] has always length 1
     return len(args) == len(parsed_sig[0]) + 1
Exemplo n.º 5
0
 def from_signature(cls, signature):
     return cls(*parse_signature(signature))