This project is currently INACTIVE as Rust doesn't have the required features to realize my vision. Until at least something like custom fat pointers land in the compiler I won't be working on this.
You might be interested in ndarray which implements an N dimensional array with several "view" operations.
-- @japaric, 2016-05-02
PSA Development is now happening on the ng
branch.
linalg.rs
Linear algebra library with BLAS and LAPACK acceleration.
alpha * A * B + beta * C
reduces to a single GEMM call, and doesn't
allocate memory for the return value.A * B * .. * Z
is chosen at runtime to minimize the
number of operations and of temporary memory allocations.A[a:b, c:]
) via the slice
method:
A.slice((a..b, c..))
.The BLAS and LAPACK libraries must be available. In Ubuntu, you can install the reference implementations with the following commands:
$ sudo apt-get install libblas-dev
$ sudo apt-get install liblapack-dev
Though an optimized BLAS package like OpenBLAS is highly recommend.
If you saw the quick reference then you know that this library is not as nice to use as Numpy or Octave due to the lack of operator sugar.
Solving this issue requires changes in the compiler, here's a list with a brief description of each change and the sugar it enables:
A[i, j]
becomes the same as A[(i, j)]
, this lets us match Python's indexing syntax.let x = &A[i, j]; // === Index::index(&A, (i, j));
let y = B[i, j]; // === *Index::index(&B, (i, j));
// &Row, &mut Col, &SubMat are fat pointers like &[T]
let row: &Row = &A[i, ..]; // === Index::index(&A, (i, ..));
let col: &mut Col = &mut A[.., j]; // === IndexMut::index_mut(&mut A, (.., j));
let submat: &SubMat = &A[a..b, c..d]; // === Index::index(&A, (a..b, c..d));
[Op]Assign
traits. The RFC's here. This would let use augmented assignment sugar:A[i, ..] += &B[j, ..]; // === AddAssign::add_assign(&mut A[i, ..], &B[j, ..]);
A[a..b, c..d] *= 2; // === MulAssign::mul_assign(&mut A[a..b, c..d], 2);
IndexSet
. There's a postponed issue for this. This would enable sugar for setting/copying
sub-matrices:A[1, ..] = 0; // === IndexSet::index_set(&mut A[1, ..], 0);
A[..2, ..] = &B[2.., ..]; // === IndexSet::index_set(&mut A[..2, ..], &B[2.., ..]);
The best way to contribute to this library is by using it and reporting any problem you encounter.
If you hit a debug_assert!
, that's a bug. Please open an issue in the issue tracker. Note that
assert!
s are normal and indicate a programmer errors like index out of bounds or mismatched
dimensions.
If you get a wrong result from an operation, like A * A.inv()
not being equal to the identity
matrix, that's a bug too.
If some operation doesn't compile and you think it should (but read the Notes about operators first) that's a "missing operation" and should be reported.
If you need some feature from the LAPACK/BLAS libraries that's not currently exposed, open a feature request in the issue tracker.
Ideally all the core functionality should be tested, but the current test suite is not that extensive. There's a list of missing unit tests here, help would be appreciated.
If you ported some (small) program from Numpy/Octave to linalg
, consider submitting it as a
example.
If you have done any measurements between linalg
and other linear algebra libraries (in any
language), Let me know how linalg
performs, specially if measurements indicate that linalg
is slower.
linalg.rs is dual licensed under the Apache 2.0 license and the MIT license.
See LICENSE-APACHE and LICENSE-MIT for more details.