Module utils

Module utils 

Source
Expand description

Utility functions for matrix printing, shape retrieval, identity generation, Kronecker product, trace, transpose operations, …

These functions were necessary for implementing this crate. They are exposed because they can be generally useful, but this is not meant to be a complete collection of linear algebra utilities at this time.

Functions§

dims2
Make sure that matrix shapes are compatible with A * B, and return the dimensions (m, n) safely cast to i32
dims3
Make sure that matrix shapes are compatible with C = A * B, and return the dimensions (m, n, k) safely cast to i32, where C is (m x n), and k is the common dimension of A and B
identity
Creates an identity matrix of size n x n.
identity_k
Creates a diagonal matrix of size n x n with ones on a specified diagonal.
into_i32
Safely casts a value to i32
ipiv_to_perm_mat
Convert pivot indices to permutation matrix
kron
Computes the Kronecker product of two 2D tensors.
pretty_print
Displays a numeric mdarray in a human-readable format (NumPy-style)
to_col_major
Given an input matrix of shape (m × n), this function creates and returns a new matrix of shape (n × m), where each element at position (i, j) in the original is moved to position (j, i) in the result.
trace
Computes the trace of a square matrix (sum of diagonal elements).
transpose_in_place
Transposes a matrix in-place. Dimensions stay the same, only the memory ordering changes.
unravel_index
Converts a flat index to multidimensional coordinates.