add get/set block sizes function for gmindex, yindex, xindex and dindex

This commit is contained in:
Christian Zimmermann 2022-12-13 00:37:59 +01:00
parent f41ada859a
commit 79535c496f
10 changed files with 95 additions and 48 deletions

View file

@ -81,42 +81,6 @@ namespace CNORXZ
}
*/
/******************************
* CArrayBase (protected) *
******************************/
template <typename T>
template <class IPack1, class IPack2>
inline Vector<SizeT> CArrayBase<T>::mkSliceBlockSize(const IPack1& ip1, const IPack2& ip2) const
{
const SizeT ip1dim = indexPackDim(ip1);
const SizeT ip2dim = indexPackDim(ip2);
if(ip1dim > ip2dim){
//const SizeT ip1sdim = indexPackSDim(ip1);
const SizeT ip2sdim = indexPackSDim(ip2);
CXZ_ASSERT(ip1dim == ip2sdim or ip2sdim == ip2dim,
"")
}
else if(ip1dim < ip2dim){
}
else {
}
}
template <typename T>
inline RangePtr CArrayBase<T>::mkSliceRange(const RangePtr& r) const
{
}
template <typename T>
inline void CArrayBase<T>::assertCompatible() const
{
}
/*****************
* ArrayBase *
*****************/

View file

@ -22,13 +22,6 @@ namespace CNORXZ
protected:
RangePtr mRange;
template <typename I, typename M>
inline Vector<SizeT> mkSliceBlockSize(const I1& i, const I2& beg) const;
inline RangePtr mkSliceRange(const RangePtr& r) const;
inline void assertCompatible() const;
public:
CArrayBase(const RangePtr& range);

View file

@ -47,6 +47,8 @@ namespace CNORXZ
UPos stepSize(const IndexId<0>& id) const;
Vector<XIndexPtr> pack() const;
Vector<SizeT> blockSizes() const;
DIndex& setBlockSizes(const Vector<SizeT>& bs);
String stringMeta() const;
DType meta() const;

View file

@ -451,6 +451,24 @@ namespace CNORXZ
return mLexBlockSizes;
}
template <class BlockType, class... Indices>
GMIndex& GMIndex<BlockType,Indices...>::setBlockSizes(const BlockType& bs)
{
if constexpr(not std::is_same<BlockType,None>::value){
mBlockSizes = bs;
}
return *this;
}
template <class BT1, class BT2, class... Indices>
decltype(auto) replaceBlockSize(const BT1& bs1, const Sptr<GMIndex<BT2,Indices...>>& gmi)
{
return iter<0,sizeof...(Indices)>
( [&](auto i) { return std::get<i>(gmi.pack()); },
[&](const auto&... e) { return std::make_shared<GMIndex<BT1,Indices...>>
( bs1, e... ); } );
}
template <class BT1, class... Is1, class BT2, class... Is2>
decltype(auto) operator*(const Sptr<GMIndex<BT1,Is1...>>& a, const Sptr<GMIndex<BT2,Is2...>>& b)
{

View file

@ -73,6 +73,7 @@ namespace CNORXZ
const IndexPack& pack() const;
const auto& blockSizes() const;
const auto& lexBlockSizes() const;
GMIndex& setBlockSizes(const BlockType& bs);
private:
template <SizeT... Is>
@ -108,6 +109,9 @@ namespace CNORXZ
PMaxT mPMax;
};
template <class BT1, class BT2, class... Indices>
decltype(auto) replaceBlockSize(const BT1& bs1, const Sptr<GMIndex<BT2,Indices...>>& gmi);
template <class BT1, class... Is1, class BT2, class... Is2>
decltype(auto) operator*(const Sptr<GMIndex<BT1,Is1...>>& a, const Sptr<GMIndex<BT2,Is2...>>& b);

View file

