# Using CXXBLAS

FLENS matrix/vector types make iteraction with BLAS easy as you have access to

• matrix/vector dimensions,

• storage order,

• leading dimensions and strides and

• data pointers.

In addition CXXBLAS makes it easy to reuse the same code for different element types like float, double, std::complex<float>, std::complex<double> or any other type that “can be used like a double”, i.e. relevant operators (e.g. +, *, ...) are overloaded.

## Toy Example

Assume you want to 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 CXXBLAS for this task you will first call gemv and subsequently axpy.

## Example Code

#include <flens/flens.cxx>
#include <iostream>

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 = 123;
y = 234;
z = 345;

GEMatrix A(3,3);
A = 123,
567,
543;

cxxblas::gemv(A.order(), Trans, A.numRows(), A.numCols(),
x.data(), x.stride(),
beta,
y.data(), y.stride());

cxxblas::axpy(y.length(), T(1), z.data(), z.stride(), y.data(), y.stride());

cout << "y = " << y << endl;

return 0;
}

Compute $$y = \beta y + \alpha A^T x$$

cxxblas::gemv(A.order(), Trans, A.numRows(), A.numCols(),
x.data(), x.stride(),
beta,
y.data(), y.stride());

Compute the update $$y = y + z$$

cxxblas::axpy(y.length(), T(1), z.data(), z.stride(), y.data(), y.stride());

## Compile and Run

$shell> cd flens/examples$shell> g++ -Wall -std=c++11 -I../.. tut02-page01-example.cc
\$shell> ./a.out
y =
47           50.5             54