yrange: fix in range cast specialization + hdf5_mpi: further read test

This commit is contained in:
Christian Zimmermann 2025-01-01 17:34:49 -08:00
parent ffec135eec
commit b3cbc61718
5 changed files with 50 additions and 2 deletions

View file

@ -700,6 +700,16 @@ namespace CNORXZ
Sptr<YRange> RangeCast<YRange>::func(const RangePtr& r)
{
if(r->stype() == "Y"){
return std::dynamic_pointer_cast<YRange>(r);
}
if(r->stype() == "M" or r->dim() > 1){
Vector<RangePtr> rv(r->dim());
for(SizeT i = 0; i != rv.size(); ++i){
rv[i] = r->sub(i);
}
return std::dynamic_pointer_cast<YRange>( YRangeFactory(rv).create() );
}
return std::dynamic_pointer_cast<YRange>( YRangeFactory({r}).create() );
}

View file

@ -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 <class I, typename M>

View file

@ -45,6 +45,20 @@ namespace CNORXZ
return out;
}
template <typename T>
template <class I, class K>
mpi::RArray<T> SRDataset<T>::read(const mpi::RIndex<I,K>& idx) const
{
CXZ_ASSERT(idx.dim() == mFileRange->dim(), "got index of inconsistent dimension, got"
<< idx.dim() << ", expected " << mFileRange->dim());
auto outrange = rangeCast<mpi::RRange<YRange,YRange>>( idx.range() );
CXZ_ASSERT(outrange->size() == mFileRange->size(),
"got index of range of inconsistent size, expected "
<< mFileRange->size() << ", got " << outrange->size());
mpi::RArray<T> out(outrange);
readbase(out.data(), outrange, nullptr);
return out;
}
}
}

View file

@ -75,6 +75,13 @@ namespace CNORXZ
@return Array containing the dataset values.
*/
mpi::RArray<T> read(const RangePtr& geom) const;
/** Read the dataset.
@param idx Index specifying the range.
@return RArray containing the dataset values.
*/
template <class I, class K>
mpi::RArray<T> read(const mpi::RIndex<I,K>& idx) const;
};
}
}

View file

@ -28,7 +28,8 @@ namespace
using namespace CNORXZ::mpi;
using Test::Numbers;
typedef MIndex<CIndex,CIndex,CIndex,CIndex> C4;
typedef UIndex<SizeT> UI;
typedef MIndex<UI,UI,UI,UI> U4;
class RDataset_test : public ::testing::Test
{
@ -111,6 +112,22 @@ namespace
auto i = std::make_shared<CIndex>(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<SRDataset<Double>>(name, par); *i = dset;
// return dset; } );
auto dat = getRDataset<Double>(h5f.open().getGroup("dir")->open(),"dat");
RIndex<U4,U4> idx(mA2.range());
auto a = dat->read(idx);
h5f.close();
auto i = std::make_shared<CIndex>(mLR2);
i->ifor( operation( [](Double a, Double b) { EXPECT_EQ(a,b); }, mA2(i), a(i) ), NoF{} )();
}
}
int main(int argc, char** argv)