@ -130,14 +130,13 @@ namespace CNORXZ
template <class Index, typename Meta>
Vector<XIndexPtr> XIndex<Index,Meta>::pack() const
{
if constexpr(has_static_sub<Index>::value){
constexpr SizeT D = index_dim<Index>::value;
// replace by traits: has_sub, has_static_sub (-> to be implemented!!!)
if constexpr(D > 1){
return iter<0,D>
( [&](auto i) { return mkXIndex(std::get<i>(mI->pack())); },
[](const auto&... e) { return { e ... }; } );
}
else if constexpr(std::is_same<Index,YIndex>::value){
else if constexpr(has_sub<Index>::value){
return mI->pack();
}
else {
@ -145,6 +144,50 @@ namespace CNORXZ
}
}
template <class Index, typename Meta>
Vector<SizeT> XIndex<Index,Meta>::blockSizes() const
{
if constexpr(has_static_sub<Index>::value){
constexpr SizeT D = index_dim<Index>::value;
return iter<0,D>
( [&](auto i) { return std::get<i>(mI->blockSizes()); },
[](const auto&... e) { return Vector<SizeT>( { e... } ); } );
}
else if constexpr(has_sub<Index>::value) {
return mI->blockSizes();
}
else {
return {};
}
}
template <class Index, typename Meta>
XIndexPtr XIndex<Index,Meta>::setBlockSizes(const Vector<SizeT>& bs)
{
if constexpr(has_static_sub<Index>::value){
constexpr SizeT D = index_dim<Index>::value;
CXZ_ASSERT(bs.size() == D,
"got block sizes of wrong dimension: " << bs.size() << " vs " << D);
typedef decltype(mI->blockSizes()) BT;
Arr<SizeT,D> arr;
std::copy_n(bs.begin(), D, arr.begin());
if constexpr(std::is_same<BT,Arr<SizeT,D>>::value){
mI->setBlockSizes(arr);
return nullptr;
}
else {
return replaceBlockSizes(arr, mI);
}
}
else if constexpr(has_sub<Index>::value) {
mI->setBlockSizes(bs);
return nullptr;
}
else {
return nullptr;
}
}
template <class Index, typename Meta>
String XIndex<Index,Meta>::stringMeta() const
{

View file

@ -37,6 +37,8 @@ namespace CNORXZ
virtual RangePtr range() const = 0;
virtual UPos stepSize(const IndexId<0>& id) const = 0;
virtual Vector<XIndexPtr> pack() const = 0;
virtual Vector<SizeT> blockSizes() const = 0;
virtual XIndexPtr setBlockSizes(const Vector<SizeT>& bs) = 0;
virtual String stringMeta() const = 0;
virtual DType meta() const = 0;
@ -86,6 +88,8 @@ namespace CNORXZ
virtual RangePtr range() const override final;
virtual UPos stepSize(const IndexId<0>& id) const override final;
virtual Vector<XIndexPtr> pack() const override final;
virtual Vector<SizeT> blockSizes() const override final;
virtual XIndexPtr setBlockSizes(const Vector<SizeT>& bs) override final;
virtual String stringMeta() const override final;
virtual DType meta() const override final;

View file

@ -60,6 +60,7 @@ namespace CNORXZ
const Vector<XIndexPtr>& pack() const;
const Vector<SizeT>& blockSizes() const;
const Vector<SizeT>& lexBlockSizes() const;
YIndex& setBlockSizes(const Vector<SizeT>& bs);
private:
inline Vector<SizeT> mkBlockSizes() const;

View file

@ -134,6 +134,17 @@ namespace CNORXZ
return mI->pack();
}
Vector<SizeT> DIndex::blockSizes() const
{
return mI->blockSizes();
}
DIndex& DIndex::setBlockSizes(const Vector<SizeT>& bs)
{
mI->setBlockSizes(bs);
return *this;
}
String DIndex::stringMeta() const
{
return mI->stringMeta();

View file

@ -372,6 +372,13 @@ namespace CNORXZ
return mLexBlockSizes;
}
YIndex& YIndex::setBlockSizes(const Vector<SizeT>& bs)
{
mBlockSizes = bs;
return *this;
}
/**********************
* YRangeFactory *
**********************/