# 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¶

 cupy.ufunc Universal function.

## Available ufuncs¶

### Math operations¶

 cupy.add Adds two arrays elementwise. cupy.subtract Subtracts arguments elementwise. cupy.multiply Multiplies two arrays elementwise. cupy.divide Elementwise true division (i.e. cupy.logaddexp Computes log(exp(x1) + exp(x2)) elementwise. cupy.logaddexp2 Computes log2(exp2(x1) + exp2(x2)) elementwise. cupy.true_divide Elementwise true division (i.e. cupy.floor_divide Elementwise floor division (i.e. cupy.negative Takes numerical negative elementwise. cupy.power Computes x1 ** x2 elementwise. cupy.remainder Computes the remainder of Python division elementwise. cupy.mod Computes the remainder of Python division elementwise. cupy.fmod Computes the remainder of C division elementwise. cupy.absolute Elementwise absolute value function. cupy.rint Rounds each element of an array to the nearest integer. cupy.sign Elementwise sign function. cupy.exp Elementwise exponential function. cupy.exp2 Elementwise exponentiation with base 2. cupy.log Elementwise natural logarithm function. cupy.log2 Elementwise binary logarithm function. cupy.log10 Elementwise common logarithm function. cupy.expm1 Computes exp(x) - 1 elementwise. cupy.log1p Computes log(1 + x) elementwise. cupy.sqrt Elementwise square root function. cupy.square Elementwise square function. cupy.reciprocal Computes 1 / x elementwise. cupy.gcd Computes gcd of x1 and x2 elementwise. cupy.lcm Computes lcm of x1 and x2 elementwise.

### Trigonometric functions¶

 cupy.sin Elementwise sine function. cupy.cos Elementwise cosine function. cupy.tan Elementwise tangent function. cupy.arcsin Elementwise inverse-sine function (a.k.a. cupy.arccos Elementwise inverse-cosine function (a.k.a. cupy.arctan Elementwise inverse-tangent function (a.k.a. cupy.arctan2 Elementwise inverse-tangent of the ratio of two arrays. cupy.hypot Computes the hypoteneous of orthogonal vectors of given length. cupy.sinh Elementwise hyperbolic sine function. cupy.cosh Elementwise hyperbolic cosine function. cupy.tanh Elementwise hyperbolic tangent function. cupy.arcsinh Elementwise inverse of hyperbolic sine function. cupy.arccosh Elementwise inverse of hyperbolic cosine function. cupy.arctanh Elementwise inverse of hyperbolic tangent function. cupy.deg2rad Converts angles from degrees to radians elementwise. cupy.rad2deg Converts angles from radians to degrees elementwise.

### Bit-twiddling functions¶

 cupy.bitwise_and Computes the bitwise AND of two arrays elementwise. cupy.bitwise_or Computes the bitwise OR of two arrays elementwise. cupy.bitwise_xor Computes the bitwise XOR of two arrays elementwise. cupy.invert Computes the bitwise NOT of an array elementwise. cupy.left_shift Shifts the bits of each integer element to the left. cupy.right_shift Shifts the bits of each integer element to the right.

### Comparison functions¶

 cupy.greater Tests elementwise if x1 > x2. cupy.greater_equal Tests elementwise if x1 >= x2. cupy.less Tests elementwise if x1 < x2. cupy.less_equal Tests elementwise if x1 <= x2. cupy.not_equal Tests elementwise if x1 != x2. cupy.equal Tests elementwise if x1 == x2. cupy.logical_and Computes the logical AND of two arrays. cupy.logical_or Computes the logical OR of two arrays. cupy.logical_xor Computes the logical XOR of two arrays. cupy.logical_not Computes the logical NOT of an array. cupy.maximum Takes the maximum of two arrays elementwise. cupy.minimum Takes the minimum of two arrays elementwise. cupy.fmax Takes the maximum of two arrays elementwise. cupy.fmin Takes the minimum of two arrays elementwise.

### Floating functions¶

 cupy.isfinite Tests finiteness elementwise. cupy.isinf Tests if each element is the positive or negative infinity. cupy.isnan Tests if each element is a NaN. cupy.signbit Tests elementwise if the sign bit is set (i.e. cupy.copysign Returns the first argument with the sign bit of the second elementwise. cupy.nextafter Computes the nearest neighbor float values towards the second argument. cupy.modf Extracts the fractional and integral parts of an array elementwise. cupy.ldexp Computes x1 * 2 ** x2 elementwise. cupy.frexp Decomposes each element to mantissa and two’s exponent. cupy.fmod Computes the remainder of C division elementwise. cupy.floor Rounds each element of an array to its floor integer. cupy.ceil Rounds each element of an array to its ceiling integer. cupy.trunc Rounds each element of an array towards zero.

## ufunc.at¶

Currently, CuPy does not support at for ufuncs in general. However, cupyx.scatter_add() can substitute add.at as both behave identically.