Provides statically allocated vector, matrix and tensor types, for interfacing with blas/blis, in a performant manor, using copy-on-write (aka cow) behavior.
rust
use slas::prelude::*;
let a = moo![f32: 1, 2, 3.2];
let b = moo![f32: 3, 0.4, 5];
println!("Dot product of {:?} and {:?} is {:?}", a, b, a.dot(&b));
More example code here.
The copy-on-write functionality is inspired by std::borrow::cow. The idea is simply that allocations (and time) can be saved, by figuring out when to copy at runtime instead of at compiletime. This can be memory inefficient at times (as an enum takes the size of its largest field + tag size), but I'm planing on making ways around this in the future.
```rust
let source: Vec
// Here we mutate v, // so the content of source will be copied into v before the mutation occours. v[0] = 0.;
asserteq!(*v, [0., 2., 3.]); asserteq!(source, vec![1., 2., 3.]); ```
The borrow checker won't allow mutating source
after v
is created, because assignment to borrowed values is not allowed.
This can be a problem in some situations.
```rust
let mut source: Vec
// Here we can mutate source, because v was created from a raw pointer. source[1] = 3.; v[0] = 0.; source[2] = 4.;
asserteq!(*v, [0., 3., 3.]);
asserteq!(source, vec![1., 3., 4.]);
``
In the example above, you can see
vchanged value the first time
sourcewas mutated, but not the second time.
This is because
vwas copied when it was mutated at the line after the first mutation of
source`.
At the moment the way I want to implement these types, causes a compiler crash, when trying to create 2 objects with the same shape. For now I'm going to try to create a temporary, and more stable, way of dealing with these variations of static multi dimensional arrays.
As of now there is a Matrix type, but no tensor type on the master branch. The stable matricies are very basic, as I hopefully will be able to replace them with a more generic tensor type soon...
```rust use slas::{prelude::*, matrix::Matrix};
let m: Matrix
assert!(m[[1, 0]] == 2.);
let k: Matrix
println!("Product of {:?} and {:?} is {:?}", m, k, m * k); ```
If you want a look at whats to come in the future, you can go here for some very experimental source code for the project.
Slas can be faster than ndarray in some specifik use cases, like when having to do a lot of allocations, or when using referenced data in vector operations. Besides slas should always be atleast as fast as ndarray, so it can't hurt.
Statical allocation and the way slas cow behavior works with the borrow checker, also means that you might catch a lot of bugs at compiletime, where ndarray most of the time will let you get away with pretty much anything.
StaticCowVec
type implements deref
and deref_mut
, so any method implemented for [T;LEN]
is also implemented for StaticCowVec
.License: Apache-2.0