From 04ebbec891554720f9a574f48efd1570b2a444d2 Mon Sep 17 00:00:00 2001 From: Luc Grosheintz Date: Wed, 8 May 2024 09:16:22 +0200 Subject: [PATCH 1/2] Fix bug in `Attribute::squeezeMemSpace`. --- include/highfive/bits/H5Attribute_misc.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/highfive/bits/H5Attribute_misc.hpp b/include/highfive/bits/H5Attribute_misc.hpp index e626d823d..98b16ec1b 100644 --- a/include/highfive/bits/H5Attribute_misc.hpp +++ b/include/highfive/bits/H5Attribute_misc.hpp @@ -167,7 +167,7 @@ inline Attribute Attribute::squeezeMemSpace(const std::vector& 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; } From 011c6755b6386b2dc65aeea90cbbfeb1264ef517 Mon Sep 17 00:00:00 2001 From: Luc Grosheintz Date: Wed, 8 May 2024 09:56:07 +0200 Subject: [PATCH 2/2] Test `Attribute::{squeeze,reshape}MemSpace`. --- tests/unit/tests_high_five_base.cpp | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/tests/unit/tests_high_five_base.cpp b/tests/unit/tests_high_five_base.cpp index 8d2f021aa..16da4bf80 100644 --- a/tests/unit/tests_high_five_base.cpp +++ b/tests/unit/tests_high_five_base.cpp @@ -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 +void check_modify_mem_space(File& file) { + const std::string name = "dset"; auto expected_values = std::vector{1.0, 2.0, 3.0}; auto values = std::vector>{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>(); + auto actual_values = obj.squeezeMemSpace({0}).template read>(); REQUIRE(actual_values.size() == expected_values.size()); for (size_t i = 0; i < actual_values.size(); ++i) { @@ -1669,7 +1667,7 @@ TEST_CASE("SqueezeMemSpace") { } SECTION("reshape") { - auto actual_values = dset.reshapeMemSpace({3}).read>(); + auto actual_values = obj.reshapeMemSpace({3}).template read>(); REQUIRE(actual_values.size() == expected_values.size()); for (size_t i = 0; i < actual_values.size(); ++i) { @@ -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(file); +} + +TEST_CASE("Modify Mem Space, dset") { + File file("h5_modify_memspace_attr.h5", File::Truncate); + check_modify_mem_space(file); +} + + template struct CreateEmptyVector;