# Universal Functions (ufunc)¶

Mars tensor provides universal functions(a.k.a ufuncs) to support various elementwise operations. Mars tensor’s ufunc supports following features of Numpy’s one:

• Broadcasting
• Output type determination
• Casting rules

Mars tensor’s ufunc currently does not support methods like reduce, accumulate, reduceat, outer, and at.

## Available ufuncs¶

### Math operations¶

 mars.tensor.add Add arguments element-wise. mars.tensor.subtract Subtract arguments, element-wise. mars.tensor.multiply Multiply arguments element-wise. mars.tensor.divide Divide arguments element-wise. mars.tensor.logaddexp Logarithm of the sum of exponentiations of the inputs. mars.tensor.logaddexp2 Logarithm of the sum of exponentiations of the inputs in base-2. mars.tensor.true_divide Returns a true division of the inputs, element-wise. mars.tensor.floor_divide Return the largest integer smaller or equal to the division of the inputs. mars.tensor.negative Numerical negative, element-wise. mars.tensor.power First tensor elements raised to powers from second tensor, element-wise. mars.tensor.remainder Return element-wise remainder of division. mars.tensor.mod Return element-wise remainder of division. mars.tensor.fmod Return the element-wise remainder of division. mars.tensor.absolute Calculate the absolute value element-wise. mars.tensor.rint Round elements of the tensor to the nearest integer. mars.tensor.sign Returns an element-wise indication of the sign of a number. mars.tensor.exp Calculate the exponential of all elements in the input tensor. mars.tensor.exp2 Calculate 2**p for all p in the input tensor. mars.tensor.log Natural logarithm, element-wise. mars.tensor.log2 Base-2 logarithm of x. mars.tensor.log10 Return the base 10 logarithm of the input tensor, element-wise. mars.tensor.expm1 Calculate exp(x) - 1 for all elements in the tensor. mars.tensor.log1p Return the natural logarithm of one plus the input tensor, element-wise. mars.tensor.sqrt Return the positive square-root of an tensor, element-wise. mars.tensor.square Return the element-wise square of the input. mars.tensor.reciprocal Return the reciprocal of the argument, element-wise.

### Trigonometric functions¶

 mars.tensor.sin Trigonometric sine, element-wise. mars.tensor.cos Cosine element-wise. mars.tensor.tan Compute tangent element-wise. mars.tensor.arcsin Inverse sine, element-wise. mars.tensor.arccos Trigonometric inverse cosine, element-wise. mars.tensor.arctan Trigonometric inverse tangent, element-wise. mars.tensor.arctan2 Element-wise arc tangent of x1/x2 choosing the quadrant correctly. mars.tensor.hypot Given the “legs” of a right triangle, return its hypotenuse. mars.tensor.sinh Hyperbolic sine, element-wise. mars.tensor.cosh Hyperbolic cosine, element-wise. mars.tensor.tanh Compute hyperbolic tangent element-wise. mars.tensor.arcsinh Inverse hyperbolic sine element-wise. mars.tensor.arccosh Inverse hyperbolic cosine, element-wise. mars.tensor.arctanh Inverse hyperbolic tangent element-wise. mars.tensor.deg2rad Convert angles from degrees to radians. mars.tensor.rad2deg Convert angles from radians to degrees.

### Bit-twiddling functions¶

 mars.tensor.bitwise_and Compute the bit-wise AND of two tensors element-wise. mars.tensor.bitwise_or Compute the bit-wise OR of two tensors element-wise. mars.tensor.bitwise_xor Compute the bit-wise XOR of two arrays element-wise. mars.tensor.invert Compute bit-wise inversion, or bit-wise NOT, element-wise. mars.tensor.left_shift Shift the bits of an integer to the left. mars.tensor.right_shift Shift the bits of an integer to the right.

### Comparison functions¶

 mars.tensor.greater Return the truth value of (x1 > x2) element-wise. mars.tensor.greater_equal Return the truth value of (x1 >= x2) element-wise. mars.tensor.less Return the truth value of (x1 < x2) element-wise. mars.tensor.less_equal Return the truth value of (x1 =< x2) element-wise. mars.tensor.not_equal Return (x1 != x2) element-wise. mars.tensor.equal Return (x1 == x2) element-wise. mars.tensor.logical_and Compute the truth value of x1 AND x2 element-wise. mars.tensor.logical_or Compute the truth value of x1 OR x2 element-wise. mars.tensor.logical_xor Compute the truth value of x1 XOR x2, element-wise. mars.tensor.logical_not Compute the truth value of NOT x element-wise. mars.tensor.maximum Element-wise maximum of tensor elements. mars.tensor.minimum Element-wise minimum of tensor elements. mars.tensor.fmax Element-wise maximum of array elements. mars.tensor.fmin Element-wise minimum of array elements.

### Floating point values¶

 mars.tensor.isfinite Test element-wise for finiteness (not infinity or not Not a Number). mars.tensor.isinf Test element-wise for positive or negative infinity. mars.tensor.isnan Test element-wise for NaN and return result as a boolean tensor. mars.tensor.signbit Returns element-wise True where signbit is set (less than zero). mars.tensor.copysign Change the sign of x1 to that of x2, element-wise. mars.tensor.nextafter Return the next floating-point value after x1 towards x2, element-wise. mars.tensor.modf Return the fractional and integral parts of a tensor, element-wise. mars.tensor.ldexp Returns x1 * 2**x2, element-wise. mars.tensor.frexp Decompose the elements of x into mantissa and twos exponent. mars.tensor.fmod Return the element-wise remainder of division. mars.tensor.floor Return the floor of the input, element-wise. mars.tensor.ceil Return the ceiling of the input, element-wise. mars.tensor.trunc Return the truncated value of the input, element-wise.