minor changes + mindex/yindex: further functionalities
This commit is contained in:
parent
25abf5e1b0
commit
0e71d45a5b
6 changed files with 137 additions and 12 deletions
|
@ -180,6 +180,9 @@ namespace CNORXZ
|
||||||
template <class BlockType, class... Indices>
|
template <class BlockType, class... Indices>
|
||||||
class GMIndex;
|
class GMIndex;
|
||||||
|
|
||||||
|
template <class... Indices>
|
||||||
|
using MIndex = GMIndex<None,Indices...>;
|
||||||
|
|
||||||
// definition: ranges/xindex.h
|
// definition: ranges/xindex.h
|
||||||
class XIndexBase; // dynamic index wrapper
|
class XIndexBase; // dynamic index wrapper
|
||||||
|
|
||||||
|
|
|
@ -79,8 +79,6 @@ namespace CNORXZ
|
||||||
template <typename T, class IndexT>
|
template <typename T, class IndexT>
|
||||||
class OpCont : public OpInterface<OpCont<T,IndexT>>
|
class OpCont : public OpInterface<OpCont<T,IndexT>>
|
||||||
{
|
{
|
||||||
// operation container (intermediate operation results)
|
|
||||||
// TO BE IMPLEMENTED!!!
|
|
||||||
public:
|
public:
|
||||||
typedef OpInterface<OpCont<T,IndexT>> OI;
|
typedef OpInterface<OpCont<T,IndexT>> OI;
|
||||||
|
|
||||||
|
|
|
@ -170,6 +170,19 @@ namespace CNORXZ
|
||||||
mkPos();
|
mkPos();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class BlockType, class... Indices>
|
||||||
|
constexpr GMIndex<BlockType,Indices...>::GMIndex(const BlockType& bs, const Indices&... is) :
|
||||||
|
IndexInterface<GMIndex<BlockType,Indices...>,Tuple<typename Indices::MetaType...>>(0),
|
||||||
|
mRange(std::dynamic_pointer_cast<RangeType>(mrange(is.range()...))),
|
||||||
|
mIPack(std::make_shared<Indices>(is)...),
|
||||||
|
mLexBlockSizes(mkLexBlockSizes(mIPack,Isqr<1,NI>{})),
|
||||||
|
mBlockSizes(bs),
|
||||||
|
mLMax(mkLMax(mIPack)),
|
||||||
|
mPMax(mkPMax(mIPack,mBlockSizes))
|
||||||
|
{
|
||||||
|
mkPos();
|
||||||
|
}
|
||||||
|
|
||||||
template <class BlockType, class... Indices>
|
template <class BlockType, class... Indices>
|
||||||
constexpr GMIndex<BlockType,Indices...>::GMIndex(const Sptr<Indices>&... is) :
|
constexpr GMIndex<BlockType,Indices...>::GMIndex(const Sptr<Indices>&... is) :
|
||||||
IndexInterface<GMIndex<BlockType,Indices...>,Tuple<typename Indices::MetaType...>>(0),
|
IndexInterface<GMIndex<BlockType,Indices...>,Tuple<typename Indices::MetaType...>>(0),
|
||||||
|
@ -183,6 +196,20 @@ namespace CNORXZ
|
||||||
mkPos();
|
mkPos();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class BlockType, class... Indices>
|
||||||
|
constexpr GMIndex<BlockType,Indices...>::GMIndex(const BlockType& bs,
|
||||||
|
const Sptr<Indices>&... is) :
|
||||||
|
IndexInterface<GMIndex<BlockType,Indices...>,Tuple<typename Indices::MetaType...>>(0),
|
||||||
|
mRange(std::dynamic_pointer_cast<RangeType>(mrange(is->range()...))),
|
||||||
|
mIPack(is...),
|
||||||
|
mLexBlockSizes(mkLexBlockSizes(mIPack,Isqr<1,NI>{})),
|
||||||
|
mBlockSizes(bs),
|
||||||
|
mLMax(mkLMax(mIPack)),
|
||||||
|
mPMax(mkPMax(mIPack,mBlockSizes))
|
||||||
|
{
|
||||||
|
mkPos();
|
||||||
|
}
|
||||||
|
|
||||||
template <class BlockType, class... Indices>
|
template <class BlockType, class... Indices>
|
||||||
constexpr GMIndex<BlockType,Indices...>::GMIndex(const RangePtr& range, SizeT lexpos) :
|
constexpr GMIndex<BlockType,Indices...>::GMIndex(const RangePtr& range, SizeT lexpos) :
|
||||||
IndexInterface<GMIndex<BlockType,Indices...>,Tuple<typename Indices::MetaType...>>(0),
|
IndexInterface<GMIndex<BlockType,Indices...>,Tuple<typename Indices::MetaType...>>(0),
|
||||||
|
@ -385,12 +412,17 @@ namespace CNORXZ
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class BlockType, class... Indices>
|
template <class BlockType, class... Indices>
|
||||||
GMIndex<BlockType,Indices...>& GMIndex<BlockType,Indices...>::operator()(const Sptr<GMIndex>& mi)
|
GMIndex<BlockType,Indices...>& GMIndex<BlockType,Indices...>::operator()(const Sptr<MIndex<Indices...>>& mi)
|
||||||
{
|
{
|
||||||
mIPack = mi.mIPack;
|
mIPack = mi.pack();
|
||||||
IB::mPos = iter<0,NI>
|
mkPos();
|
||||||
( [&](auto i) { return std::get<i>(mIPack)->pos()*std::get<i>(blockSizes()).val(); },
|
return *this;
|
||||||
[](const auto&... xs) { return (xs + ...); });
|
}
|
||||||
|
|
||||||
|
template <class BlockType, class... Indices>
|
||||||
|
GMIndex<BlockType,Indices...>& GMIndex<BlockType,Indices...>::operator()()
|
||||||
|
{
|
||||||
|
mkPos();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,8 +24,6 @@ namespace CNORXZ
|
||||||
typedef MRange<typename Indices::RangeType...> RangeType;
|
typedef MRange<typename Indices::RangeType...> RangeType;
|
||||||
static constexpr SizeT NI = sizeof...(Indices);
|
static constexpr SizeT NI = sizeof...(Indices);
|
||||||
|
|
||||||
// NO DEFAULT HERE !!!
|
|
||||||
// ( have to assign sub-indices (ptr!) correctly )
|
|
||||||
constexpr GMIndex() = default;
|
constexpr GMIndex() = default;
|
||||||
constexpr GMIndex(GMIndex&& i) = default;
|
constexpr GMIndex(GMIndex&& i) = default;
|
||||||
constexpr GMIndex& operator=(GMIndex&& i) = default;
|
constexpr GMIndex& operator=(GMIndex&& i) = default;
|
||||||
|
@ -34,7 +32,9 @@ namespace CNORXZ
|
||||||
constexpr GMIndex& operator=(const GMIndex& i);
|
constexpr GMIndex& operator=(const GMIndex& i);
|
||||||
|
|
||||||
constexpr GMIndex(const Indices&... is);
|
constexpr GMIndex(const Indices&... is);
|
||||||
|
constexpr GMIndex(const BlockType& blockSizes, const Indices&... is);
|
||||||
constexpr GMIndex(const Sptr<Indices>&... is);
|
constexpr GMIndex(const Sptr<Indices>&... is);
|
||||||
|
constexpr GMIndex(const BlockType& blockSizes, const Sptr<Indices>&... is);
|
||||||
constexpr GMIndex(const RangePtr& range, SizeT lexpos = 0);
|
constexpr GMIndex(const RangePtr& range, SizeT lexpos = 0);
|
||||||
constexpr GMIndex(const RangePtr& range, const BlockType& blockSizes, SizeT lexpos = 0);
|
constexpr GMIndex(const RangePtr& range, const BlockType& blockSizes, SizeT lexpos = 0);
|
||||||
|
|
||||||
|
@ -67,7 +67,8 @@ namespace CNORXZ
|
||||||
constexpr decltype(auto) ifor(const Xpr& xpr, F&& f) const;
|
constexpr decltype(auto) ifor(const Xpr& xpr, F&& f) const;
|
||||||
|
|
||||||
// replace sub-index instances; only use if you know what you are doing!
|
// replace sub-index instances; only use if you know what you are doing!
|
||||||
GMIndex& operator()(const Sptr<GMIndex>& mi);
|
GMIndex& operator()(const Sptr<MIndex<Indices...>>& mi);
|
||||||
|
GMIndex& operator()();
|
||||||
|
|
||||||
const IndexPack& pack() const;
|
const IndexPack& pack() const;
|
||||||
const auto& blockSizes() const;
|
const auto& blockSizes() const;
|
||||||
|
@ -107,8 +108,8 @@ namespace CNORXZ
|
||||||
PMaxT mPMax;
|
PMaxT mPMax;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class... Indices>
|
//template <class... Indices>
|
||||||
using MIndex = GMIndex<None,Indices...>;
|
//using MIndex = GMIndex<None,Indices...>;
|
||||||
|
|
||||||
template <class... Ranges>
|
template <class... Ranges>
|
||||||
class MRangeFactory : public RangeFactoryBase
|
class MRangeFactory : public RangeFactoryBase
|
||||||
|
|
|
@ -24,6 +24,8 @@ namespace CNORXZ
|
||||||
YIndex(const YIndex& i);
|
YIndex(const YIndex& i);
|
||||||
YIndex& operator=(const YIndex& i);
|
YIndex& operator=(const YIndex& i);
|
||||||
|
|
||||||
|
YIndex(const Vector<XIndexPtr>& is);
|
||||||
|
YIndex(const Vector<SizeT>& bs, const Vector<XIndexPtr>& is);
|
||||||
YIndex(const RangePtr& range, SizeT lexpos);
|
YIndex(const RangePtr& range, SizeT lexpos);
|
||||||
|
|
||||||
YIndex& operator=(SizeT lexpos);
|
YIndex& operator=(SizeT lexpos);
|
||||||
|
@ -51,9 +53,18 @@ namespace CNORXZ
|
||||||
|
|
||||||
DXpr<SizeT> ifor(const DXpr<SizeT>& xpr, const std::function<SizeT(SizeT,SizeT)>& f) const;
|
DXpr<SizeT> ifor(const DXpr<SizeT>& xpr, const std::function<SizeT(SizeT,SizeT)>& f) const;
|
||||||
|
|
||||||
|
YIndex& operator()(const Sptr<YIndex>& i);
|
||||||
|
YIndex& operator()();
|
||||||
|
|
||||||
|
const Vector<XIndexPtr>& pack() const;
|
||||||
|
const Vector<SizeT>& blockSizes() const;
|
||||||
|
const Vector<SizeT>& lexBlockSizes() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
inline Vector<SizeT> mkBlockSizes() const;
|
inline Vector<SizeT> mkBlockSizes() const;
|
||||||
inline Vector<SizeT> mkLexBlockSizes() const;
|
inline Vector<SizeT> mkLexBlockSizes() const;
|
||||||
|
inline Vector<RangePtr> mkRangeVec(const Vector<XIndexPtr>& is) const;
|
||||||
|
inline void mkPos();
|
||||||
inline Vector<XIndexPtr> mkIndices() const;
|
inline Vector<XIndexPtr> mkIndices() const;
|
||||||
inline void up(SizeT i);
|
inline void up(SizeT i);
|
||||||
inline void down(SizeT i);
|
inline void down(SizeT i);
|
||||||
|
@ -114,6 +125,8 @@ namespace CNORXZ
|
||||||
Vector<RangePtr> mRVec;
|
Vector<RangePtr> mRVec;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
RangePtr yrange(const Vector<RangePtr>& rs);
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct RangeCast<YRange>
|
struct RangeCast<YRange>
|
||||||
{
|
{
|
||||||
|
|
|
@ -42,6 +42,23 @@ namespace CNORXZ
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline Vector<RangePtr> YIndex::mkRangeVec(const Vector<XIndexPtr>& is) const
|
||||||
|
{
|
||||||
|
Vector<RangePtr> o(is.size());
|
||||||
|
std::transform(is.begin(), is.end(), o.begin(), [](const auto& e) { return e->range(); });
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void YIndex::mkPos()
|
||||||
|
{
|
||||||
|
mLex = 0;
|
||||||
|
IB::mPos = 0;
|
||||||
|
for(SizeT i = 0; i != dim(); ++i){
|
||||||
|
mLex += mIs[i]->lex() * mLexBlockSizes[i];
|
||||||
|
IB::mPos += mIs[i]->pos() * mBlockSizes[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
inline void YIndex::up(SizeT i)
|
inline void YIndex::up(SizeT i)
|
||||||
{
|
{
|
||||||
auto& idx = mIs[i];
|
auto& idx = mIs[i];
|
||||||
|
@ -129,6 +146,30 @@ namespace CNORXZ
|
||||||
return *this = i.lex();
|
return *this = i.lex();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
YIndex::YIndex(const Vector<XIndexPtr>& is) :
|
||||||
|
IndexInterface<YIndex,DType>(0),
|
||||||
|
mRange(std::dynamic_pointer_cast<YRange>(yrange(mkRangeVec(is)))),
|
||||||
|
mIs(is),
|
||||||
|
mBlockSizes(mkBlockSizes()),
|
||||||
|
mLexBlockSizes(mkLexBlockSizes()),
|
||||||
|
mPMax(mkPMax()),
|
||||||
|
mLMax(mkLMax())
|
||||||
|
{
|
||||||
|
mkPos();
|
||||||
|
}
|
||||||
|
|
||||||
|
YIndex::YIndex(const Vector<SizeT>& bs, const Vector<XIndexPtr>& is) :
|
||||||
|
IndexInterface<YIndex,DType>(0),
|
||||||
|
mRange(std::dynamic_pointer_cast<YRange>(yrange(mkRangeVec(is)))),
|
||||||
|
mIs(is),
|
||||||
|
mBlockSizes(bs),
|
||||||
|
mLexBlockSizes(mkLexBlockSizes()),
|
||||||
|
mPMax(mkPMax()),
|
||||||
|
mLMax(mkLMax())
|
||||||
|
{
|
||||||
|
mkPos();
|
||||||
|
}
|
||||||
|
|
||||||
YIndex::YIndex(const RangePtr& range, SizeT lexpos) :
|
YIndex::YIndex(const RangePtr& range, SizeT lexpos) :
|
||||||
IndexInterface<YIndex,DType>(0),
|
IndexInterface<YIndex,DType>(0),
|
||||||
mRange(rangeCast<YRange>(range)),
|
mRange(rangeCast<YRange>(range)),
|
||||||
|
@ -289,6 +330,34 @@ namespace CNORXZ
|
||||||
return mkIFor(0, xpr, f);
|
return mkIFor(0, xpr, f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
YIndex& YIndex::operator()(const Sptr<YIndex>& i)
|
||||||
|
{
|
||||||
|
mIs = i->pack();
|
||||||
|
mkPos();
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
YIndex& YIndex::operator()()
|
||||||
|
{
|
||||||
|
mkPos();
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Vector<XIndexPtr>& YIndex::pack() const
|
||||||
|
{
|
||||||
|
return mIs;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Vector<SizeT>& YIndex::blockSizes() const
|
||||||
|
{
|
||||||
|
return mBlockSizes;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Vector<SizeT>& YIndex::lexBlockSizes() const
|
||||||
|
{
|
||||||
|
return mLexBlockSizes;
|
||||||
|
}
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* YRangeFactory *
|
* YRangeFactory *
|
||||||
**********************/
|
**********************/
|
||||||
|
@ -375,6 +444,15 @@ namespace CNORXZ
|
||||||
|
|
||||||
YRange::YRange(Vector<RangePtr>&& rvec) : mRVec(std::forward<Vector<RangePtr>>(rvec)) {}
|
YRange::YRange(Vector<RangePtr>&& rvec) : mRVec(std::forward<Vector<RangePtr>>(rvec)) {}
|
||||||
|
|
||||||
|
/****************************
|
||||||
|
* non-member functions *
|
||||||
|
****************************/
|
||||||
|
|
||||||
|
RangePtr yrange(const Vector<RangePtr>& rs)
|
||||||
|
{
|
||||||
|
return YRangeFactory(rs).create();
|
||||||
|
}
|
||||||
|
|
||||||
/*******************
|
/*******************
|
||||||
* Range Casts *
|
* Range Casts *
|
||||||
*******************/
|
*******************/
|
||||||
|
|
Loading…
Reference in a new issue