From 9d01e7359cb9b123dbb342b57ca23aff985c1782 Mon Sep 17 00:00:00 2001 From: Daniel Garcia-Sanchez Date: Tue, 30 Oct 2018 10:26:35 +0100 Subject: [PATCH] Use Container in read_selection and write_selection --- include/deal.II/base/hdf5.h | 8 +++---- source/base/hdf5.cc | 42 ++++++++++++++++++++----------------- source/base/hdf5.inst.in | 8 +++++-- tests/base/hdf5_03.cc | 3 ++- tests/base/hdf5_04.cc | 3 ++- tests/base/hdf5_05.cc | 2 +- 6 files changed, 38 insertions(+), 28 deletions(-) diff --git a/include/deal.II/base/hdf5.h b/include/deal.II/base/hdf5.h index 2f9baad0bf..52c0ed048c 100644 --- a/include/deal.II/base/hdf5.h +++ b/include/deal.II/base/hdf5.h @@ -452,8 +452,8 @@ namespace HDF5 * Transfer: Datatype Conversion and Selection section in the HDF5 * User's Guide. */ - template - std::vector + template + Container read_selection(const std::vector &coordinates); /** @@ -595,9 +595,9 @@ namespace HDF5 * Transfer: Datatype Conversion and Selection section in the HDF5 * User's Guide. */ - template + template void - write_selection(const std::vector & data, + write_selection(const Container & data, const std::vector &coordinates); // clang-format off diff --git a/source/base/hdf5.cc b/source/base/hdf5.cc index 8e8db82d8f..873f7cb0ae 100644 --- a/source/base/hdf5.cc +++ b/source/base/hdf5.cc @@ -734,23 +734,23 @@ namespace HDF5 - template - std::vector + template + Container DataSet::read_selection(const std::vector &coordinates) { Assert(coordinates.size() % rank == 0, ExcMessage( "The dimension of coordinates has to be divisible by the rank")); - const std::shared_ptr t_type = internal::get_hdf5_datatype(); - hid_t plist; - hid_t memory_dataspace; - herr_t ret; + const std::shared_ptr t_type = + internal::get_hdf5_datatype(); + hid_t plist; + hid_t memory_dataspace; + herr_t ret; std::vector data_dimensions{ static_cast(coordinates.size() / rank)}; - std::vector data( - static_cast(coordinates.size() / rank)); + Container data = internal::initialize_container(data_dimensions); memory_dataspace = H5Screate_simple(1, data_dimensions.data(), NULL); Assert(memory_dataspace >= 0, ExcMessage("Error at H5Screate_simple")); @@ -777,7 +777,7 @@ namespace HDF5 memory_dataspace, *dataspace, plist, - data.data()); + internal::get_container_pointer(data)); Assert(ret >= 0, ExcMessage("Error at H5Dread")); if (mpi) @@ -1055,14 +1055,16 @@ namespace HDF5 - template + template void - DataSet::write_selection(const std::vector & data, + DataSet::write_selection(const Container & data, const std::vector &coordinates) { AssertDimension(coordinates.size(), data.size() * rank); - const std::shared_ptr t_type = internal::get_hdf5_datatype(); - const std::vector data_dimensions = {data.size()}; + const std::shared_ptr t_type = + internal::get_hdf5_datatype(); + const std::vector data_dimensions = + internal::get_container_dimensions(data); hid_t memory_dataspace; hid_t plist; @@ -1094,7 +1096,7 @@ namespace HDF5 memory_dataspace, *dataspace, plist, - data.data()); + internal::get_container_const_pointer(data)); Assert(ret >= 0, ExcMessage("Error at H5Dwrite")); if (mpi) @@ -1637,9 +1639,10 @@ namespace HDF5 DataSet::read>(); template std::vector - DataSet::read_selection(const std::vector &coordinates); + DataSet::read_selection>( + const std::vector &coordinates); template std::vector - DataSet::read_selection( + DataSet::read_selection>( const std::vector &coordinates); template std::vector @@ -1677,10 +1680,11 @@ namespace HDF5 const std::vector &data); template void - DataSet::write_selection(const std::vector & data, - const std::vector &coordinates); + DataSet::write_selection>( + const std::vector & data, + const std::vector &coordinates); template void - DataSet::write_selection( + DataSet::write_selection>( const std::vector &data, const std::vector & coordinates); diff --git a/source/base/hdf5.inst.in b/source/base/hdf5.inst.in index 87bf2c2a28..01aaa687f4 100644 --- a/source/base/hdf5.inst.in +++ b/source/base/hdf5.inst.in @@ -25,7 +25,9 @@ for (number : REAL_AND_COMPLEX_SCALARS) template Vector DataSet::read>(); template FullMatrix DataSet::read>(); - template std::vector DataSet::read_selection( + template std::vector DataSet::read_selection>( + const std::vector &coordinates); + template Vector DataSet::read_selection>( const std::vector &coordinates); template std::vector DataSet::read_hyperslab>( @@ -62,8 +64,10 @@ for (number : REAL_AND_COMPLEX_SCALARS) template void DataSet::write>( const FullMatrix &data); - template void DataSet::write_selection( + template void DataSet::write_selection>( const std::vector &data, const std::vector &coordinates); + template void DataSet::write_selection>( + const Vector &data, const std::vector &coordinates); template void DataSet::write_hyperslab>( const std::vector & data, diff --git a/tests/base/hdf5_03.cc b/tests/base/hdf5_03.cc index dba6dde6e5..a19402fd3f 100644 --- a/tests/base/hdf5_03.cc +++ b/tests/base/hdf5_03.cc @@ -602,7 +602,8 @@ read_test(HDF5::Group root_group, 4, // third point 25, 12}; // fourth point - auto data_a = dataset.template read_selection(coordinates_a); + auto data_a = + dataset.template read_selection>(coordinates_a); deallog << "Selection " + dataset_name << " " << container_name << "<" << type_name << ">" << " (Read): " << data_a[0] << ", " << data_a[1] << ", " diff --git a/tests/base/hdf5_04.cc b/tests/base/hdf5_04.cc index 882b7dd923..2dd9c06761 100644 --- a/tests/base/hdf5_04.cc +++ b/tests/base/hdf5_04.cc @@ -556,7 +556,8 @@ read_test(HDF5::Group root_group) 4, // third point 25, 12}; // fourth point - auto data_a = dataset.template read_selection(coordinates_a); + auto data_a = + dataset.template read_selection>(coordinates_a); deallog << "Selection " + dataset_name << " " << container_name << "<" << type_name << ">" << " (Read): " << data_a[0] << ", " << data_a[1] << ", " diff --git a/tests/base/hdf5_05.cc b/tests/base/hdf5_05.cc index 7be7ec55ef..a5482dc797 100644 --- a/tests/base/hdf5_05.cc +++ b/tests/base/hdf5_05.cc @@ -972,7 +972,7 @@ read_test(HDF5::Group root_group, 3, 2}; // fith point - auto data = dataset.read_selection(coordinates); + auto data = dataset.read_selection>(coordinates); pcout << "Sub-matrix" << std::endl; pcout << "IO mode " + dataset_name << "<" << type_name << ">" -- 2.39.5