Universal Functions (ufunc)¶
CuPy provides universal functions (a.k.a. ufuncs) to support various elementwise operations. CuPy’s ufunc supports following features of NumPy’s one:
- Broadcasting
- Output type determination
- Casting rules
CuPy’s ufunc currently does not provide methods such as reduce
, accumulate
, reduceat
, outer
, and at
.
Ufunc class¶
-
class
cupy.
ufunc
¶ Universal function.
Variables: -
__call__
()¶ Applies the universal function to arguments elementwise.
Parameters: - args – Input arguments. Each of them can be a
cupy.ndarray
object or a scalar. The output arguments can be omitted or be specified by theout
argument. - out (cupy.ndarray) – Output array. It outputs to new arrays default.
- dtype – Data type specifier.
Returns: Output array or a tuple of output arrays.
- args – Input arguments. Each of them can be a
-
types
¶ A list of type signatures.
Each type signature is represented by type character codes of inputs and outputs separated by ‘->’.
-
Available ufuncs¶
Math operations¶
add
subtract
multiply
divide
logaddexp
logaddexp2
true_divide
floor_divide
negative
power
remainder
mod
fmod
absolute
rint
sign
exp
exp2
log
log2
log10
expm1
log1p
sqrt
square
reciprocal
Trigonometric functions¶
sin
cos
tan
arcsin
arccos
arctan
arctan2
hypot
sinh
cosh
tanh
arcsinh
arccosh
arctanh
deg2rad
rad2deg
Bit-twiddling functions¶
bitwise_and
bitwise_or
bitwise_xor
invert
left_shift
right_shift
Comparison functions¶
greater
greater_equal
less
less_equal
not_equal
equal
logical_and
logical_or
logical_xor
logical_not
maximum
minimum
fmax
fmin
ufunc.at¶
Currently, CuPy does not support at
for ufuncs in general.
However, cupy.scatter_add()
can substitute add.at
as both behave identically.