Crate linxal [] [src]


linxal is a linear algebra package on top of ndarray.It currently provides major drivers from LAPACK, but will also support other higher-level tasks in the future, such as linear regression, PCA, etc.

The repository for linxal can be found here.


linxal is available as a crate through cargo. Add the following line to your Cargo.toml, in the dependencies section:

linxal = "0.3"

In your or file, use

extern crate linxal;
use linxal::prelude::*;

The linxal::prelude modules re-exports the most useful functionality.


Most of the useful functionality for linxal comes in the form of traits, which are implemented in terms of scalars and provide functionality for matrices and vectors composed of the scalars. Most traits have a compute function, and variants, which performs the describe behavior.

For instance, the Eigen trait, implemented for single- and double-precision real and complex-valued matrices, allows one to compute eigenvalues and eigenvectors of square matrices.

extern crate linxal;
extern crate ndarray;

use linxal::eigenvalues::{Eigen};
use linxal::types::{c32, Magnitude};
use ndarray::{Array, arr1, arr2};

fn main() {
    let m = arr2(&[[1.0f32, 2.0],
                   [-2.0, 1.0]]);

    let r = Eigen::compute_into(m, false, true);

    let r = r.unwrap();
    let true_evs = arr1(&[c32::new(1.0, 2.0), c32::new(1.0, -2.0)]);
    assert_eq_within_tol!(true_evs, r.values, 0.01);


Symmetric Algorithms

Some traits and algorithms are designed only to work on symmetric or Hermititan matrices. Throught the library, 'Sym' or 'Symmetric' refers simply to symmetric matrices for real-valued matrices and Hermititan matrices for complex-valued matrices.

Symmetric algorithms typically take a (Symmetric) enum argument. Symmetric::Upper indicates that the values of the matrix are stored in the upper-triangular portion of the matrix. Symmetric::Lower corresponds to the lower portion. For algorithms that take this argument, only that portion is read. So, for example:

extern crate linxal;
extern crate ndarray;

use linxal::eigenvalues::{SymEigen};
use ndarray::{arr1, arr2};

fn test_eig_access() {
    // `upper_only` is not symmetric, but the portion below the diagonal is  never read.
    let upper_only = arr2(&[[1.0f32, 2.0], [-3.0, 1.0]]);

    // Since only the upper triangle is read by `SymEigen`, it is equivalent to `full`.
    let full = arr2(&[[1.0f32, 2.0], [2.0, 1.0]]);

    let upper_only_ev = SymEigen::compute_into(upper_only, Symmetric::Upper).unwrap();
    let full_ev = SymEigen::compute_into(full, Symmetric::Upper).unwrap();

    assert_eq_within_tol!(upper_only_ev, full_ev, 1e-5);



Contains methods for solving eigenvalues, including general and symmetric/Hermitian eigenvalue problems.


Traits and functions for computing matrix factoriations.


This module contains the LeastSquares trait, which acts as an entry point, which is used to compute least squares solutions.


Common traits, structures, and macros for most user-end applications


Containts traits and methods to solve sets of linear equations.


Solve singular value decomposition problems.


Globally-used traits, structs, and enums




Assert that two ndarrays are logically equivalent, within tolerance.