From 7fed2738bcf3b73307cb7fd57cd931269102a567 Mon Sep 17 00:00:00 2001 From: Thomas Hahn Date: Tue, 30 Apr 2024 11:14:45 -0400 Subject: [PATCH] Bug fix in h5::array_interface --- c++/h5/array_interface.cpp | 7 ++++--- test/c++/h5_array_interface.cpp | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/c++/h5/array_interface.cpp b/c++/h5/array_interface.cpp index 043a49c..c6b3ee9 100644 --- a/c++/h5/array_interface.cpp +++ b/c++/h5/array_interface.cpp @@ -77,9 +77,6 @@ namespace h5::array_interface { // create the result vectors v_t parent_shape(rank), h5_strides(rank); - // from the above equations it follows that parent_shape[0] (size of the slowest varying dimension) is arbitrary - parent_shape[0] = view_size; - // We initialize the h5_strides array to the values of np_strides // and successively divide off the parent_shape values as they appear // in the equations above. @@ -91,6 +88,10 @@ namespace h5::array_interface { for (int v = u; v >= 0; --v) { h5_strides[v] /= gcd; } } + // from the above equations it follows that parent_shape[0] (size of the slowest varying dimension) + // is arbitrary as long as it is big enough to contain the elements selected by the hyperslab + parent_shape[0] = view_size * h5_strides[0]; + return {parent_shape, h5_strides}; } diff --git a/test/c++/h5_array_interface.cpp b/test/c++/h5_array_interface.cpp index d669278..491bcfd 100644 --- a/test/c++/h5_array_interface.cpp +++ b/test/c++/h5_array_interface.cpp @@ -49,7 +49,7 @@ void check_strides(const std::vector &np_strides, const std::vector for (int i = static_cast(np_strides.size()) - 1; i >= 0; --i) { EXPECT_EQ(np_strides[i], product * h5_strides[i]); product *= parent_shape[i]; - EXPECT_TRUE(parent_shape[i] >= view_shape[i]); + EXPECT_TRUE(parent_shape[i] >= view_shape[i] * h5_strides[i]); } }