|
Ublas : |
Subject: [ublas] fill ublas matrix from array
From: Kraus Philipp (philipp.kraus_at_[hidden])
Date: 2010-11-14 09:50:53
Hello,
I have written a wrapper class for HDF 5 datatypes. At this time I
read a static array of my HDF structur into a Boost matrix with this
code:
ublas::matrix<T> l_mat(l_size[1],l_size[0]);
T l_data[l_size[0]][l_size[1]];
l_dataset.read( l_data, p_datatype );
for(std::size_t i=0; i < l_mat.size1(); ++i)
for(std::size_t j=0; j < l_mat.size2(); ++j)
l_mat(i,j) = l_data[j][i];
T is a template variable like double or float, p_datatype is the
datatype in the HDF file. l_dataset is the structur of the HDF file
with the data. This code works but my question is, can I create the
Boost matrix only from the static array l_data? I would like to remove
the both for-loops to this
T l_data[l_size[0]][l_size[1]];
l_dataset.read( l_data, p_datatype );
ublas::matrix<T> l_mat(l_data);
or can I use a reference of the data structure of the matrix like:
ublas::matrix<T> l_mat(l_size[1],l_size[0]);
l_dataset.read( &l_data.getDataRefernce(), p_datatype );
Do you have any idea for filling the matrix?
Thanks
Phil