Module rds::blas [] [src]

Module containing Blas bindings and overloaded operation for NDData.

Introduction

Blas functionalities are implemented for any struct implementing NDDataMut<T> where T is either f32 or f64.

The convention is that the calling array is always the output array. This means for example that a matrix vector multiplication should be called on the vector. Whether a matrix need a translation or not is infered by the framework. If there are more than one solution, the one requiring the less translations is taken.

The operators are overloaded to use those Blas functions, however they only operate on references making the syntax a bit weird.

Examples

Blas level 1

use rds::array::{NDDataMut, NDArray};
use rds::blas::Blas;
 
let mut array1 = NDArray::<f32>::new(&[5], 1.0);
assert!(array1.asum() == 5.0);
assert!(array1.asum() == 5.0);
array1.scal(2.0);
let mut array2 = NDArray::<f32>::copy(&array1);
assert!(array1.dot(&array2) == 20.0);
array2 += &array1;
assert!(array2.asum() == 20.0);

Blas level 2

use rds::array::{NDDataMut, NDArray};
use rds::blas::Blas;
 
let vec1 = NDArray::<f32>::from_slice(&[2], &[2.0, 0.0]);
let mut vec2 = NDArray::<f32>::copy(&vec1);
let rot90 = NDArray::<f32>::from_slice(&[2,2], &[0.0, -1.0, 1.0, 0.0]);
vec2 *= &rot90;
assert!(vec1.dot(&vec2) == 0.0);
assert!(vec2 == NDArray::<f32>::from_slice(&[2], &[0.0, 2.0]));

Blas level 3

use rds::array::{NDDataMut, NDArray};
use rds::blas::Blas;
 
let rot90 = NDArray::<f32>::from_slice(&[2,2], &[0.0, -1.0, 1.0, 0.0]);
let rot180 = &rot90 * &rot90;
let identity = NDArray::<f32>::from_slice(&[2,2], &[1.0, 0.0, 0.0, 1.0]);
let mut transformed = NDArray::<f32>::copy(&identity);
transformed *= &rot90;
transformed *= &rot180;
transformed *= &rot90;
assert!(transformed == identity);

Traits

Blas

A trait representing N-dimensional array on which blas functions can be applied.