Skip to content

Commit

Permalink
Bug fix in h5::array_interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Thoemi09 committed Apr 30, 2024
1 parent 893a621 commit 7fed273
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions c++/h5/array_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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};
}

Expand Down
2 changes: 1 addition & 1 deletion test/c++/h5_array_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void check_strides(const std::vector<long> &np_strides, const std::vector<long>
for (int i = static_cast<int>(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]);
}
}

Expand Down

0 comments on commit 7fed273

Please sign in to comment.