In [2]:
from dynd import nd, ndt
In [3]:
@nd.functional.elwise
def f(x, y, z) -> ndt.float64:
return 2 * x + y - z
f
Out[3]:
In [4]:
f([0, 3, 5], 2.5, [5, 10, 15])
Out[4]:
In [3]:
@nd.functional.reduction
def f(x, y) -> ndt.int32:
return max(x, y)
f
Out[3]:
In [4]:
f([-5, 5, -3, 7, 2, -1])
Out[4]:
In [5]:
f([-5, 5, -3, 7, 2, -1], identity = 101)
Out[5]:
In [8]:
import math
@nd.functional.apply
def f_factorial(n: ndt.int32) -> ndt.int32:
return math.factorial(n - 1)
@nd.functional.apply
def f_gamma(x: ndt.float64) -> ndt.float64:
return math.gamma(x)
f = nd.functional.elwise(nd.functional.multidispatch(ndt.type('(Scalar) -> Scalar'), [f_factorial, f_gamma]))
f
Out[8]:
In [9]:
f([5, 4, 3, 2, 1])
Out[9]:
In [10]:
f([5.5, 4.5, 3.5, 2.5, 1.5])
Out[10]:
In [ ]: