From 4a4211ac55f23a84ba963509ea862f66781d145f Mon Sep 17 00:00:00 2001 From: Luc Grosheintz Date: Mon, 29 Jan 2024 10:19:26 +0100 Subject: [PATCH 1/5] Add `read_raw` and deprecate `raw(T*, ...)`. --- include/highfive/bits/H5Slice_traits.hpp | 36 ++++++++++++++++++- include/highfive/bits/H5Slice_traits_misc.hpp | 24 ++++++++++--- 2 files changed, 55 insertions(+), 5 deletions(-) diff --git a/include/highfive/bits/H5Slice_traits.hpp b/include/highfive/bits/H5Slice_traits.hpp index c753026c3..5c3810108 100644 --- a/include/highfive/bits/H5Slice_traits.hpp +++ b/include/highfive/bits/H5Slice_traits.hpp @@ -292,6 +292,7 @@ class SliceTraits { /// /// Read the entire dataset into a buffer + /// /// An exception is raised is if the numbers of dimension of the buffer and /// of the dataset are different. /// @@ -305,13 +306,16 @@ class SliceTraits { /// /// Read the entire dataset into a raw buffer /// + /// \deprecated Use `read_raw` instead. + /// /// No dimensionality checks will be performed, it is the user's /// responsibility to ensure that the right amount of space has been /// allocated. /// \param array: A buffer containing enough space for the data - /// \param dtype: The type of the data, in case it cannot be automatically guessed + /// \param dtype: The datatype of elements of the in memory buffer. /// \param xfer_props: Data Transfer properties template + H5_DEPRECATED("Use 'read_raw' instead.") void read(T* array, const DataType& dtype, const DataTransferProps& xfer_props = DataTransferProps()) const; @@ -319,6 +323,8 @@ class SliceTraits { /// /// Read the entire dataset into a raw buffer /// + /// \deprecated Use `read_raw` instead. + /// /// Same as `read(T*, const DataType&, const DataTransferProps&)`. However, /// this overload deduces the HDF5 datatype of the element of `array` from /// `T`. Note, that the file datatype is already fixed. @@ -326,8 +332,36 @@ class SliceTraits { /// \param array: A buffer containing enough space for the data /// \param xfer_props: Data Transfer properties template + H5_DEPRECATED("Use 'read_raw' instead.") void read(T* array, const DataTransferProps& xfer_props = DataTransferProps()) const; + /// + /// Read the entire dataset into a raw buffer + /// + /// No dimensionality checks will be performed, it is the user's + /// responsibility to ensure that the right amount of space has been + /// allocated. + /// \param array: A buffer containing enough space for the data + /// \param dtype: The type of the data, in case it cannot be automatically guessed + /// \param xfer_props: Data Transfer properties + template + void read_raw(T* array, + const DataType& dtype, + const DataTransferProps& xfer_props = DataTransferProps()) const; + + /// + /// Read the entire dataset into a raw buffer + /// + /// Same as `read(T*, const DataType&, const DataTransferProps&)`. However, + /// this overload deduces the HDF5 datatype of the element of `array` from + /// `T`. Note, that the file datatype is already fixed. + /// + /// \param array: A buffer containing enough space for the data + /// \param xfer_props: Data Transfer properties + template + void read_raw(T* array, const DataTransferProps& xfer_props = DataTransferProps()) const; + + /// /// Write the integrality N-dimension buffer to this dataset /// An exception is raised is if the numbers of dimension of the buffer and diff --git a/include/highfive/bits/H5Slice_traits_misc.hpp b/include/highfive/bits/H5Slice_traits_misc.hpp index dd7e45b1d..88804f6d0 100644 --- a/include/highfive/bits/H5Slice_traits_misc.hpp +++ b/include/highfive/bits/H5Slice_traits_misc.hpp @@ -186,7 +186,7 @@ inline void SliceTraits::read(T& array, const DataTransferProps& xfer_ auto dims = mem_space.getDimensions(); auto r = details::data_converter::get_reader(dims, array, file_datatype); - read(r.getPointer(), buffer_info.data_type, xfer_props); + read_raw(r.getPointer(), buffer_info.data_type, xfer_props); // re-arrange results r.unserialize(array); @@ -207,12 +207,26 @@ inline void SliceTraits::read(T& array, const DataTransferProps& xfer_ } } - template template inline void SliceTraits::read(T* array, const DataType& mem_datatype, const DataTransferProps& xfer_props) const { + read_raw(array, mem_datatype, xfer_props); +} + +template +template +inline void SliceTraits::read(T* array, const DataTransferProps& xfer_props) const { + read_raw(array, xfer_props); +} + + +template +template +inline void SliceTraits::read_raw(T* array, + const DataType& mem_datatype, + const DataTransferProps& xfer_props) const { static_assert(!std::is_const::value, "read() requires a non-const structure to read data into"); @@ -226,13 +240,14 @@ inline void SliceTraits::read(T* array, static_cast(array)); } + template template -inline void SliceTraits::read(T* array, const DataTransferProps& xfer_props) const { +inline void SliceTraits::read_raw(T* array, const DataTransferProps& xfer_props) const { using element_type = typename details::inspector::base_type; const DataType& mem_datatype = create_and_check_datatype(); - read(array, mem_datatype, xfer_props); + read_raw(array, mem_datatype, xfer_props); } @@ -276,6 +291,7 @@ inline void SliceTraits::write_raw(const T* buffer, static_cast(buffer)); } + template template inline void SliceTraits::write_raw(const T* buffer, const DataTransferProps& xfer_props) { From bf5b8c25b6168b80d6498932e32de146381bbbc3 Mon Sep 17 00:00:00 2001 From: Luc Grosheintz Date: Mon, 29 Jan 2024 11:19:55 +0100 Subject: [PATCH 2/5] Cases of containers being picked up as pointers. These cases are modernized to silence the compiler. These semantically, don't write a from a raw pointer. However, the compiler picks the overload for pointers in these cases and it kinda works. --- tests/unit/test_high_five_selection.cpp | 8 ++++---- tests/unit/tests_high_five_base.cpp | 14 +++++++------- tests/unit/tests_high_five_multi_dims.cpp | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/unit/test_high_five_selection.cpp b/tests/unit/test_high_five_selection.cpp index e3b91e4cc..2c29e9990 100644 --- a/tests/unit/test_high_five_selection.cpp +++ b/tests/unit/test_high_five_selection.cpp @@ -124,14 +124,14 @@ TEST_CASE("selectionByElementMultiDim") { { int value[2]; - set.select(ElementSet{0, 0, 2, 2}).read(value); + set.select(ElementSet{0, 0, 2, 2}).read_raw(value); CHECK(value[0] == 1); CHECK(value[1] == 9); } { int value[2]; - set.select(ElementSet{{0, 1}, {1, 2}}).read(value); + set.select(ElementSet{{0, 1}, {1, 2}}).read_raw(value); CHECK(value[0] == 2); CHECK(value[1] == 6); } @@ -175,7 +175,7 @@ void columnSelectionTest() { Selection slice = dataset.select(columns); T result[x_size][3]; - slice.read(result); + slice.read_raw(result); CHECK(slice.getSpace().getDimensions()[0] == x_size); CHECK(slice.getMemSpace().getDimensions()[0] == x_size); @@ -508,7 +508,7 @@ void irregularHyperSlabSelectionWriteTest() { file.getDataSet(dataset_name).select(test_case.slab).write(changed_values); T overwritten_values[x_size][y_size]; - file.getDataSet(dataset_name).read(overwritten_values); + file.getDataSet(dataset_name).read_raw(overwritten_values); T expected_values[x_size][y_size]; for (size_t i = 0; i < x_size; ++i) { diff --git a/tests/unit/tests_high_five_base.cpp b/tests/unit/tests_high_five_base.cpp index 163535b55..7463cba7c 100644 --- a/tests/unit/tests_high_five_base.cpp +++ b/tests/unit/tests_high_five_base.cpp @@ -538,7 +538,7 @@ TEST_CASE("Test extensible datasets") { DataSet dataset_absolute = file.getDataSet("/" + dataset_name); const auto dims = dataset_absolute.getSpace().getDimensions(); long double values[4][6]; - dataset_absolute.read(values); + dataset_absolute.read_raw(values); CHECK(4 == dims[0]); CHECK(6 == dims[1]); @@ -595,7 +595,7 @@ TEST_CASE("Test reference count") { d1_ptr.reset(); double values[10][10]; - d2.read(values); + d2.read_raw(values); for (std::size_t i = 0; i < 10; ++i) { for (std::size_t j = 0; j < 10; ++j) { @@ -950,7 +950,7 @@ TEST_CASE("HighFiveReadWriteShortcut") { DataSet ds_int2 = file.createDataSet("/TmpCArrayInt", int_c_array); decltype(int_c_array) int_c_array_out; - ds_int2.read(int_c_array_out); + ds_int2.read_raw(int_c_array_out); for (size_t i = 0; i < 10; ++i) { REQUIRE(int_c_array[i] == int_c_array_out[i]); } @@ -962,7 +962,7 @@ TEST_CASE("HighFiveReadWriteShortcut") { DataSet ds_char2 = file.createDataSet("/TmpCArray2dchar", char_c_2darray); decltype(char_c_2darray) char_c_2darray_out; - ds_char2.read(char_c_2darray_out); + ds_char2.read_raw(char_c_2darray_out); for (size_t i = 0; i < 4; ++i) { for (size_t j = 0; j < 3; ++j) { REQUIRE(char_c_2darray[i][j] == char_c_2darray_out[i][j]); @@ -1231,7 +1231,7 @@ void readWriteShuffleDeflateTest() { T result[x_size][y_size]; - dataset_read.read(result); + dataset_read.read_raw(result); for (size_t i = 0; i < x_size; ++i) { for (size_t j = 0; i < y_size; ++i) { @@ -1294,7 +1294,7 @@ void readWriteSzipTest() { T result[x_size][y_size]; - dataset_read.read(result); + dataset_read.read_raw(result); for (size_t i = 0; i < x_size; ++i) { for (size_t j = 0; i < y_size; ++i) { @@ -1477,7 +1477,7 @@ TEST_CASE("ReadInBroadcastDims") { { char read_back[2]; - dataset.read(read_back); + dataset.read_raw(read_back); CHECK(read_back[0] == 'a'); CHECK(read_back[1] == '\0'); diff --git a/tests/unit/tests_high_five_multi_dims.cpp b/tests/unit/tests_high_five_multi_dims.cpp index 08fbea9ce..966bbf8f8 100644 --- a/tests/unit/tests_high_five_multi_dims.cpp +++ b/tests/unit/tests_high_five_multi_dims.cpp @@ -52,7 +52,7 @@ void readWrite2DArrayTest() { dataset.write(array); T result[x_size][y_size]; - dataset.read(result); + dataset.read_raw(result); for (size_t i = 0; i < x_size; ++i) { for (size_t j = 0; j < y_size; ++j) { From 7bb912a72dc9c999b5f38e65c1e8056d5891c2ba Mon Sep 17 00:00:00 2001 From: Luc Grosheintz Date: Mon, 29 Jan 2024 11:23:11 +0100 Subject: [PATCH 3/5] Modernize tests. --- src/examples/read_write_raw_ptr.cpp | 2 +- tests/unit/tests_high_five_base.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/examples/read_write_raw_ptr.cpp b/src/examples/read_write_raw_ptr.cpp index b6cd9eda5..4c8b563cb 100644 --- a/src/examples/read_write_raw_ptr.cpp +++ b/src/examples/read_write_raw_ptr.cpp @@ -66,7 +66,7 @@ int main(void) { auto nd_array = std::vector(n_elements); // Finally, read into the memory by passing a raw pointer to the library. - dataset.read(nd_array.data()); + dataset.read_raw(nd_array.data()); } return 0; diff --git a/tests/unit/tests_high_five_base.cpp b/tests/unit/tests_high_five_base.cpp index 7463cba7c..aa12e4d38 100644 --- a/tests/unit/tests_high_five_base.cpp +++ b/tests/unit/tests_high_five_base.cpp @@ -2452,7 +2452,7 @@ TEST_CASE("HighFiveFixedString") { // Due to missing non-const overload of `data()` until C++17 we'll // read into something else instead (don't forget the '\0'). auto expected = std::vector(n_chars, '!'); - ds.read(expected.data(), datatype); + ds.read_raw(expected.data(), datatype); CHECK(expected.size() == value.size() + 1); for (size_t i = 0; i < value.size(); ++i) { @@ -2483,7 +2483,7 @@ TEST_CASE("HighFiveFixedString") { ds.write_raw(value.data(), datatype); auto expected = std::vector(value.size(), '-'); - ds.read(expected.data(), datatype); + ds.read_raw(expected.data(), datatype); CHECK(expected.size() == value.size()); for (size_t i = 0; i < value.size(); ++i) { From 2ff78546d944577df4e4a8a7855aa37f0c67c626 Mon Sep 17 00:00:00 2001 From: Luc Grosheintz Date: Mon, 29 Jan 2024 13:45:35 +0100 Subject: [PATCH 4/5] Don't deprecate. --- include/highfive/bits/H5Slice_traits.hpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/include/highfive/bits/H5Slice_traits.hpp b/include/highfive/bits/H5Slice_traits.hpp index 5c3810108..556683853 100644 --- a/include/highfive/bits/H5Slice_traits.hpp +++ b/include/highfive/bits/H5Slice_traits.hpp @@ -315,7 +315,6 @@ class SliceTraits { /// \param dtype: The datatype of elements of the in memory buffer. /// \param xfer_props: Data Transfer properties template - H5_DEPRECATED("Use 'read_raw' instead.") void read(T* array, const DataType& dtype, const DataTransferProps& xfer_props = DataTransferProps()) const; @@ -332,7 +331,6 @@ class SliceTraits { /// \param array: A buffer containing enough space for the data /// \param xfer_props: Data Transfer properties template - H5_DEPRECATED("Use 'read_raw' instead.") void read(T* array, const DataTransferProps& xfer_props = DataTransferProps()) const; /// From 6078ebe425e0d031cc7e45143e298f51df548447 Mon Sep 17 00:00:00 2001 From: Luc Grosheintz Date: Mon, 29 Jan 2024 13:45:45 +0100 Subject: [PATCH 5/5] Revert "Cases of containers being picked up as pointers." This reverts commit 5e86ac824dd48df04727ac74c88b64bea2b586e0. --- tests/unit/test_high_five_selection.cpp | 8 ++++---- tests/unit/tests_high_five_base.cpp | 14 +++++++------- tests/unit/tests_high_five_multi_dims.cpp | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/unit/test_high_five_selection.cpp b/tests/unit/test_high_five_selection.cpp index 2c29e9990..e3b91e4cc 100644 --- a/tests/unit/test_high_five_selection.cpp +++ b/tests/unit/test_high_five_selection.cpp @@ -124,14 +124,14 @@ TEST_CASE("selectionByElementMultiDim") { { int value[2]; - set.select(ElementSet{0, 0, 2, 2}).read_raw(value); + set.select(ElementSet{0, 0, 2, 2}).read(value); CHECK(value[0] == 1); CHECK(value[1] == 9); } { int value[2]; - set.select(ElementSet{{0, 1}, {1, 2}}).read_raw(value); + set.select(ElementSet{{0, 1}, {1, 2}}).read(value); CHECK(value[0] == 2); CHECK(value[1] == 6); } @@ -175,7 +175,7 @@ void columnSelectionTest() { Selection slice = dataset.select(columns); T result[x_size][3]; - slice.read_raw(result); + slice.read(result); CHECK(slice.getSpace().getDimensions()[0] == x_size); CHECK(slice.getMemSpace().getDimensions()[0] == x_size); @@ -508,7 +508,7 @@ void irregularHyperSlabSelectionWriteTest() { file.getDataSet(dataset_name).select(test_case.slab).write(changed_values); T overwritten_values[x_size][y_size]; - file.getDataSet(dataset_name).read_raw(overwritten_values); + file.getDataSet(dataset_name).read(overwritten_values); T expected_values[x_size][y_size]; for (size_t i = 0; i < x_size; ++i) { diff --git a/tests/unit/tests_high_five_base.cpp b/tests/unit/tests_high_five_base.cpp index aa12e4d38..bf41a29c6 100644 --- a/tests/unit/tests_high_five_base.cpp +++ b/tests/unit/tests_high_five_base.cpp @@ -538,7 +538,7 @@ TEST_CASE("Test extensible datasets") { DataSet dataset_absolute = file.getDataSet("/" + dataset_name); const auto dims = dataset_absolute.getSpace().getDimensions(); long double values[4][6]; - dataset_absolute.read_raw(values); + dataset_absolute.read(values); CHECK(4 == dims[0]); CHECK(6 == dims[1]); @@ -595,7 +595,7 @@ TEST_CASE("Test reference count") { d1_ptr.reset(); double values[10][10]; - d2.read_raw(values); + d2.read(values); for (std::size_t i = 0; i < 10; ++i) { for (std::size_t j = 0; j < 10; ++j) { @@ -950,7 +950,7 @@ TEST_CASE("HighFiveReadWriteShortcut") { DataSet ds_int2 = file.createDataSet("/TmpCArrayInt", int_c_array); decltype(int_c_array) int_c_array_out; - ds_int2.read_raw(int_c_array_out); + ds_int2.read(int_c_array_out); for (size_t i = 0; i < 10; ++i) { REQUIRE(int_c_array[i] == int_c_array_out[i]); } @@ -962,7 +962,7 @@ TEST_CASE("HighFiveReadWriteShortcut") { DataSet ds_char2 = file.createDataSet("/TmpCArray2dchar", char_c_2darray); decltype(char_c_2darray) char_c_2darray_out; - ds_char2.read_raw(char_c_2darray_out); + ds_char2.read(char_c_2darray_out); for (size_t i = 0; i < 4; ++i) { for (size_t j = 0; j < 3; ++j) { REQUIRE(char_c_2darray[i][j] == char_c_2darray_out[i][j]); @@ -1231,7 +1231,7 @@ void readWriteShuffleDeflateTest() { T result[x_size][y_size]; - dataset_read.read_raw(result); + dataset_read.read(result); for (size_t i = 0; i < x_size; ++i) { for (size_t j = 0; i < y_size; ++i) { @@ -1294,7 +1294,7 @@ void readWriteSzipTest() { T result[x_size][y_size]; - dataset_read.read_raw(result); + dataset_read.read(result); for (size_t i = 0; i < x_size; ++i) { for (size_t j = 0; i < y_size; ++i) { @@ -1477,7 +1477,7 @@ TEST_CASE("ReadInBroadcastDims") { { char read_back[2]; - dataset.read_raw(read_back); + dataset.read(read_back); CHECK(read_back[0] == 'a'); CHECK(read_back[1] == '\0'); diff --git a/tests/unit/tests_high_five_multi_dims.cpp b/tests/unit/tests_high_five_multi_dims.cpp index 966bbf8f8..08fbea9ce 100644 --- a/tests/unit/tests_high_five_multi_dims.cpp +++ b/tests/unit/tests_high_five_multi_dims.cpp @@ -52,7 +52,7 @@ void readWrite2DArrayTest() { dataset.write(array); T result[x_size][y_size]; - dataset.read_raw(result); + dataset.read(result); for (size_t i = 0; i < x_size; ++i) { for (size_t j = 0; j < y_size; ++j) {