I'm trying to write a set of 2D arrays into a dataset, but an error is reported as follows:
"Failure to write contiguous data to dataset [/data]!"
Could anyone provide an impl. to write the 2D array data?
Thx!
The code I used is attached:
auto mat = cv::Mat_<float>(5, 20);
using namespace hdf5;
auto lc_list = property::LinkCreationList();
auto dc_list = property::DatasetCreationList();
dc_list.layout(property::DatasetLayout::Chunked);
dc_list.chunk({ size_t(mat.rows), size_t(mat.cols), 100});
const auto hpath = std::filesystem::path(path.toStdString() + "/data.h5");
using std::filesystem::exists;
auto f = file::create(hpath, file::AccessFlags::Truncate);
auto root_group = f.root();
dataspace::Simple space{ {0,0,0},{size_t(mat.rows), size_t(mat.cols), dataspace::Simple::unlimited} };
auto type = datatype::create(mat);
auto dataset = node::Dataset(root_group, "data", type, space, lc_list, dc_list);
dataspace::Hyperslab sel({ 0,0,0 }, { size_t(mat.rows), size_t(mat.cols), 1 }, { 1,1,1 });
for (auto i = 0; i < 10; ++i) {
mat = float(i);
dataset.extent(2, 1);
dataset.write(mat, sel);
sel.offset(2, i);
}
f.close();
Hi,
I'm trying to write a set of 2D arrays into a dataset, but an error is reported as follows: "Failure to write contiguous data to dataset [/data]!" Could anyone provide an impl. to write the 2D array data? Thx!
The code I used is attached: