Expand description
A slas backend defines how a set of supported algebraic operations can be performed on a specific software and/or hardware configuration.
operations
The first argument of an operations, should be a reference to an instance of the backend to run the operation on. The following arguments should just be the arguments of the operation.
The possible operations that can be implemented for a backend and its associated functions are:
operations::DotProduct
Implemented for complex and real floats on slas_backend::Blas
.
Implemented for real floats on slas_backend::Rust
.
dot
Should take two vectors of equal length, and return their dot product.
operations::Normalize
Implemented for real floats on slas_backend::Rust
.
norm
Should return the euclidean length of a vector.
normalize
Should normalize self (devide each element by the norm of the vector)
operations::MatrixMul
Implemented for f32 and f64 -floats on slas_backend::Blas
.
matrix_mul
Matrix-Matrix multiplication
vector_mul
Matrix-Vector multiplication
operations::Transpose
Operation for transposing matricies, not general tensors.
Implemented for all floats on slas_backend::Rust
transpose
Transpose matrix into buffer
transpose_inplace
Transpose matrix into self
Addition, Subtraction, Multiplication and Divition
Basic element-wise vector operations implemented on slas_backend::Rust
for f32 and f64 floats.
Addition has one method, add
,
which takes two input vectors and a buffer,
same applies to other element-wise operations.
How to specify backend
If you’re trying to use slas on a system where blas isn’t available,
you can use the slas_backend::Rust
statically.
use slas::prelude::*;
assert_eq!(
moo![on slas_backend::Rust:f32: 0..4]
.dot(&[1., 2., 3., 4.].moo_ref().static_backend()),
20.
);
Custom backend example
use slas::prelude::*;
use slas::backends::operations;
#[derive(Default)]
pub struct CustomBackend;
impl<T: Float + std::iter::Sum> operations::DotProduct<T> for CustomBackend {
fn dot<const LEN: usize>(
&self,
a: &impl StaticVec<T, LEN>,
b: &impl StaticVec<T, LEN>,
) -> T {
a.moo_ref().iter().zip(b.moo_ref().iter()).map(|(&a, &b)| a * b).sum()
}
}
impl<T> Backend<T> for CustomBackend{}
Modules
Structs
A pure rust slas backend with simd support.
Perform opertaions on a StaticVec
with a static backend.