various fixes

This commit is contained in:
Christian Zimmermann 2023-03-15 17:29:24 +01:00
parent c1f92b4685
commit 4642ebe6d2
4 changed files with 137 additions and 107 deletions

View file

@ -402,7 +402,7 @@ namespace CNORXZ
template <SizeT I> template <SizeT I>
constexpr decltype(auto) Contraction<CXpr>::rootSteps(const IndexId<I>& id) const constexpr decltype(auto) Contraction<CXpr>::rootSteps(const IndexId<I>& id) const
{ {
return mCXpr.stepSize(id); return mCXpr.rootSteps(id);
} }
template <class F, class Op, class IndexT> template <class F, class Op, class IndexT>

View file

@ -80,6 +80,7 @@ namespace CNORXZ
public: public:
typedef RangeBase RB; typedef RangeBase RB;
typedef CIndex IndexType; typedef CIndex IndexType;
typedef SizeT MetaType;
typedef CRangeFactory FType; typedef CRangeFactory FType;
friend CRangeFactory; friend CRangeFactory;

View file

@ -10,110 +10,110 @@ namespace CNORXZ
* PIndex * * PIndex *
**************/ **************/
template <class Index> template <class IndexT>
PIndex<Index>::PIndex(const RangePtr& range, SizeT pos) : PIndex<IndexT>::PIndex(const RangePtr& range, SizeT pos) :
IndexInterface<Index,typename Index::MetaType>(pos), IndexInterface<PIndex<IndexT>,typename IndexT::MetaType>(pos),
mRangePtr(rangeCast<RangeType>(range)), mRangePtr(rangeCast<RangeType>(range)),
mOrig(std::make_shared<Index>(mRangePtr->orig(),mRangePtr->parts()[pos])) mOrig(std::make_shared<IndexT>(mRangePtr->orig(),mRangePtr->parts()[pos]))
{} {}
template <class Index> template <class IndexT>
PIndex<Index>& PIndex<Index>::operator=(SizeT lexpos) PIndex<IndexT>& PIndex<IndexT>::operator=(SizeT lexpos)
{ {
IB::mPos = lexpos; IB::mPos = lexpos;
*mOrig = mRangePtr->parts()[IB::mPos]; *mOrig = mRangePtr->parts()[IB::mPos];
return *this; return *this;
} }
template <class Index> template <class IndexT>
PIndex<Index>& PIndex<Index>::operator++() PIndex<IndexT>& PIndex<IndexT>::operator++()
{ {
++IB::mPos; ++IB::mPos;
*mOrig = mRangePtr->parts()[IB::mPos]; *mOrig = mRangePtr->parts()[IB::mPos];
return *this; return *this;
} }
template <class Index> template <class IndexT>
PIndex<Index>& PIndex<Index>::operator--() PIndex<IndexT>& PIndex<IndexT>::operator--()
{ {
--IB::mPos; --IB::mPos;
*mOrig = mRangePtr->parts()[IB::mPos]; *mOrig = mRangePtr->parts()[IB::mPos];
return *this; return *this;
} }
template <class Index> template <class IndexT>
PIndex<Index> PIndex<Index>::operator+(Int n) const PIndex<IndexT> PIndex<IndexT>::operator+(Int n) const
{ {
return PIndex(mRangePtr, IB::mPos + n); return PIndex(mRangePtr, IB::mPos + n);
} }
template <class Index> template <class IndexT>
PIndex<Index> PIndex<Index>::operator-(Int n) const PIndex<IndexT> PIndex<IndexT>::operator-(Int n) const
{ {
return PIndex(mRangePtr, IB::mPos - n); return PIndex(mRangePtr, IB::mPos - n);
} }
template <class Index> template <class IndexT>
PIndex<Index>& PIndex<Index>::operator+=(Int n) PIndex<IndexT>& PIndex<IndexT>::operator+=(Int n)
{ {
IB::mPos += n; IB::mPos += n;
*mOrig = mRangePtr->parts()[IB::mPos]; *mOrig = mRangePtr->parts()[IB::mPos];
return *this; return *this;
} }
template <class Index> template <class IndexT>
PIndex<Index>& PIndex<Index>::operator-=(Int n) PIndex<IndexT>& PIndex<IndexT>::operator-=(Int n)
{ {
IB::mPos -= n; IB::mPos -= n;
*mOrig = mRangePtr->parts()[IB::mPos]; *mOrig = mRangePtr->parts()[IB::mPos];
return *this; return *this;
} }
template <class Index> template <class IndexT>
SizeT PIndex<Index>::lex() const SizeT PIndex<IndexT>::lex() const
{ {
return IB::mPos; return IB::mPos;
} }
template <class Index> template <class IndexT>
UPos PIndex<Index>::pmax() const UPos PIndex<IndexT>::pmax() const
{ {
return UPos(mRangePtr->size()); return UPos(mRangePtr->size());
} }
template <class Index> template <class IndexT>
UPos PIndex<Index>::lmax() const UPos PIndex<IndexT>::lmax() const
{ {
return UPos(mRangePtr->size()); return UPos(mRangePtr->size());
} }
template <class Index> template <class IndexT>
IndexId<0> PIndex<Index>::id() const IndexId<0> PIndex<IndexT>::id() const
{ {
return IndexId<0>(this->ptrId()); return IndexId<0>(this->ptrId());
} }
template <class Index> template <class IndexT>
const typename PIndex<Index>::MetaType& PIndex<Index>::operator*() const decltype(auto) PIndex<IndexT>::operator*() const
{ {
return **mOrig; return **mOrig;
} }
template <class Index> template <class IndexT>
SizeT PIndex<Index>::dim() const SizeT PIndex<IndexT>::dim() const
{ {
return 1; return 1;
} }
template <class Index> template <class IndexT>
Sptr<typename PIndex<Index>::RangeType> PIndex<Index>::range() const Sptr<typename PIndex<IndexT>::RangeType> PIndex<IndexT>::range() const
{ {
return mRangePtr; return mRangePtr;
} }
template <class Index> template <class IndexT>
template <SizeT I> template <SizeT I>
UPos PIndex<Index>::stepSize(const IndexId<I>& id) const UPos PIndex<IndexT>::stepSize(const IndexId<I>& id) const
{ {
if(id == this->id()){ if(id == this->id()){
return UPos(1); return UPos(1);
@ -123,67 +123,70 @@ namespace CNORXZ
} }
} }
template <class Index> template <class IndexT>
String PIndex<Index>::stringMeta() const String PIndex<IndexT>::stringMeta() const
{ {
return mOrig->stringMeta(); return mOrig->stringMeta();
} }
template <class Index> template <class IndexT>
const typename PIndex<Index>::MetaType& PIndex<Index>::meta() const decltype(auto) PIndex<IndexT>::meta() const
{ {
return mOrig->meta(); return mOrig->meta();
} }
template <class Index> template <class IndexT>
PIndex<Index>& PIndex<Index>::at(const MetaType& metaPos) PIndex<IndexT>& PIndex<IndexT>::at(const MetaType& metaPos)
{ {
mOrig->at(metaPos); mOrig->at(metaPos);
mkPos(); mkPos();
return *this; return *this;
} }
template <class Index> template <class IndexT>
decltype(auto) PIndex<Index>::xpr(const Sptr<PIndex<Index>>& _this) const decltype(auto) PIndex<IndexT>::xpr(const Sptr<PIndex<IndexT>>& _this) const
{ {
return poperation( mOrig->xpr(mOrig), mRangePtr->parts(), _this ); CXZ_ERROR("implement!!!");
//return poperation( _this, mOrig, mRangePtr->parts(), mOrig->xpr(mOrig) );
return mOrig->xpr(mOrig);
} }
template <class Index> template <class IndexT>
template <class I> template <class I>
decltype(auto) PIndex<Index>::format(const Sptr<I>& ind) const decltype(auto) PIndex<IndexT>::format(const Sptr<I>& ind) const
{ {
return ind; return ind;
} }
template <class Index> template <class IndexT>
template <class I> template <class I>
decltype(auto) PIndex<Index>::slice(const Sptr<I>& ind) const decltype(auto) PIndex<IndexT>::slice(const Sptr<I>& ind) const
{ {
if(ind != nullptr){ if(ind != nullptr){
if(ind->dim() != 0){ if(ind->dim() != 0){
return Sptr<PIndex<Index>>(); return Sptr<PIndex<IndexT>>();
} }
} }
return std::make_shared<PIndex<Index>>(*this); return std::make_shared<PIndex<IndexT>>(*this);
} }
template <class Index> template <class IndexT>
template <class Xpr, class F> template <class Xpr, class F>
decltype(auto) PIndex<Index>::ifor(const Xpr& xpr, F&& f) const decltype(auto) PIndex<IndexT>::ifor(const Xpr& xpr, F&& f) const
{ {
return PFor<0,0,Xpr,F>(this->lmax().val(), this->id(), mOrig->id(), xpr, std::forward<F>(f)); return PFor<0,0,Xpr,F>(this->lmax().val(), this->id(), mOrig->id(),
mRangePtr->parts().data(), xpr, std::forward<F>(f));
} }
template <class Index> template <class IndexT>
PIndex<Index>& PIndex<Index>::operator()() PIndex<IndexT>& PIndex<IndexT>::operator()()
{ {
mkPos(); mkPos();
return *this; return *this;
} }
template <class Index> template <class IndexT>
PIndex<Index>& PIndex<Index>::operator()(const Sptr<Index>& i) PIndex<IndexT>& PIndex<IndexT>::operator()(const Sptr<IndexT>& i)
{ {
mOrig = i; mOrig = i;
mkPos(); mkPos();
@ -194,8 +197,8 @@ namespace CNORXZ
* PIndex (private) * * PIndex (private) *
************************/ ************************/
template <class Index> template <class IndexT>
void PIndex<Index>::mkPos() void PIndex<IndexT>::mkPos()
{ {
const SizeT opos = mOrig->lex(); const SizeT opos = mOrig->lex();
IB::mPos = 0; IB::mPos = 0;
@ -208,23 +211,38 @@ namespace CNORXZ
CXZ_ERROR("meta position '" << mOrig->meta() << "' not part of range"); CXZ_ERROR("meta position '" << mOrig->meta() << "' not part of range");
} }
/***************************
* PIndex (non-member) *
***************************/
template <class I, class I1>
decltype(auto) operator*(const Sptr<PIndex<I>>& a, const Sptr<I1>& b)
{
return iptrMul(a, b);
}
/********************* /*********************
* PRangeFactory * * PRangeFactory *
*********************/ *********************/
template <class Range> template <class RangeT>
PRangeFactory<Range>::PRangeFactory(const Sptr<Range>& range, const Vector<SizeT>& _parts) : PRangeFactory<RangeT>::PRangeFactory(const Sptr<RangeT>& range, const Vector<SizeT>& _parts) :
mRange(range), mParts(_parts) mRange(range), mParts(_parts)
{} {}
template <class Range> template <class RangeT>
void PRangeFactory<Range>::make() PRangeFactory<RangeT>::PRangeFactory(const RangePtr& range, const Vector<SizeT>& _parts) :
mRange(rangeCast<RangeT>(range)), mParts(_parts)
{}
template <class RangeT>
void PRangeFactory<RangeT>::make()
{ {
const Vector<Uuid> key = { mRange->id() }; const Vector<Uuid> key = { mRange->id() };
const auto& info = typeid(PRange<Range>); const auto& info = typeid(PRange<RangeT>);
mProd = this->fromCreated(info, key); mProd = this->fromCreated(info, key);
if(mProd == nullptr) { if(mProd == nullptr) {
mProd = std::make_shared<PRange<Range>>( new PRange<Range>(mRange, mParts) ); mProd = std::shared_ptr<PRange<RangeT>>( new PRange<RangeT>(mRange, mParts) );
this->addToCreated(info, key, mProd); this->addToCreated(info, key, mProd);
} }
} }
@ -233,57 +251,57 @@ namespace CNORXZ
* PRange * * PRange *
**************/ **************/
template <class Range> template <class RangeT>
SizeT PRange<Range>::size() const SizeT PRange<RangeT>::size() const
{ {
return mParts.size(); return mParts.size();
} }
template <class Range> template <class RangeT>
SizeT PRange<Range>::dim() const SizeT PRange<RangeT>::dim() const
{ {
return 1; return 1;
} }
template <class Range> template <class RangeT>
String PRange<Range>::stringMeta(SizeT pos) const String PRange<RangeT>::stringMeta(SizeT pos) const
{ {
return mRange->stringMeta( mParts[pos] ); return mRange->stringMeta( mParts[pos] );
} }
template <class Range> template <class RangeT>
const TypeInfo& PRange<Range>::type() const const TypeInfo& PRange<RangeT>::type() const
{ {
return typeid(PRange<Range>); return typeid(PRange<RangeT>);
} }
template <class Range> template <class RangeT>
const TypeInfo& PRange<Range>::metaType() const const TypeInfo& PRange<RangeT>::metaType() const
{ {
return mRange->metaType(); return mRange->metaType();
} }
template <class Range> template <class RangeT>
RangePtr PRange<Range>::extend(const RangePtr& r) const RangePtr PRange<RangeT>::extend(const RangePtr& r) const
{ {
CXZ_ERROR("implement!!!"); CXZ_ERROR("implement!!!");
return nullptr; return nullptr;
} }
template <class Range> template <class RangeT>
RangePtr PRange<Range>::orig() const RangePtr PRange<RangeT>::orig() const
{ {
return mRange; return mRange;
} }
template <class Range> template <class RangeT>
const Vector<SizeT>& PRange<Range>::parts() const const Vector<SizeT>& PRange<RangeT>::parts() const
{ {
return mParts; return mParts;
} }
template <class Range> template <class RangeT>
RangePtr PRange<Range>::derive() const RangePtr PRange<RangeT>::derive() const
{ {
Vector<MetaType> meta(this->size()); Vector<MetaType> meta(this->size());
auto i = mRange->begin(); auto i = mRange->begin();
@ -298,11 +316,16 @@ namespace CNORXZ
* PRange (private) * * PRange (private) *
************************/ ************************/
template <class Range> template <class RangeT>
PRange<Range>::PRange(const Sptr<Range>& range, const Vector<SizeT>& _parts) : PRange<RangeT>::PRange(const Sptr<RangeT>& range, const Vector<SizeT>& _parts) :
mRange(range), mParts(_parts) mRange(range), mParts(_parts)
{} {}
template <class RangeT>
Vector<Uuid> PRange<RangeT>::key() const
{
return Vector<Uuid> { mRange->id() };
}
} }
#endif #endif

View file

@ -10,14 +10,14 @@
namespace CNORXZ namespace CNORXZ
{ {
template <class Index> template <class IndexT>
class PIndex : public IndexInterface<Index,typename Index::MetaType> class PIndex : public IndexInterface<PIndex<IndexT>,typename IndexT::MetaType>
{ {
public: public:
typedef IndexInterface<Index,typename Index::MetaType> IB; typedef IndexInterface<PIndex<IndexT>,typename IndexT::MetaType> IB;
typedef PRange<typename Index::RangeType> RangeType; typedef PRange<typename IndexT::RangeType> RangeType;
typedef typename Index::MetaType MetaType; typedef typename IndexT::MetaType MetaType;
PIndex(const RangePtr& range, SizeT pos = 0); PIndex(const RangePtr& range, SizeT pos = 0);
@ -34,7 +34,7 @@ namespace CNORXZ
UPos lmax() const; UPos lmax() const;
IndexId<0> id() const; IndexId<0> id() const;
const MetaType& operator*() const; decltype(auto) operator*() const;
SizeT dim() const; SizeT dim() const;
Sptr<RangeType> range() const; Sptr<RangeType> range() const;
@ -43,9 +43,9 @@ namespace CNORXZ
UPos stepSize(const IndexId<I>& id) const; UPos stepSize(const IndexId<I>& id) const;
String stringMeta() const; String stringMeta() const;
const MetaType& meta() const; decltype(auto) meta() const;
PIndex& at(const MetaType& metaPos); PIndex& at(const MetaType& metaPos);
decltype(auto) xpr(const Sptr<PIndex<Index>>& _this) const; decltype(auto) xpr(const Sptr<PIndex<IndexT>>& _this) const;
template <class I> template <class I>
decltype(auto) format(const Sptr<I>& ind) const; decltype(auto) format(const Sptr<I>& ind) const;
@ -57,39 +57,43 @@ namespace CNORXZ
decltype(auto) ifor(const Xpr& xpr, F&& f) const; decltype(auto) ifor(const Xpr& xpr, F&& f) const;
PIndex& operator()(); PIndex& operator()();
PIndex& operator()(const Sptr<Index>& i); PIndex& operator()(const Sptr<IndexT>& i);
const Sptr<Index>& orig() const; const Sptr<IndexT>& orig() const;
private: private:
Sptr<RangeType> mRangePtr; Sptr<RangeType> mRangePtr;
Sptr<Index> mOrig; Sptr<IndexT> mOrig;
void mkPos(); void mkPos();
}; };
template <class Range> template <class I, class I1>
decltype(auto) operator*(const Sptr<PIndex<I>>& a, const Sptr<I1>& b);
template <class RangeT>
class PRangeFactory : public RangeFactoryBase class PRangeFactory : public RangeFactoryBase
{ {
public: public:
PRangeFactory(const Sptr<Range>& range, const Vector<SizeT>& _parts); PRangeFactory(const Sptr<RangeT>& range, const Vector<SizeT>& _parts);
PRangeFactory(const RangePtr& range, const Vector<SizeT>& _parts);
private: private:
PRangeFactory() = default; PRangeFactory() = default;
virtual void make() override final; virtual void make() override final;
RangePtr mRange; Sptr<RangeT> mRange;
Vector<SizeT> mParts; Vector<SizeT> mParts;
}; };
template <class Range> template <class RangeT>
class PRange : public RangeInterface<PRange<Range>> class PRange : public RangeInterface<PRange<RangeT>>
{ {
public: public:
typedef RangeBase RB; typedef RangeBase RB;
typedef PIndex<typename Range::IndexType> IndexType; typedef PIndex<typename RangeT::IndexType> IndexType;
typedef typename Range::MetaType MetaType; typedef typename RangeT::MetaType MetaType;
friend PRangeFactory<Range>; friend PRangeFactory<RangeT>;
virtual SizeT size() const override final; virtual SizeT size() const override final;
virtual SizeT dim() const override final; virtual SizeT dim() const override final;
@ -106,9 +110,11 @@ namespace CNORXZ
PRange() = delete; PRange() = delete;
PRange(const PRange& in) = delete; PRange(const PRange& in) = delete;
PRange(const Sptr<Range>& range, const Vector<SizeT>& _parts); PRange(const Sptr<RangeT>& range, const Vector<SizeT>& _parts);
Sptr<Range> mRange; virtual Vector<Uuid> key() const override final;
Sptr<RangeT> mRange;
Vector<SizeT> mParts; Vector<SizeT> mParts;
}; };