diff --git a/src/lib/ranges/yrange.cc b/src/lib/ranges/yrange.cc index 94b981f..9b4be48 100644 --- a/src/lib/ranges/yrange.cc +++ b/src/lib/ranges/yrange.cc @@ -700,6 +700,16 @@ namespace CNORXZ Sptr RangeCast::func(const RangePtr& r) { + if(r->stype() == "Y"){ + return std::dynamic_pointer_cast(r); + } + if(r->stype() == "M" or r->dim() > 1){ + Vector rv(r->dim()); + for(SizeT i = 0; i != rv.size(); ++i){ + rv[i] = r->sub(i); + } + return std::dynamic_pointer_cast( YRangeFactory(rv).create() ); + } return std::dynamic_pointer_cast( YRangeFactory({r}).create() ); } diff --git a/src/opt/hdf5/include/h5_dataset.h b/src/opt/hdf5/include/h5_dataset.h index bfd483b..aeeb24b 100644 --- a/src/opt/hdf5/include/h5_dataset.h +++ b/src/opt/hdf5/include/h5_dataset.h @@ -114,7 +114,7 @@ namespace CNORXZ /** Read the dataset using range of given index. The index position is ignored. - @param idx Index specifying the range type. + @param idx Index specifying the range. @return Array containing the dataset values. */ template diff --git a/src/opt/hdf5_mpi/include/h5_rdataset.cc.h b/src/opt/hdf5_mpi/include/h5_rdataset.cc.h index 3365e6c..08bd7ce 100644 --- a/src/opt/hdf5_mpi/include/h5_rdataset.cc.h +++ b/src/opt/hdf5_mpi/include/h5_rdataset.cc.h @@ -45,6 +45,20 @@ namespace CNORXZ return out; } + template + template + mpi::RArray SRDataset::read(const mpi::RIndex& idx) const + { + CXZ_ASSERT(idx.dim() == mFileRange->dim(), "got index of inconsistent dimension, got" + << idx.dim() << ", expected " << mFileRange->dim()); + auto outrange = rangeCast>( idx.range() ); + CXZ_ASSERT(outrange->size() == mFileRange->size(), + "got index of range of inconsistent size, expected " + << mFileRange->size() << ", got " << outrange->size()); + mpi::RArray out(outrange); + readbase(out.data(), outrange, nullptr); + return out; + } } } diff --git a/src/opt/hdf5_mpi/include/h5_rdataset.h b/src/opt/hdf5_mpi/include/h5_rdataset.h index 3113e8e..bced81e 100644 --- a/src/opt/hdf5_mpi/include/h5_rdataset.h +++ b/src/opt/hdf5_mpi/include/h5_rdataset.h @@ -75,6 +75,13 @@ namespace CNORXZ @return Array containing the dataset values. */ mpi::RArray read(const RangePtr& geom) const; + + /** Read the dataset. + @param idx Index specifying the range. + @return RArray containing the dataset values. + */ + template + mpi::RArray read(const mpi::RIndex& idx) const; }; } } diff --git a/src/opt/hdf5_mpi/tests/h5_mpi_basic_unit_test.cc b/src/opt/hdf5_mpi/tests/h5_mpi_basic_unit_test.cc index 3ce83dd..ee2ba44 100644 --- a/src/opt/hdf5_mpi/tests/h5_mpi_basic_unit_test.cc +++ b/src/opt/hdf5_mpi/tests/h5_mpi_basic_unit_test.cc @@ -28,7 +28,8 @@ namespace using namespace CNORXZ::mpi; using Test::Numbers; - typedef MIndex C4; + typedef UIndex UI; + typedef MIndex U4; class RDataset_test : public ::testing::Test { @@ -111,6 +112,22 @@ namespace auto i = std::make_shared(mLR2); i->ifor( operation( [](Double a, Double b) { EXPECT_EQ(a,b); }, mA2(i), a(i) ), NoF{} )(); } + + TEST_F(RDataset_test, ReadExplicit) + { + RFile h5f(mFilename, false); + //auto dat = h5f.open().getGroup("dir")->open().get("dat", [](const String& name, const ContentBase* par, auto& i) + //{ (*i)->close(); auto dset = std::make_shared>(name, par); *i = dset; + // return dset; } ); + auto dat = getRDataset(h5f.open().getGroup("dir")->open(),"dat"); + RIndex idx(mA2.range()); + + auto a = dat->read(idx); + h5f.close(); + + auto i = std::make_shared(mLR2); + i->ifor( operation( [](Double a, Double b) { EXPECT_EQ(a,b); }, mA2(i), a(i) ), NoF{} )(); + } } int main(int argc, char** argv)