numojo.routines.math.arithmetic¶
Arithmetic routines for NuMojo (numojo.routines.math.arithmetic).
Implements addition, subtraction, multiplication, division, floor division, fused multiply-add, and remainder helpers for NDArrays.
Functions¶
add¶
Overload 1¶
add[dtype: DType, backend: Backend = Vectorized](array1: NDArray[dtype], array2: NDArray[dtype]) -> NDArray[dtype]
Perform addition on two arrays.
Constraints
Both arrays must have the same shapes.
Parameters:
dtype(DType): The element type.backend(Backend): Sets utility function origin, defaults toVectorized.
Args:
array1(NDArray): A NDArray.array2(NDArray): A NDArray.
Returns:
NDArray
Raises
Overload 2¶
add[dtype: DType, backend: Backend = Vectorized](array: NDArray[dtype], scalar: Scalar[dtype]) -> NDArray[dtype]
Perform addition on between an array and a scalar.
Parameters:
dtype(DType): The element type.backend(Backend): Sets utility function origin, defaults toVectorized.
Args:
array(NDArray): A NDArray.scalar(Scalar): A NDArray.
Returns:
NDArray
Raises
Overload 3¶
add[dtype: DType, backend: Backend = Vectorized](scalar: Scalar[dtype], array: NDArray[dtype]) -> NDArray[dtype]
Perform addition on between an array and a scalar.
Parameters:
dtype(DType): The element type.backend(Backend): Sets utility function origin, defaults toVectorized.
Args:
scalar(Scalar): A NDArray.array(NDArray): A NDArray.
Returns:
NDArray
Raises
Overload 4¶
add[dtype: DType, backend: Backend = Vectorized](var *values: Variant[NDArray[dtype], Scalar[dtype]]) -> NDArray[dtype]
Perform addition on a list of arrays and a scalars.
Parameters:
dtype(DType): The element type.backend(Backend): Sets utility function origin, defaults toVectorized.
Args:
*values(Variant)[var]: A list of arrays or Scalars to be added.
Returns:
NDArray
Raises
sub¶
Overload 1¶
sub[dtype: DType, backend: Backend = Vectorized](array1: NDArray[dtype], array2: NDArray[dtype]) -> NDArray[dtype]
Perform subtraction on two arrays.
Constraints
Both arrays must have the same shapes.
Parameters:
dtype(DType): The element type.backend(Backend): Sets utility function origin, defaults toVectorized.
Args:
array1(NDArray): A NDArray.array2(NDArray): A NDArray.
Returns:
NDArray
Raises
Overload 2¶
sub[dtype: DType, backend: Backend = Vectorized](array: NDArray[dtype], scalar: Scalar[dtype]) -> NDArray[dtype]
Perform subtraction on between an array and a scalar.
Parameters:
dtype(DType): The element type.backend(Backend): Sets utility function origin, defaults toVectorized.
Args:
array(NDArray): A NDArray.scalar(Scalar): A NDArray.
Returns:
NDArray
Raises
Overload 3¶
sub[dtype: DType, backend: Backend = Vectorized](scalar: Scalar[dtype], array: NDArray[dtype]) -> NDArray[dtype]
Perform subtraction on between an array and a scalar.
Parameters:
dtype(DType): The element type.backend(Backend): Sets utility function origin, defaults toVectorized.
Args:
scalar(Scalar): A NDArray.array(NDArray): A NDArray.
Returns:
NDArray
Raises
diff¶
Compute the n-th order difference of the input array.
Parameters:
dtype(DType): The element type.
Args:
array(NDArray): A array.n(Int): The order of the difference.
Returns:
NDArray
Raises
mod¶
Overload 1¶
mod[dtype: DType, backend: Backend = Vectorized](array1: NDArray[dtype], array2: NDArray[dtype]) -> NDArray[dtype]
Element-wise modulo of array1 and array2.
Constraints
Both arrays must have the same shapes.
Parameters:
dtype(DType): The element type.backend(Backend): Sets utility function origin, defaults toVectorized.
Args:
array1(NDArray): A NDArray.array2(NDArray): A NDArray.
Returns:
NDArray
Raises
Overload 2¶
mod[dtype: DType, backend: Backend = Vectorized](array: NDArray[dtype], scalar: Scalar[dtype]) -> NDArray[dtype]
Perform subtraction on between an array and a scalar.
Parameters:
dtype(DType): The element type.backend(Backend): Sets utility function origin, defaults toVectorized.
Args:
array(NDArray): A NDArray.scalar(Scalar): A NDArray.
Returns:
NDArray
Raises
Overload 3¶
mod[dtype: DType, backend: Backend = Vectorized](scalar: Scalar[dtype], array: NDArray[dtype]) -> NDArray[dtype]
Perform subtraction on between an array and a scalar.
Parameters:
dtype(DType): The element type.backend(Backend): Sets utility function origin, defaults toVectorized.
Args:
scalar(Scalar): A NDArray.array(NDArray): A NDArray.
Returns:
NDArray
Raises
mul¶
Overload 1¶
mul[dtype: DType, backend: Backend = Vectorized](array1: NDArray[dtype], array2: NDArray[dtype]) -> NDArray[dtype]
Element-wise product of array1 and array2.
Constraints
Both arrays must have the same shapes.
Parameters:
dtype(DType): The element type.backend(Backend): Sets utility function origin, defaults toVectorized.
Args:
array1(NDArray): A NDArray.array2(NDArray): A NDArray.
Returns:
NDArray
Raises
Overload 2¶
mul[dtype: DType, backend: Backend = Vectorized](array: NDArray[dtype], scalar: Scalar[dtype]) -> NDArray[dtype]
Perform multiplication on between an array and a scalar.
Parameters:
dtype(DType): The element type.backend(Backend): Sets utility function origin, defaults toVectorized.
Args:
array(NDArray): A NDArray.scalar(Scalar): A NDArray.
Returns:
NDArray
Raises
Overload 3¶
mul[dtype: DType, backend: Backend = Vectorized](scalar: Scalar[dtype], array: NDArray[dtype]) -> NDArray[dtype]
Perform multiplication on between an array and a scalar.
Parameters:
dtype(DType): The element type.backend(Backend): Sets utility function origin, defaults toVectorized.
Args:
scalar(Scalar): A NDArray.array(NDArray): A NDArray.
Returns:
NDArray
Raises
Overload 4¶
mul[dtype: DType, backend: Backend = Vectorized](var *values: Variant[NDArray[dtype], Scalar[dtype]]) -> NDArray[dtype]
Perform multiplication on a list of arrays an arrays and a scalars.
Parameters:
dtype(DType): The element type.backend(Backend): Sets utility function origin, defaults toVectorized.
Args:
*values(Variant)[var]: A list of arrays or Scalars to be added.
Returns:
NDArray
Raises
div¶
Overload 1¶
div[dtype: DType, backend: Backend = Vectorized](array1: NDArray[dtype], array2: NDArray[dtype]) -> NDArray[dtype]
Element-wise quotient of array1 and array2.
Constraints
Both arrays must have the same shapes.
Parameters:
dtype(DType): The element type.backend(Backend): Sets utility function origin, defaults toVectorized.
Args:
array1(NDArray): A NDArray.array2(NDArray): A NDArray.
Returns:
NDArray
Raises
Overload 2¶
div[dtype: DType, backend: Backend = Vectorized](array: NDArray[dtype], scalar: Scalar[dtype]) -> NDArray[dtype]
Perform true division on between an array and a scalar.
Parameters:
dtype(DType): The element type.backend(Backend): Sets utility function origin, defaults toVectorized.
Args:
array(NDArray): A NDArray.scalar(Scalar): A NDArray.
Returns:
NDArray
Raises
Overload 3¶
div[dtype: DType, backend: Backend = Vectorized](scalar: Scalar[dtype], array: NDArray[dtype]) -> NDArray[dtype]
Perform true division on between an array and a scalar.
Parameters:
dtype(DType): The element type.backend(Backend): Sets utility function origin, defaults toVectorized.
Args:
scalar(Scalar): A NDArray.array(NDArray): A NDArray.
Returns:
NDArray
Raises
floor_div¶
Overload 1¶
floor_div[dtype: DType, backend: Backend = Vectorized](array1: NDArray[dtype], array2: NDArray[dtype]) -> NDArray[dtype]
Element-wise quotient of array1 and array2.
Constraints
Both arrays must have the same shapes.
Parameters:
dtype(DType): The element type.backend(Backend): Sets utility function origin, defaults toVectorized.
Args:
array1(NDArray): A NDArray.array2(NDArray): A NDArray.
Returns:
NDArray
Raises
Overload 2¶
floor_div[dtype: DType, backend: Backend = Vectorized](array: NDArray[dtype], scalar: Scalar[dtype]) -> NDArray[dtype]
Perform true division on between an array and a scalar.
Parameters:
dtype(DType): The element type.backend(Backend): Sets utility function origin, defaults toVectorized.
Args:
array(NDArray): A NDArray.scalar(Scalar): A NDArray.
Returns:
NDArray
Raises
Overload 3¶
floor_div[dtype: DType, backend: Backend = Vectorized](scalar: Scalar[dtype], array: NDArray[dtype]) -> NDArray[dtype]
Perform true division on between an array and a scalar.
Parameters:
dtype(DType): The element type.backend(Backend): Sets utility function origin, defaults toVectorized.
Args:
scalar(Scalar): A NDArray.array(NDArray): A NDArray.
Returns:
NDArray
Raises
fma¶
Overload 1¶
fma[dtype: DType, backend: Backend = Vectorized](array1: NDArray[dtype], array2: NDArray[dtype], array3: NDArray[dtype]) -> NDArray[dtype]
Apply a SIMD level fuse multiply add function of three variables and one return to a NDArray.
Constraints
Both arrays must have the same shape.
Parameters:
dtype(DType): The element type.backend(Backend): Sets utility function origin, defaults toVectorized.
Args:
array1(NDArray): A NDArray.array2(NDArray): A NDArray.array3(NDArray): A NDArray.
Returns:
NDArray
Raises
Overload 2¶
fma[dtype: DType, backend: Backend = Vectorized](array1: NDArray[dtype], array2: NDArray[dtype], simd: Scalar[dtype]) -> NDArray[dtype]
Apply a SIMD level fuse multiply add function of three variables and one return to a NDArray.
Constraints
Both arrays must have the same shape
Parameters:
dtype(DType): The element type.backend(Backend): Sets utility function origin, defaults toVectorized.
Args:
array1(NDArray): A NDArray.array2(NDArray): A NDArray.simd(Scalar): A SIMD[dtype,1] value to be added.
Returns:
NDArray
Raises
remainder¶
remainder[dtype: DType, backend: Backend = Vectorized](array1: NDArray[dtype], array2: NDArray[dtype]) -> NDArray[dtype]
Element-wise remainders of NDArray.
Constraints
Both arrays must have the same shapes.
Parameters:
dtype(DType): The element type.backend(Backend): Sets utility function origin, defaults toVectorized.
Args:
array1(NDArray): A NDArray.array2(NDArray): A NDArray.
Returns:
NDArray
Raises