diff --git a/tests/unit/data_generator.hpp b/tests/unit/data_generator.hpp index 872c1840f..624257e9d 100644 --- a/tests/unit/data_generator.hpp +++ b/tests/unit/data_generator.hpp @@ -8,6 +8,10 @@ #include #include +#ifdef H5_USE_BOOST +#include +#endif + #include namespace HighFive { @@ -58,7 +62,10 @@ static size_t flat_size(const std::vector& dims) { return n; } +template +struct DataGeneratorTraits; +// -- Scalar basecases --------------------------------------------------------- template struct ScalarDataGeneratorTraits { using container_type = T; @@ -77,9 +84,18 @@ struct ScalarDataGeneratorTraits { } }; -template -struct DataGeneratorTraits; +template +struct DataGeneratorTraits::value>::type> + : public ScalarDataGeneratorTraits {}; + +template +struct DataGeneratorTraits::value>::type> + : public ScalarDataGeneratorTraits {}; + +template <> +struct DataGeneratorTraits: public ScalarDataGeneratorTraits {}; +// -- STL ---------------------------------------------------------------------- template <> struct DataGeneratorTraits> { using container_type = std::vector; @@ -101,7 +117,6 @@ struct DataGeneratorTraits> { } }; - template struct DataGeneratorSTLLikeTraits { using container_type = Container; @@ -156,16 +171,76 @@ struct DataGeneratorTraits>: public DataGeneratorSTLLikeTraits< } }; -template -struct DataGeneratorTraits::value>::type> - : public ScalarDataGeneratorTraits {}; +// -- Boost ------------------------------------------------------------------- +#ifdef H5_USE_BOOST +template +struct DataGeneratorTraits> { + using container_type = typename boost::multi_array; + using value_type = T; + using base_type = typename DataGeneratorTraits::base_type; -template -struct DataGeneratorTraits::value>::type> - : public ScalarDataGeneratorTraits {}; + static void set(container_type& array, + const std::vector& indices, + const base_type& value) { + auto i = std::vector(indices.begin(), indices.begin() + n); + return DataGeneratorTraits::set(array(i), lstrip(indices, n), value); + } + + static base_type get(const container_type& array, const std::vector& indices) { + auto i = std::vector(indices.begin(), indices.begin() + n); + return DataGeneratorTraits::get(array(i), lstrip(indices, n)); + } + + static container_type allocate(const std::vector& dims) { + auto local_dims = std::vector(dims.begin(), dims.begin() + n); + container_type array(local_dims); + + size_t n_elements = flat_size(local_dims); + for (size_t i = 0; i < n_elements; ++i) { + auto element = DataGeneratorTraits::allocate(lstrip(dims, n)); + set(array, unravel(i, local_dims), element); + } + + return array; + } +}; + +template +struct DataGeneratorTraits> { + using container_type = typename boost::numeric::ublas::matrix; + using value_type = T; + using base_type = typename DataGeneratorTraits::base_type; + + static void set(container_type& array, + const std::vector& indices, + const base_type& value) { + auto i = indices[0]; + auto j = indices[1]; + return DataGeneratorTraits::set(array(i, j), lstrip(indices, 2), value); + } + + static base_type get(const container_type& array, const std::vector& indices) { + auto i = indices[0]; + auto j = indices[1]; + return DataGeneratorTraits::get(array(i, j), lstrip(indices, 2)); + } + + static container_type allocate(const std::vector& dims) { + auto local_dims = std::vector(dims.begin(), dims.begin() + 2); + container_type array(local_dims[0], local_dims[1]); + + size_t n_elements = flat_size(local_dims); + for (size_t i = 0; i < n_elements; ++i) { + auto element = DataGeneratorTraits::allocate(lstrip(dims, 2)); + set(array, unravel(i, local_dims), element); + } + + return array; + } +}; + +#endif -template <> -struct DataGeneratorTraits: public ScalarDataGeneratorTraits {}; template T default_real_value(const std::vector& indices, T shift, T base, T factor) { diff --git a/tests/unit/test_all_types.cpp b/tests/unit/test_all_types.cpp index 1b7fc42ec..212d9931c 100644 --- a/tests/unit/test_all_types.cpp +++ b/tests/unit/test_all_types.cpp @@ -388,6 +388,18 @@ TEMPLATE_TEST_CASE("TestreadRegularSTLArray", "[read]", int, unsigned int, float check_read_regular>(file_name, {4}); } +#ifdef H5_USE_BOOST +TEMPLATE_TEST_CASE("TestReadRegularBoostMultiArray", "[runme]", int, unsigned int, float, double) { + const std::string file_name("rw_read_regular_boost_multi_array" + typeNameHelper() + ".h5"); + check_read_regular>(file_name, {2, 3, 5, 7}); +} + +TEMPLATE_TEST_CASE("TestReadRegularBoostUblasMatrix", "[runme]", int, unsigned int, float, double) { + const std::string file_name("rw_read_regular_boost_ublas_matrix" + typeNameHelper() + ".h5"); + check_read_regular>(file_name, {3, 5}); +} +#endif + template void check_writing(const std::vector& dims, Write write) { @@ -494,6 +506,18 @@ TEMPLATE_TEST_CASE("TestWriteRegularSTLArray", "[runme]", int, unsigned int, flo check_write_regular>(file_name, {4}); } +#ifdef H5_USE_BOOST +TEMPLATE_TEST_CASE("TestWriteRegularBoostMultiArray", "[runme]", int, unsigned int, float, double) { + const std::string file_name("rw_write_regular_boost_multi_array" + typeNameHelper() + ".h5"); + check_write_regular>(file_name, {2, 3, 5, 7}); +} + +TEMPLATE_TEST_CASE("TestWriteRegularBoostUblasMatrix", "[runme]", int, unsigned int, float, double) { + const std::string file_name("rw_write_regular_boost_ublas_matrix" + typeNameHelper() + ".h5"); + check_write_regular>(file_name, {3, 5}); +} +#endif + template void check_write_read_cycle(File& file, const std::string& name, const std::vector& dims) { auto vr = testing::DataGenerator::create(dims); @@ -529,3 +553,15 @@ TEMPLATE_TEST_CASE("TestWriteReadCycleSTDArray", "[runme]", bool, std::string) { const std::string file_name("rw_cycle_std_array" + typeNameHelper() + ".h5"); check_write_read_cycle>(file_name, {6}); } + +#ifdef H5_USE_BOOST +TEMPLATE_TEST_CASE("TestWriteReadCycleBoostMulti", "[runme]", int, double) { + const std::string file_name("rw_cycle_boost_multi_array" + typeNameHelper() + ".h5"); + check_write_read_cycle>(file_name, {2, 5, 7}); +} + +TEMPLATE_TEST_CASE("TestWriteReadCycleBoostUblasMatrix", "[runme]", int, double) { + const std::string file_name("rw_cycle_boost_ublas_matrix" + typeNameHelper() + ".h5"); + check_write_read_cycle>(file_name, {2, 5}); +} +#endif