Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in Attribute::squeezeMemSpace. #995

Merged
merged 2 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/highfive/bits/H5Attribute_misc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ inline Attribute Attribute::squeezeMemSpace(const std::vector<size_t>& axes) con
auto squeezed_dims = detail::squeeze(mem_dims, axes);

auto attr = *this;
attr._mem_space = DataSpace(mem_dims);
attr._mem_space = DataSpace(squeezed_dims);
return attr;
}

Expand Down
25 changes: 17 additions & 8 deletions tests/unit/tests_high_five_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1649,18 +1649,16 @@ TEST_CASE("squeeze") {
CHECK_THROWS(detail::squeeze({}, {0}));
}

TEST_CASE("SqueezeMemSpace") {
const std::string file_name("h5_squeeze_memspace.h5");
const std::string dataset_name("dset");

File file(file_name, File::Truncate);
template <class CreateTraits>
void check_modify_mem_space(File& file) {
const std::string name = "dset";

auto expected_values = std::vector<double>{1.0, 2.0, 3.0};
auto values = std::vector<std::vector<double>>{expected_values};

auto dset = file.createDataSet(dataset_name, values);
auto obj = CreateTraits::create(file, name, values);
SECTION("squeeze") {
auto actual_values = dset.squeezeMemSpace({0}).read<std::vector<double>>();
auto actual_values = obj.squeezeMemSpace({0}).template read<std::vector<double>>();

REQUIRE(actual_values.size() == expected_values.size());
for (size_t i = 0; i < actual_values.size(); ++i) {
Expand All @@ -1669,7 +1667,7 @@ TEST_CASE("SqueezeMemSpace") {
}

SECTION("reshape") {
auto actual_values = dset.reshapeMemSpace({3}).read<std::vector<double>>();
auto actual_values = obj.reshapeMemSpace({3}).template read<std::vector<double>>();

REQUIRE(actual_values.size() == expected_values.size());
for (size_t i = 0; i < actual_values.size(); ++i) {
Expand All @@ -1678,6 +1676,17 @@ TEST_CASE("SqueezeMemSpace") {
}
}

TEST_CASE("Modify Mem Space, attr") {
File file("h5_modify_memspace_dset.h5", File::Truncate);
check_modify_mem_space<testing::DataSetCreateTraits>(file);
}

TEST_CASE("Modify Mem Space, dset") {
File file("h5_modify_memspace_attr.h5", File::Truncate);
check_modify_mem_space<testing::AttributeCreateTraits>(file);
}


template <int n_dim>
struct CreateEmptyVector;

Expand Down
Loading