braincore.math module

braincore.math module#

get_dtype(a)

Get the dtype of a.

is_float(array)

Check if the array is a floating point array.

is_int(array)

Check if the array is an integer array.

exprel(x)

Relative error exponential, (exp(x) - 1)/x.

flatten(input[, start_dim, end_dim])

Flattens input by reshaping it into a one-dimensional tensor.

unflatten(x, dim, sizes)

Expands a dimension of the input tensor over multiple dimensions.

remove_diag(arr)

Remove the diagonal of the matrix.

clip_by_norm(t, clip_norm[, axis])

Clip the tensor by the norm of the tensor.

from_numpy(x)

Convert the numpy array to jax array.

as_numpy(x)

Convert the array to numpy array.

tree_zeros_like(tree)

Create a tree with the same structure as the input tree, but with zeros in each leaf.

tree_ones_like(tree)

Create a tree with the same structure as the input tree, but with ones in each leaf.

ein_reduce(tensor, pattern, reduction, ...)

ein_reduce provides combination of reordering and reduction using reader-friendly notation.

ein_rearrange(tensor, pattern, **axes_lengths)

ein_rearrange is a reader-friendly smart element reordering for multidimensional tensors.

ein_repeat(tensor, pattern, **axes_lengths)

ein_repeat allows reordering elements and repeating them in arbitrary combinations.

ein_shape(x, pattern)

Parse a tensor shape to dictionary mapping axes names to their lengths.