saiunit.math module#
Unit-aware mathematical functions for JAX arrays.
This subpackage provides unit-aware wrappers for NumPy-style functions, organized by how they handle units:
Array creation:
array,zeros,ones,arange,linspace, etc.Keep unit: functions that preserve the input unit (
sum,mean,concatenate,reshape,abs,round, etc.).Change unit: functions whose output unit differs from the input (
multiply,divide,square,sqrt,dot,matmul, etc.).Remove unit: functions that return dimensionless results (
equal,greater,argmax,argsort,sign, etc.).Accept unitless: functions that require unitless inputs (
exp,log,sin,cos,arctan, etc.).Activations: neural-network activation functions (
relu,sigmoid,gelu,silu, etc.).Einops: Einstein-notation operations (
einsum,einrearrange, etc.).
Activation Functions#
Rectified linear unit activation function. |
|
Rectified Linear Unit 6 activation function. |
|
Sigmoid activation function. |
|
Softplus activation function. |
|
Sparse plus function. |
|
Sparse sigmoid activation function. |
|
Soft-sign activation function. |
|
SiLU (aka swish) activation function. |
|
Swish (aka SiLU) activation function. |
|
Log-sigmoid activation function. |
|
Leaky rectified linear unit activation function. |
|
Hard Sigmoid activation function. |
|
Hard SiLU (swish) activation function. |
|
Hard SiLU (swish) activation function. |
|
Hard \(\mathrm{tanh}\) activation function. |
|
Exponential linear unit activation function. |
|
Continuously-differentiable exponential linear unit activation. |
|
Scaled exponential linear unit activation. |
|
Gaussian error linear unit activation function. |
|
Gated linear unit activation function. |
|
Squareplus activation function. |
|
Mish activation function. |
Unit Processing#
Test if a value is dimensionless or not. |
|
Test if a value is unitless or not. |
|
Return the dimension of any object that has them. |
|
Return the unit of any object that has them. |
|
Return the mantissa of a Quantity or a number. |
|
Return the mantissa of a Quantity or a number. |
|
Display a value in a certain unit with a given precision. |
|
Convert a quantity to a plain number if it is dimensionless. |
|
Decorator to check dimensions of arguments passed to a function |
|
Decorator to check units of arguments passed to a function |
|
Compare the dimensions of two objects. |
|
Compare the units of two objects. |
|
Assert that a Quantity has a certain mantissa and unit. |
|
Create a new Dimension object or get a reference to an existing one. |
Einstein Operations#
Combine reordering and reduction using reader-friendly notation. |
|
Reader-friendly smart element reordering for multidimensional tensors. |
|
Reorder elements and repeat them in arbitrary combinations. |
|
Parse a tensor shape to a dictionary mapping axis names to their lengths. |
|
Einstein summation for arrays and quantities. |
Functions that Accepting Unitless#
Relative error exponential, |
|
Set the Taylor series order used by |
|
Calculate the exponential of all elements in the input. |
|
Calculate |
|
Calculate |
|
Natural logarithm, element-wise. |
|
Base-10 logarithm, element-wise. |
|
Natural logarithm of |
|
Base-2 logarithm, element-wise. |
|
Inverse cosine, element-wise. |
|
Inverse hyperbolic cosine, element-wise. |
|
Inverse sine, element-wise. |
|
Inverse hyperbolic sine, element-wise. |
|
Inverse tangent, element-wise. |
|
Inverse hyperbolic tangent, element-wise. |
|
Cosine, element-wise. |
|
Hyperbolic cosine, element-wise. |
|
Sine, element-wise. |
|
Normalized sinc function, |
|
Hyperbolic sine, element-wise. |
|
Tangent, element-wise. |
|
Hyperbolic tangent, element-wise. |
|
Convert angles from degrees to radians. |
|
Convert angles from radians to degrees. |
|
Convert angles from radians to degrees (alias for |
|
Convert angles from degrees to radians (alias for |
|
Return the angle of the complex argument, element-wise. |
|
Decompose elements into mantissa and base-2 exponent. |
|
Given the legs of a right triangle, return its hypotenuse. |
|
Element-wise arc tangent of |
|
Logarithm of the sum of exponentiations of the inputs. |
|
Logarithm of the sum of exponentiations of the inputs in base 2. |
|
Return Pearson product-moment correlation coefficients. |
|
Cross-correlation of two 1-dimensional sequences. |
|
Estimate a covariance matrix, given data and weights. |
|
Returns x * 2**y, element-wise. |
|
Compute bit-wise NOT, element-wise. |
|
Compute bit-wise inversion (NOT), element-wise. |
|
Compute bit-wise AND of two arrays, element-wise. |
|
Compute bit-wise OR of two arrays, element-wise. |
|
Compute bit-wise XOR of two arrays, element-wise. |
|
Shift the bits of an integer to the left, element-wise. |
|
Shift the bits of an integer to the right, element-wise. |
Array Creation Functions#
Return a new quantity or array of given shape, filled with |
|
Return a 2-D identity-like quantity or array with ones on the diagonal. |
|
Return the identity quantity or array. |
|
Return an array with ones at and below the given diagonal and zeros elsewhere. |
|
Return a new quantity or array of given shape and type, without initializing entries. |
|
Return a new quantity or array of given shape and type, filled with ones. |
|
Return a new quantity or array of given shape and type, filled with zeros. |
|
Return a new quantity or array with the same shape and type as a given array, filled with |
|
Extract a diagonal or construct a diagonal array. |
|
Return the lower triangle of an array. |
|
Return the upper triangle of an array. |
|
Return a new uninitialized quantity or array with the same shape and type as a given array. |
|
Return a quantity or array of ones with the same shape and type as a given array. |
|
Return a quantity or array of zeros with the same shape and type as a given array. |
|
Fill the main diagonal of the given array of any dimensionality. |
|
Convert the input to a quantity or array. |
|
Convert the input to a quantity or array. |
|
Return evenly spaced values within a given interval. |
|
Return evenly spaced numbers over a specified interval. |
|
Return numbers spaced evenly on a log scale. |
|
Return coordinate matrices from coordinate vectors. |
|
Generate a Vandermonde matrix. |
|
Return the indices of lower triangle of an array of size |
|
Return the indices for the lower-triangle of an |
|
Return the indices of upper triangle of an array of size |
|
Return the indices for the upper-triangle of an |
|
Convert a NumPy array to a JAX array, optionally attaching a unit. |
|
Convert a JAX array (or |
|
Create a tree with the same structure as the input, but with ones in each leaf. |
|
Create a tree with the same structure as the input, but with zeros in each leaf. |
Functions that Changing Unit#
Return the reciprocal of the argument, element-wise. |
|
Return the product of array elements over a given axis. |
|
Return the product of array elements over a given axis. |
|
Return the cumulative product of elements along a given axis treating NaNs as one. |
|
Return the product of array elements over a given axis treating NaNs as one. |
|
Return the cumulative product of elements along a given axis. |
|
Return the cumulative product of elements along a given axis. |
|
Compute the variance along the specified axis. |
|
Compute the variance along the specified axis, while ignoring NaNs. |
|
Compute the cube root of each element. |
|
Compute the square of each element. |
|
Compute the positive square root of each element. |
|
Multiply arguments element-wise. |
|
Divide arguments element-wise. |
|
First array elements raised to powers from second array, element-wise. |
|
Return the cross product of two (arrays of) vectors. |
|
Return a true division of the inputs, element-wise. |
|
Return the largest integer smaller or equal to the division of the inputs. |
|
First array elements raised to powers from second array, element-wise. |
|
Return element-wise quotient and remainder simultaneously. |
|
Return the discrete, linear convolution of two one-dimensional sequences. |
|
Compute the dot product of two arrays or quantities. |
|
Efficiently compute matrix products between a sequence of arrays. |
|
Perform a conjugate multiplication of two 1D vectors. |
|
Perform a conjugate multiplication of two batched vectors. |
|
Compute the inner product of two arrays or quantities. |
|
Compute the outer product of two vectors or quantities. |
|
Compute the Kronecker product of two arrays or quantities. |
|
Compute the matrix product of two arrays or quantities. |
|
Compute tensor dot product along specified axes. |
|
Raise a square matrix to the (integer) power n. |
Functions that Keeping Unit#
Stack quantities or arrays in sequence vertically (row wise). |
|
Join a sequence of quantities or arrays along an existing axis. |
|
Join a sequence of quantities or arrays along a new axis. |
|
Stack quantities or arrays in sequence vertically (row wise). |
|
Stack quantities arrays in sequence horizontally (column wise). |
|
Stack quantities or arrays in sequence depth wise (along third axis). |
|
Stack 1-D arrays as columns into a 2-D array. |
|
Assemble a quantity or an array from nested lists of blocks. |
|
Append values to the end of a quantity or an array. |
|
Split quantity or array into a list of multiple sub-arrays. |
|
Split an array into multiple sub-arrays. |
|
Split a quantity or an array into multiple sub-arrays along the 3rd axis (depth). |
|
Split a quantity or an array into multiple sub-arrays horizontally (column-wise). |
|
Split a quantity or an array into multiple sub-arrays vertically (row-wise). |
|
View inputs as quantities or arrays with at least one dimension. |
|
View inputs as quantities or arrays with at least two dimensions. |
|
View inputs as quantities or arrays with at least three dimensions. |
|
Broadcast any number of arrays against each other. |
|
Broadcast an array to a new shape. |
|
Gives a new shape to a quantity or an array without changing its data. |
|
Moves axes of a quantity or an array to new positions. |
|
Permute the dimensions of a quantity or an array. |
|
Interchange two axes of a quantity or an array. |
|
Construct a quantity or an array by repeating A the number of times given by reps. |
|
Repeat elements of a quantity or an array. |
|
Reverse the order of elements in a quantity or an array along the given axis. |
|
Flip quantity or array in the left/right direction. |
|
Flip quantity or array in the up/down direction. |
|
Roll quantity or array elements along a given axis. |
|
Expand the shape of a quantity or an array. |
|
Remove single-dimensional entries from the shape of a quantity or an array. |
|
Return a sorted copy of a quantity or an array. |
|
Return the maximum of a quantity or an array or maximum along an axis. |
|
Return the minimum of a quantity or an array or minimum along an axis. |
|
Return the maximum of a quantity or an array or maximum along an axis. |
|
Return the minimum of a quantity or an array or minimum along an axis. |
|
Create a two-dimensional a quantity or array with the flattened input as a diagonal. |
|
Return specified diagonals. |
|
Construct a quantity or an array from an index array and a set of arrays to choose from. |
|
Return a contiguous flattened quantity or array. |
|
Flattens input by reshaping it into a one-dimensional tensor. |
|
Expands a dimension of the input tensor over multiple dimensions. |
|
Remove the diagonal of the matrix. |
|
Copy of the array, cast to a specified type. |
|
Return the real part of the complex argument. |
|
Return the imaginary part of the complex argument. |
|
Return the complex conjugate of the argument. |
|
Return the complex conjugate of the argument. |
|
Return the negative of the argument. |
|
Return the positive of the argument. |
|
Return the absolute value of the argument. |
|
Return the sum of the array elements. |
|
Return the cumulative sum of the array elements, ignoring NaNs. |
|
Return the sum of the array elements, ignoring NaNs. |
|
Return the cumulative sum of the array elements. |
|
Return the differences between consecutive elements of the array. |
|
Return the absolute value of the argument. |
|
Return the absolute value of the argument. |
|
Return the median of the array elements. |
|
Return the minimum of the array elements, ignoring NaNs. |
|
Return the maximum of the array elements, ignoring NaNs. |
|
Return the range of the array elements (maximum - minimum). |
|
Return the weighted average of the array elements. |
|
Return the mean of the array elements. |
|
Return the standard deviation of the array elements. |
|
Return the median of the array elements, ignoring NaNs. |
|
Return the mean of the array elements, ignoring NaNs. |
|
Return the standard deviation of the array elements, ignoring NaNs. |
|
Return the differences between consecutive elements of the array. |
|
Rotate an array by 90 degrees in the plane specified by axes. |
|
Find the intersection of two arrays. |
|
Replace NaN with zero and infinity with large finite numbers (default behaviour) or with the numbers defined by the user using the nan, posinf and/or neginf keywords. |
|
Compute the q-th percentile of the data along the specified axis. |
|
Compute the q-th percentile of the data along the specified axis, while ignoring nan values. |
|
Compute the q-th percentile of the data along the specified axis. |
|
Compute the q-th percentile of the data along the specified axis, while ignoring nan values. |
|
Round an array to the nearest integer. |
|
Round an array to the nearest integer. |
|
Round an array to the nearest integer. |
|
Return the floor of the argument. |
|
Return the ceiling of the argument. |
|
Return the truncated value of the argument. |
|
Return the nearest integer towards zero. |
|
Return the fractional and integer parts of the array elements. |
|
Return the element-wise remainder of division. |
|
Return the element-wise modulus of division. |
|
Return a copy of the first array elements with the sign of the second array. |
|
Returns the element-wise remainder of division. |
|
Element-wise maximum of array elements. |
|
Element-wise minimum of array elements. |
|
Element-wise maximum of array elements ignoring NaNs. |
|
Element-wise minimum of array elements ignoring NaNs. |
|
Return the least common multiple of x1 and x2. |
|
Return the greatest common divisor of x1 and x2. |
|
Return the sum along diagonals of the array. |
|
Add arguments element-wise. |
|
Subtract arguments, element-wise. |
|
Return the next floating-point value after x towards y, element-wise. |
|
Promote the data types of the inputs to a common type. |
|
One-dimensional linear interpolation. |
|
Clip (limit) the values in an array. |
|
Compute the histogram of a set of data. |
|
Return selected slices of a quantity or an array along given axis. |
|
Return the elements of an array that satisfy some condition. |
|
Take elements from an array along an axis. |
|
Return an array drawn from elements in choicelist, depending on conditions. |
|
Return elements chosen from x or y depending on condition. |
|
Find the unique elements of a quantity or an array. |
|
Gather values along an axis specified by dim, according to index. |
Functions that Removing Unit#
Return True if x is a complex type or an array of complex numbers. |
|
Compute the Heaviside step function. |
|
Return element-wise True where the sign bit is set (less than zero). |
|
Return the sign of each element in the input array. |
|
Count number of occurrences of each value in array of non-negative ints. |
|
Return the indices of the bins to which each value in input array belongs. |
|
Promote the data types of the inputs to a common type. |
|
Test whether all array elements along a given axis evaluate to True. |
|
Test whether any array element along a given axis evaluates to True. |
|
Compute the truth value of NOT x element-wise. |
|
Return |
|
Return |
|
Return |
|
Return |
|
Return |
|
Return |
|
Return True if two arrays have the same shape and elements. |
|
Returns a boolean array where two arrays are element-wise equal within a tolerance. |
|
Returns True if two arrays are element-wise equal within a tolerance. |
|
Compute the truth value of |
|
Compute the truth value of |
|
Compute the truth value of |
|
Test whether all array elements along a given axis evaluate to True. |
|
Test whether any array element along a given axis evaluates to True. |
|
Return the indices that would sort an array or Quantity. |
|
Return the index of the maximum value along an axis. |
|
Return the index of the minimum value along an axis. |
|
Return the index of the maximum value, ignoring NaNs. |
|
Return the index of the minimum value, ignoring NaNs. |
|
Find the indices of array elements that are non-zero. |
|
Return the indices of non-zero elements. |
|
Return indices that are non-zero in the flattened input. |
|
Find indices where elements should be inserted to maintain order. |
|
Count the number of non-zero values in the input. |
|
Return indices for accessing the main diagonal of a given array. |
Other Functions#
Check whether x is a |
|
Check if a dtype is a sub-dtype of another in the type hierarchy. |
|
Determine the result dtype from a set of input arrays or dtypes. |
|
Return the number of dimensions of an array or |
|
Test element-wise whether each element is real (has zero imaginary part). |
|
Return |
|
Test element-wise for finiteness (not inf and not NaN). |
|
Test element-wise for positive or negative infinity. |
|
Test element-wise for NaN. |
|
Return the shape of an array. |
|
Return the number of elements along a given axis. |
|
Get the dtype of an array, |
|
Check if the array has a floating-point dtype. |
|
Check if the array has an integer dtype. |
|
Broadcast a sequence of array shapes. |
|
Computes the gradient of a scalar field. |
|
Return a Bartlett window of size M. |
|
Return a Blackman window of size M. |
|
Return a Hamming window of size M. |
|
Return a Hanning window of size M. |
|
Return a Kaiser window of size M. |
|
A JAX scalar constructor of type uint2. |
|
A JAX scalar constructor of type uint4. |
|
A JAX scalar constructor of type uint8. |
|
A JAX scalar constructor of type uint16. |
|
A JAX scalar constructor of type uint32. |
|
A JAX scalar constructor of type uint64. |
|
A JAX scalar constructor of type int2. |
|
A JAX scalar constructor of type int4. |
|
A JAX scalar constructor of type int8. |
|
A JAX scalar constructor of type int16. |
|
A JAX scalar constructor of type int32. |
|
A JAX scalar constructor of type int64. |
|
A JAX scalar constructor of type bfloat16. |
|
A JAX scalar constructor of type float16. |
|
A JAX scalar constructor of type float32. |
|
A JAX scalar constructor of type float64. |
|
A JAX scalar constructor of type complex64. |
|
A JAX scalar constructor of type complex128. |
|
Abstract base class of all numeric scalar types with a (potentially) inexact representation of the values in its range, such as floating-point numbers. |
|
Convert a string or number to a floating-point number, if possible. |
|
Convert a string or number to a floating-point number, if possible. |
|
Convert a string or number to a floating-point number, if possible. |
|
Convert a string or number to a floating-point number, if possible. |
|
Convert a string or number to a floating-point number, if possible. |
|
The type of the None singleton. |