Content |
Using FLENS-BLAS
FLENS-BLAS is built on top of CXXBLAS and utilizes FLENS matrix/vector types. Main benefits are:
-
It is easier to use as functions from FLENS-BLAS require less arguments
-
Technical details like are encapsulated in the implementation and hidden from the user. You pass complete matrix/vector types instead of things like pointers and dimensions. This makes your code less error prone.
Toy Example
We use the same example as before, i.e. we compute \(y = \beta y + \alpha\,A^T x + z\) where \(\alpha, \beta\) are scalars, \(x, y, z\) are (dense) vectors and \(A\) is a (general) matrix (with full storage).
Using FLENS-BLAS for this task we
As long as you do not compile with -DNDEBUG the FLENS-BLAS layer also does some error-checking on its arguments.
Example Code
#include <flens/flens.cxx>
using namespace flens;
using namespace std;
int
main()
{
typedef double T;
typedef DenseVector<Array<T> > DEVector;
typedef GeMatrix<FullStorage<T, ColMajor> > GEMatrix;
const T alpha = 1.5,
beta = 2.5;
DEVector x(3), y(3), z(3);
x = 1, 2, 3;
y = 2, 3, 4;
z = 3, 4, 5;
GEMatrix A(3,3);
A = 1, 2, 3,
5, 6, 7,
5, 4, 3;
blas::mv(Trans, alpha, A, x, beta, y);
blas::axpy(T(1), z, y);
cout << "y = " << y << endl;
return 0;
}
Comments on Example Code
Compute \(y = \beta y + \alpha A^T x\)
Compute the update \(y = y + z\)
Compile and Run
$shell> cd flens/examples $shell> g++ -Wall -std=c++11 -I../.. tut02-page02-example.cc $shell> ./a.out y = 47 50.5 54