I have a 2 dimensional data(row x col), which was reading in a boost::multi_array
container. I also need to know if I can read this data into ublas::vector
, e.g., data has three rows and read them into three vectors v1, v2, v3: I am not very familiar with the interface of ublas::vector
.
Data is stored in a .h5
file and in order to read I'm using this library. Can anyone show me how to replace boost::multi_array
with the ublas::vector
?
Suggestion with some other example is also appreciated. Thanks!
#include <boost/multi_array.hpp>
#include <h5xx/h5xx.hpp>
#include <iostream>
#include <boost/numeric/ublas/vector.hpp>
using array_2d_t = boost::multi_array<float, 2>;
template <typename T>
void print_array(T const& array)
{
for (auto const& row : array)
{ for (auto v : row)
printf("%10f ", v);
printf("\n");
}
std::cout << "\n End of file " << std::endl;
}
array_2d_t read_frame(std::string const& filename) {
h5xx::file xaa(filename, h5xx::file::mode::in);
h5xx::group g(xaa, "particles/lipids/box/edges");
h5xx::dataset ds(g, "box_size");
auto ds_shape = h5xx::dataspace(ds).extents<2>();
array_2d_t arr(boost::extents[ds_shape[0]][ds_shape[1]]);
h5xx::read_dataset(ds, arr);
return arr;
}
int main(int argc, char const* argv[]) {
if ( argc < 2) {
std::cout << "Usage: " << argv[0] << " input.h5 " << std::endl;
return -1;
}
std::string filename(argv[1]);
auto count = read_frame(filename);
std::cout << "Frames in file: " << count[1][1] << "\n";
print_array(count);
return 0;
}