Skip to content

Problem of writing a list of 2D arrays into one Dataset. #628

@ZL-Su

Description

@ZL-Su

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:

        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();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions