Skip to content

feature ublas_00004_matrix_view

Nasos edited this page Jan 27, 2016 · 3 revisions

A matrix_view is a shallow container that can be used to represent matrix data. A shallow container doesn't own the data it is referring to. It can only modify the values of this data.

The view aids in integrating uBlas with existing code bases and provides a friendly way to deal with data sharing.

For example you may have a matrix of vertices, used to plot some surface on OpenGL. Your 3D engine can keep them in a buffer in memory and by using a matrix view you can manipulate them using uBLAS algorithms without copying the data back and forth.

An example implementation of a sparse view can be found here: https://github.com/uBLAS/ublas/blob/master/include/boost/numeric/ublas/experimental/sparse_view.hpp

See also: feature ublas_00003_vector_view

Planned interface:

double *p = ...; // p is a pointer to some array in memory
ublas::matrix_view<double> M(p, 1000, 1000); // Define a view of 1000x1000 double elements

// Use it like a regular ublas MATRIX:
for (auto i=0; i!=v.size1(); i++)
    for (auto j=0; j!=v.size2(); j++)
       M(i,J) = 2*i+22+3*j;

Branch source code:

https://github.com/uBLAS/ublas/tree/ublas_feature0002_matrix_view