funclp.ufunc module
- funclp.ufunc(*, variables=None, data=None, parameters=None, constants=None, main=False, fastmath=True)[source]
Decorator class defining universal function factory object from python kernel function, will create kernels, vectorized functions, jitted functions, stack functions, all on CPU / Parallel CPU / GPU.
Examples
>>> from funclp import Parameter, ufunc >>> import numpy as np ... >>> class MyClass() : ... @ufunc(variables=['x', 'y'], data=['constant'], parameters=[Parameter('a', 1), Parameter('b', 0)]) ... def myfunc(x, y, constant, /, a, b) : ... return a * x + b * y + constant ... cuda = False ... >>> instance = MyClass() ... >>> x = np.arange(20).reshape((1, 20)) # Example of variables that can be broadcasted together >>> y = np.arange(20).reshape((20, 1)) # Example of variables that can be broadcasted together >>> constant = np.ones((5, 20, 20)) # Example of data with full shape >>> a = np.arange(5) # Example of parameter vector >>> b = 0.5 # Example of scalar use >>> cpu_out = instance.myfunc(x, y, constant, a=a, b=b) >>> instance.cuda = True >>> gpu_out = instance.myfunc(x, y, constant, a=a, b=b)
…