Module easy_ml::linear_algebra
source · Expand description
Linear algebra algorithms on numbers and matrices
Note that many of these functions are also exposed as corresponding methods on the Matrix type, and the Tensor type, but in depth documentation is only presented here.
It is recommended to favor the corresponding methods on the Matrix and Tensor types as the Rust compiler can get confused with the generics on these functions if you use these methods without turbofish syntax.
Nearly all of these functions are generic over Numeric types,
unfortunately, when using these functions the compiler may get confused about what
type T
should be and you will get the error:
overflow evaluating the requirement
&'a _: easy_ml::numeric::NumericByValue<_, _>
In this case you need to manually specify the type of T by using the
turbofish syntax like:
linear_algebra::inverse::<f32>(&matrix)
You might be working with a generic type of T, in which case specify that
linear_algebra::inverse::<T>(&matrix)
Generics
For the tensor variants of these functions, the generics allow very flexible input types.
A function like
pub fn inverse_tensor<T, S, I>(tensor: I) -> Option<Tensor<T, 2>> where
T: Numeric,
for<'a> &'a T: NumericRef<T>,
I: Into<TensorView<T, S, 2>>,
S: TensorRef<T, 2>,
Means it takes any type that can be converted to a TensorView, which includes Tensor, &Tensor, &mut Tensor as well as references to a TensorView.
Structs
LDL^T
Decomposition of some matrix A
such that LDL^T = A
.LDL^T
Decomposition of some matrix A
such that LDL^T = A
.QR = A
.QR = A
.Functions
L
such that for the provided matrix A
, L * L^T = A
. L
will always be
lower triangular, ie all entries above the diagonal will be 0. Hence cholesky
decomposition can be interpreted as a generalised square root function.L
such that for the provided matrix A
, L * L^T = A
. L
will always be
lower triangular, ie all entries above the diagonal will be 0. Hence cholesky
decomposition can be interpreted as a generalised square root function.ad - bc
for:ad - bc
for:L
and a matrix D
such that for the provided matrix A
, L * D * L^T = A
. L
will always be
unit lower triangular, ie all entries above the diagonal will be 0, and all entries along
the diagonal will br 1. D
will always contain zeros except along the diagonal. This
decomposition is closely related to the cholesky decomposition
with the notable difference that it avoids taking square roots.L
and a matrix D
such that for the provided matrix A
, L * D * L^T = A
. L
will always be
unit lower triangular, ie all entries above the diagonal will be 0, and all entries along
the diagonal will br 1. D
will always contain zeros except along the diagonal. This
decomposition is closely related to the cholesky decomposition
with the notable difference that it avoids taking square roots.