我有一个二维数据(行 x col),它正在boost::multi_array
容器中读取。我还需要知道我是否可以将这些数据读入ublas::vector
,例如,数据有三行并将它们读入三个向量v1,v2,v3:我对接口不是很熟悉ublas::vector
。数据存储在一个.h5
文件中,为了阅读我正在使用这个库。谁能告诉我如何boost::multi_array
替换ublas::vector
?还感谢您提出其他示例的建议。谢谢!
#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;
}