re-enable index ifor

This commit is contained in:
Christian Zimmermann 2022-10-16 23:05:48 +02:00
parent 6fc3a50fa9
commit b0d002b7b1
23 changed files with 231 additions and 222 deletions

View file

@ -6,29 +6,11 @@
namespace CNORXZ
{
/*
template <class Expr>
auto CRange::ifor(SizeT step, Expr ex) const
-> For<CIndex,Expr>
template <class PosT, class Xpr>
decltype(auto) CIndex::ifor(const PosT& step, const Xpr& xpr) const
{
return For<CIndex,Expr>(this, step, ex);
return For<0,PosT,Xpr>(this->max(), this->id(), step, xpr);
}
*/
/*
template <class Expr>
auto CRange::iforh(SizeT step, Expr ex) const
-> For<CIndex,Expr,ForType::HIDDEN>
{
}
template <class Expr>
auto CRange::pifor(SizeT step, Expr ex) const
-> PFor<CIndex,Expr>
{
}
*/
}
#endif

View file

@ -5,6 +5,7 @@
#include "base/base.h"
#include "ranges/index_base.h"
#include "ranges/range_base.h"
#include "xpr/xpr.h"
namespace CNORXZ
{
@ -25,6 +26,9 @@ namespace CNORXZ
CIndex& operator+=(Int n);
CIndex& operator-=(Int n);
SizeT max() const;
IndexId<0> id() const;
SizeT operator*() const;
SizeT operator->() const;
@ -33,25 +37,15 @@ namespace CNORXZ
SizeT dim() const; // = 1
Sptr<RangeType> range() const;
SizeT getStepSize(PtrId iptr) const;
UPos stepSize(const IndexId<0>& id) const;
String stringMeta() const;
SizeT meta() const;
CIndex& at(const SizeT& metaPos);
//template <class Expr>
//auto ifor(SizeT step, Expr ex) const
// -> For<CIndex,Expr>;
template <class PosT, class Xpr>
decltype(auto) ifor(const PosT& step, const Xpr& xpr) const;
/*
template <class Expr>
auto iforh(SizeT step, Expr ex) const
-> For<CIndex<SizeT>,Expr,ForType::HIDDEN>;
template <class Expr>
auto pifor(SizeT step, Expr ex) const
-> PFor<CIndex<SizeT>,Expr>;
*/
private:
Sptr<RangeType> mRangePtr;
};

View file

@ -11,7 +11,6 @@ namespace CNORXZ
IndexInterface<DIndex,DType>(i.pos()),
mI(std::make_shared<XIndex<Index,Meta>>(i))
{}
}
#endif

View file

@ -5,6 +5,7 @@
#include "base/base.h"
#include "range_base.h"
#include "index_base.h"
#include "xpr/xpr.h"
namespace CNORXZ
{
@ -31,6 +32,9 @@ namespace CNORXZ
DIndex& operator+=(Int n);
DIndex& operator-=(Int n);
SizeT max() const;
IndexId<0> id() const;
DType operator*() const;
DType operator->() const;
@ -39,14 +43,14 @@ namespace CNORXZ
SizeT dim() const;
RangePtr range() const;
SizeT getStepSize(PtrId iptr) const;
UPos stepSize(const IndexId<0>& id) const;
String stringMeta() const;
DType meta() const;
DIndex& at(const DType& meta);
//DExpr ifor(SizeT step, DExpr ex) const;
//DExpr iforh(SizeT step, DExpr ex) const;
DXpr ifor(const UPos& step, const DXpr& xpr) const;
private:
XIndexPtr mI;

View file

@ -5,6 +5,8 @@
#include "base/base.h"
#include "range_base.h"
#include "xpr/index_id.h"
#include "xpr/xpr_base.h"
namespace CNORXZ
{
@ -29,6 +31,7 @@ namespace CNORXZ
SizeT pos() const;
SizeT max() const { return THIS().max(); }
PtrId ptrId() const;
decltype(auto) id() const { return THIS().id(); }
bool operator==(const IndexInterface& in) const;
bool operator!=(const IndexInterface& in) const;
@ -44,21 +47,17 @@ namespace CNORXZ
SizeT dim() const { return THIS().dim(); }
decltype(auto) range() const { return THIS().range(); }
SizeT getStepSize(PtrId iptr) const { return THIS().getStepSize(iptr); }
//SizeT getStepSize(SizeT n) const { return THIS().getStepSize(n); }
template <SizeT J>
decltype(auto) stepSize(const IndexId<J>& id) const { return THIS().stepSize(id); }
String stringMeta() const { return THIS().stringMeta(); }
decltype(auto) meta() const { return THIS().meta(); }
I& at(const MetaType& meta) { return THIS().at(meta); }
/*
template <class Expr>
auto ifor(SizeT step, const Expr ex) const
{ return THIS().template ifor<Expr>(step,ex); }
template <class Expr>
auto iforh(SizeT step, const Expr ex) const
{ return THIS().template iforh<Expr>(step,ex); }
*/
template <class PosT, class Xpr>
decltype(auto) ifor(const PosT& step, const Xpr& xpr) const { return THIS().ifor(step,xpr); }
protected:
SizeT mPos = 0;

View file

@ -12,24 +12,20 @@ namespace CNORXZ
Index(i) {}
template <class Index, SizeT L>
template <SizeT L1>
auto LIndex<Index,L>::getStaticStepSize(PtrId iptr) const
IndexId<L> LIndex<Index,L>::id() const
{
if constexpr(L == 0 or L1 == 0){
return this->getStepSize(iptr);
return IndexId<L>(this->ptrId());
}
template <class Index, SizeT L>
template <SizeT I>
decltype(auto) LIndex<Index,L>::stepSize(const IndexId<I>& id) const
{
if constexpr(L == 0 or I == 0){
return UPos(this->id() == id ? 1 : 0);
}
else {
if constexpr(L == L1){
CXZ_ASSERT(iptr == this->ptrId(),
"got two different indices with the same static label " << L);
return SPos<1>();
}
else {
CXZ_ASSERT(iptr == this->ptrId(),
"got two equal indices with the different static label " << L
<< " and " << L1);
return SPos<0>();
}
return this->id() == id ? SPos<1>() : SPos<0>();
}
}

View file

@ -5,6 +5,7 @@
#include "base/base.h"
#include "ranges/index_base.h"
#include "ranges/range_base.h"
#include "xpr/xpr.h"
namespace CNORXZ
{
@ -20,8 +21,10 @@ namespace CNORXZ
LIndex(const Index& i);
LIndex(Index&& i);
template <SizeT L1>
auto getStaticStepSize(PtrId iptr) const;
IndexId<L> id() const;
template <SizeT I>
decltype(auto) stepSize(const IndexId<I>& id) const;
};
}

View file

@ -6,6 +6,7 @@
#include "base/base.h"
#include "range_base.h"
#include "index_base.h"
#include "xpr/xpr.h"
namespace CNORXZ
{
@ -45,7 +46,10 @@ namespace CNORXZ
MIndex operator-(Int n) const;
MIndex& operator+=(Int n);
MIndex& operator-=(Int n);
SizeT max() const;
decltype(auto) id() const;
SizeT operator*() const;
SizeT operator->() const;
@ -54,22 +58,17 @@ namespace CNORXZ
SizeT dim();
Sptr<RangeType> range();
SizeT getStepSize(PtrId iptr) const;
template <SizeT I>
decltype(auto) stepSize(const IndexId<I>& id) const;
String stringMeta() const;
MetaType meta() const;
MIndex& at(const MetaType& metaPos);
/*
template <class Exprs>
auto ifor(SizeT step, Exprs exs) const;
template <class PosT, class Xpr>
auto ifor(const PosT& step, const Xpr& xpr) const;
template <class Exprs>
auto iforh(SizeT step, Exprs exs) const;
template <class Exprs>
auto pifor(SizeT step, Exprs exs) const;
*/
private:
MIndex() = default;

View file

@ -6,6 +6,7 @@
#include <algorithm>
#include "urange.h"
#include "xpr/for.h"
namespace CNORXZ
{
@ -67,6 +68,18 @@ namespace CNORXZ
return *this;
}
template <typename MetaType>
SizeT UIndex<MetaType>::max() const
{
return mRangePtr->size();
}
template <typename MetaType>
IndexId<0> UIndex<MetaType>::id() const
{
return IndexId<0>(this->ptrId());
}
template <typename MetaType>
const MetaType& UIndex<MetaType>::operator*() const
{
@ -125,36 +138,18 @@ namespace CNORXZ
}
template <typename MetaType>
SizeT UIndex<MetaType>::getStepSize(PtrId iptr) const
template <SizeT I>
UPos UIndex<MetaType>::stepSize(const IndexId<I>& id) const
{
return iptr == this->ptrId() ? 1 : 0;
return UPos(id == this->id() ? 1 : 0);
}
/*
template <typename MetaType>
template <class Expr>
auto UIndex<MetaType>::ifor(size_t step, Expr ex) const
-> For<URange<MetaType>,Expr>
template <class PosT, class Xpr>
decltype(auto) UIndex<MetaType>::ifor(const PosT step, Xpr xpr) const
{
return For<UIndex<MetaType>,Expr>(this, step, ex);
return For<0,PosT,Xpr>(this->max(), this->id(), step, xpr);
}
template <typename MetaType>
template <class Expr>
auto UIndex<MetaType>::iforh(size_t step, Expr ex) const
-> For<URange<MetaType>,Expr,ForType::HIDDEN>
{
return For<UIndex<MetaType>,Expr,ForType::HIDDEN>(this, step, ex);
}
template <typename MetaType>
template <class Expr>
auto UIndex<MetaType>::pifor(size_t step, Expr ex) const
-> PFor<URange<MetaType>,Expr>
{
return PFor<UIndex<MetaType>,Expr>(this, step, ex);
}
*/
/**********************
* URangeFactory *

View file

@ -6,7 +6,7 @@
#include "base/base.h"
#include "ranges/index_base.h"
#include "ranges/range_base.h"
#include "xpr/for_type.h"
#include "xpr/xpr.h"
namespace CNORXZ
{
@ -29,6 +29,9 @@ namespace CNORXZ
UIndex& operator+=(Int n);
UIndex& operator-=(Int n);
SizeT max() const;
IndexId<0> id() const;
const MetaType& operator*() const;
const MetaType* operator->() const;
@ -37,24 +40,17 @@ namespace CNORXZ
SizeT dim() const; // = 1
Sptr<RangeType> range() const;
SizeT getStepSize(PtrId iptr) const;
template <SizeT I>
UPos stepSize(const IndexId<I>& id) const;
String stringMeta() const;
const MetaType& meta() const;
UIndex& at(const MetaType& metaPos);
/*
template <class Expr>
auto ifor(SizeT step, Expr ex) const
-> For<UIndex<MetaType>,Expr>;
template <class Expr>
auto iforh(SizeT step, Expr ex) const
-> For<UIndex<MetaType>,Expr,ForType::HIDDEN>;
template <class PosT, class Xpr>
decltype(auto) ifor(const PosT step, Xpr xpr) const;
template <class Expr>
auto pifor(SizeT step, Expr ex) const
-> PFor<UIndex<MetaType>,Expr>;
*/
private:
Sptr<RangeType> mRangePtr;
const MetaType* mMetaPtr;

View file

@ -78,6 +78,18 @@ namespace CNORXZ
return *this;
}
template <class Index, typename Meta>
SizeT XIndex<Index,Meta>::max() const
{
return mI->max();
}
template <class Index, typename Meta>
IndexId<0> XIndex<Index,Meta>::id() const
{
return IndexId<0>(mI->id().id());
}
template <class Index, typename Meta>
DType XIndex<Index,Meta>::operator*() const
{
@ -117,9 +129,9 @@ namespace CNORXZ
}
template <class Index, typename Meta>
SizeT XIndex<Index,Meta>::getStepSize(PtrId iptr) const
UPos XIndex<Index,Meta>::stepSize(const IndexId<0>& id) const
{
return mI->getStepSize(iptr);
return mI->stepSize(id);
}
template <class Index, typename Meta>
@ -141,19 +153,13 @@ namespace CNORXZ
mI->at(std::any_cast<const Meta&>(meta.get()));
return *this;
}
/*
template <class Index, typename Meta>
DExpr XIndex<Index,Meta>::ifor(SizeT step, DExpr ex) const
{
return mI->ifor(step, ex);
}
template <class Index, typename Meta>
DExpr XIndex<Index,Meta>::iforh(SizeT step, DExpr ex) const
DXpr XIndex<Index,Meta>::ifor(const UPos& step, const DXpr& xpr) const
{
return mI->iforh(step, ex);
return DXpr(mI->ifor(step, xpr));
}
*/
}
#endif

View file

@ -5,6 +5,7 @@
#include "base/base.h"
#include "range_base.h"
#include "index_base.h"
#include "xpr/xpr.h"
namespace CNORXZ
{
@ -24,6 +25,9 @@ namespace CNORXZ
virtual XIndexBase& operator+=(Int n) = 0;
virtual XIndexBase& operator-=(Int n) = 0;
virtual SizeT max() const = 0;
virtual IndexId<0> id() const = 0;
virtual DType operator*() const = 0;
virtual DType operator->() const = 0;
@ -32,15 +36,13 @@ namespace CNORXZ
virtual SizeT dim() const = 0;
virtual RangePtr range() const = 0;
virtual SizeT getStepSize(PtrId iptr) const = 0;
virtual UPos stepSize(const IndexId<0>& id) const = 0;
virtual String stringMeta() const = 0;
virtual DType meta() const = 0;
virtual XIndexBase& at(const DType& meta) = 0;
//virtual DExpr ifor(SizeT step, DExpr ex) const = 0;
//virtual DExpr iforh(SizeT step, DExpr ex) const = 0;
// ...!!!
virtual DXpr ifor(const UPos& step, const DXpr& xpr) const = 0;
};
//Sptr<XIndexBase>& operator++(Sptr<XIndexBase>& i);
@ -72,6 +74,9 @@ namespace CNORXZ
virtual XIndex& operator+=(Int n) override final;
virtual XIndex& operator-=(Int n) override final;
virtual SizeT max() const override final;
virtual IndexId<0> id() const override final;
virtual DType operator*() const override final;
virtual DType operator->() const override final;
@ -80,15 +85,13 @@ namespace CNORXZ
virtual SizeT dim() const override final;
virtual RangePtr range() const override final;
virtual SizeT getStepSize(PtrId iptr) const override final;
virtual UPos stepSize(const IndexId<0>& id) const override final;
virtual String stringMeta() const override final;
virtual DType meta() const override final;
virtual XIndexBase& at(const DType& meta) override final;
//virtual DExpr ifor(SizeT step, DExpr ex) const override final;
//virtual DExpr iforh(SizeT step, DExpr ex) const override final;
// ....!!!!
virtual DXpr ifor(const UPos& step, const DXpr& xpr) const override final;
private:
IndexPtr<Index,Meta> mI;

View file

@ -12,18 +12,20 @@ namespace CNORXZ
* For *
***********/
template <SizeT L, class Xpr>
constexpr For<L,Xpr>::For(SizeT size, const IndexId<L>& id, SizeT step, const Xpr& xpr) :
template <SizeT L, class PosT, class Xpr>
constexpr For<L,PosT,Xpr>::For(SizeT size, const IndexId<L>& id, const PosT& step, const Xpr& xpr) :
mSize(size),
mId(id),
mStep(step),
mXpr(xpr),
mStep(step),
mExt(mXpr.rootSteps(mId))
{}
{
static_assert(is_pos_type<PosT>::value, "got non-pos type");
}
template <SizeT L, class Xpr>
template <SizeT L, class PosT, class Xpr>
template <class PosT1, class PosT2>
inline SizeT For<L,Xpr>::operator()(const PosT1& mlast, const PosT2& last) const
inline SizeT For<L,PosT,Xpr>::operator()(const PosT1& mlast, const PosT2& last) const
{
for(SizeT i = 0; i != mSize; ++i){
const auto mpos = mlast + mStep * UPos(i);
@ -33,63 +35,65 @@ namespace CNORXZ
return 0;
}
template <SizeT L, class Xpr>
inline SizeT For<L,Xpr>::operator()() const
template <SizeT L, class PosT, class Xpr>
inline SizeT For<L,PosT,Xpr>::operator()() const
{
for(SizeT i = 0; i != mSize; ++i){
const SizeT mpos = mStep * UPos(i);
const auto mpos = mStep * UPos(i);
const auto pos = mExt * UPos(i);
mXpr(mpos, pos);
}
return 0;
}
template <SizeT L, class Xpr>
template <SizeT L, class PosT, class Xpr>
template <SizeT I>
inline decltype(auto) For<L,Xpr>::rootSteps(const IndexId<I>& id) const
inline decltype(auto) For<L,PosT,Xpr>::rootSteps(const IndexId<I>& id) const
{
return mXpr.rootSteps(id);
}
/*************
* SLFor *
*************/
/************
* SFor *
************/
template <SizeT N, SizeT L, SizeT S, class Xpr>
constexpr SLFor<N,L,S,Xpr>::SLFor(const IndexId<L>& id, const Xpr& xpr) :
template <SizeT N, SizeT L, class PosT, class Xpr>
constexpr SFor<N,L,PosT,Xpr>::SFor(const IndexId<L>& id, const PosT& step, const Xpr& xpr) :
mId(id),
mStep(step),
mXpr(xpr),
mExt(mXpr.RootSteps(mId))
{}
{
static_assert(is_pos_type<PosT>::value, "got non-pos type");
}
template <SizeT N, SizeT L, SizeT S, class Xpr>
template <SizeT N, SizeT L, class PosT, class Xpr>
template <class PosT1, class PosT2>
constexpr SizeT SLFor<N,L,S,Xpr>::operator()(const PosT1& mlast, const PosT2& last) const
constexpr SizeT SFor<N,L,PosT,Xpr>::operator()(const PosT1& mlast, const PosT2& last) const
{
return exec<0>(mlast, last);
}
template <SizeT N, SizeT L, SizeT S, class Xpr>
constexpr SizeT SLFor<N,L,S,Xpr>::operator()() const
template <SizeT N, SizeT L, class PosT, class Xpr>
constexpr SizeT SFor<N,L,PosT,Xpr>::operator()() const
{
return exec<0>();
}
template <SizeT N, SizeT L, SizeT S, class Xpr>
template <SizeT N, SizeT L, class PosT, class Xpr>
template <SizeT I>
constexpr decltype(auto) SLFor<N,L,S,Xpr>::rootSteps(const IndexId<I>& id) const
constexpr decltype(auto) SFor<N,L,PosT,Xpr>::rootSteps(const IndexId<I>& id) const
{
return mXpr.rootSteps(id);
}
template <SizeT N, SizeT L, SizeT S, class Xpr>
template <SizeT N, SizeT L, class PosT, class Xpr>
template <SizeT I, class PosT1, class PosT2>
constexpr SizeT SLFor<N,L,S,Xpr>::exec(const PosT1& mlast, const PosT2& last) const
constexpr SizeT SFor<N,L,PosT,Xpr>::exec(const PosT1& mlast, const PosT2& last) const
{
constexpr SPos<I> i;
constexpr SPos<S> step;
const auto mpos = mlast + step * i;
const auto mpos = mlast + mStep * i;
const auto pos = last + mExt * i;
mXpr(mpos, pos);
if constexpr(I < N-1){
@ -100,13 +104,12 @@ namespace CNORXZ
}
}
template <SizeT N, SizeT L, SizeT S, class Xpr>
template <SizeT N, SizeT L, class PosT, class Xpr>
template <SizeT I>
constexpr SizeT SLFor<N,L,S,Xpr>::exec() const
constexpr SizeT SFor<N,L,PosT,Xpr>::exec() const
{
constexpr SPos<I> i;
constexpr SPos<S> step;
const auto mpos = step * i;
const auto mpos = mStep * i;
const auto pos = mExt * i;
mXpr(mpos, pos);
if constexpr(I < N-1){
@ -121,18 +124,24 @@ namespace CNORXZ
* TFor *
************/
template <SizeT L, class Xpr>
constexpr TFor<L,Xpr>::TFor(SizeT size, const IndexId<L>& id, SizeT step, const Xpr& xpr) :
template <SizeT L, class PosT, class Xpr>
constexpr TFor<L,PosT,Xpr>::TFor(SizeT size, const IndexId<L>& id, const PosT& step, const Xpr& xpr) :
mSize(size),
mId(id),
mStep(step),
mXpr(xpr),
mExt(mXpr.rootSteps(mId))
{}
{
static_assert(is_pos_type<PosT>::value, "got non-pos type");
if constexpr(is_static_pos_type<PosT>::value){
static_assert(step.val() != 0, "step has to be non-zero for TPos");
}
CXZ_ASSERT(step.val() != 0, "step has to be non-zero for TPos");
}
template <SizeT L, class Xpr>
template <SizeT L, class PosT, class Xpr>
template <class PosT1, class PosT2>
inline SizeT TFor<L,Xpr>::operator()(const PosT1& mlast, const PosT2& last) const
inline SizeT TFor<L,PosT,Xpr>::operator()(const PosT1& mlast, const PosT2& last) const
{
int i = 0;
#pragma omp parallel shared(mXpr) private(i)
@ -148,8 +157,8 @@ namespace CNORXZ
return 0;
}
template <SizeT L, class Xpr>
inline SizeT TFor<L,Xpr>::operator()() const
template <SizeT L, class PosT, class Xpr>
inline SizeT TFor<L,PosT,Xpr>::operator()() const
{
int i = 0;
#pragma omp parallel shared(mXpr) private(i)
@ -165,9 +174,9 @@ namespace CNORXZ
return 0;
}
template <SizeT L, class Xpr>
template <SizeT L, class PosT, class Xpr>
template <SizeT I>
inline decltype(auto) TFor<L,Xpr>::rootSteps(const IndexId<I>& id) const
inline decltype(auto) TFor<L,PosT,Xpr>::rootSteps(const IndexId<I>& id) const
{
return mXpr.rootSteps(id);
}

View file

@ -8,13 +8,13 @@
namespace CNORXZ
{
template <SizeT L, class Xpr>
class For : public XprInterface<For<L,Xpr>>
template <SizeT L, class PosT, class Xpr>
class For : public XprInterface<For<L,PosT,Xpr>>
{
public:
DEFAULT_MEMBERS(For);
constexpr For(SizeT size, const IndexId<L>& id, SizeT step, const Xpr& xpr);
constexpr For(SizeT size, const IndexId<L>& id, const PosT& step, const Xpr& xpr);
template <class PosT1, class PosT2>
inline SizeT operator()(const PosT1& mlast, const PosT2& last) const;
@ -28,20 +28,20 @@ namespace CNORXZ
SizeT mSize = 0;
IndexId<L> mId;
Xpr mXpr;
UPos mStep;
typedef decltype(mXpr.rootSteps(mId)) PosT;
PosT mExt;
PosT mStep; // one-dim
typedef decltype(mXpr.rootSteps(mId)) XPosT;
XPosT mExt;
};
// unrolled loop:
template <SizeT N, SizeT L, SizeT S, class Xpr>
class SLFor : public XprInterface<SLFor<N,L,S,Xpr>>
template <SizeT N, SizeT L, class PosT, class Xpr>
class SFor : public XprInterface<SFor<N,L,PosT,Xpr>>
{
public:
DEFAULT_MEMBERS(SLFor);
DEFAULT_MEMBERS(SFor);
constexpr SLFor(const IndexId<L>& id, const Xpr& xpr);
constexpr SFor(const IndexId<L>& id, const PosT& step, const Xpr& xpr);
template <class PosT1, class PosT2>
constexpr SizeT operator()(const PosT1& mlast, const PosT2& last) const;
@ -61,20 +61,21 @@ namespace CNORXZ
IndexId<L> mId;
Xpr mXpr;
typedef decltype(mXpr.RootSteps(mId)) PosT;
PosT mExt;
PosT mStep;
typedef decltype(mXpr.RootSteps(mId)) XPosT;
XPosT mExt;
};
// multi-threading
template <SizeT L, class Xpr>
class TFor : public XprInterface<TFor<L,Xpr>>
template <SizeT L, class PosT, class Xpr>
class TFor : public XprInterface<TFor<L,PosT,Xpr>>
{
public:
DEFAULT_MEMBERS(TFor);
constexpr TFor(SizeT size, const IndexId<L>& id, SizeT step, const Xpr& xpr);
constexpr TFor(SizeT size, const IndexId<L>& id, const PosT& step, const Xpr& xpr);
template <class PosT1, class PosT2>
inline SizeT operator()(const PosT1& mlast, const PosT2& last) const;
@ -88,9 +89,9 @@ namespace CNORXZ
SizeT mSize = 0;
IndexId<L> mId = 0;
Xpr mXpr;
UPos mStep;
typedef decltype(mXpr.rootSteps(mId)) PosT;
PosT mExt;
PosT mStep;
typedef decltype(mXpr.rootSteps(mId)) XPosT;
XPosT mExt;
};

View file

@ -8,7 +8,7 @@ namespace CNORXZ
{
template <SizeT I>
explicit constexpr IndexId<I>::IndexId(PtrId id) :
constexpr IndexId<I>::IndexId(PtrId id) :
mId(id)
{}

View file

@ -1,4 +1,6 @@
#include "vpos_type.cc.h"
#include "pos_type.cc.h"
#include "xpr_base.cc.h"
#include "for.cc.h"
#include "index_id.cc.h"

View file

@ -1,6 +1,8 @@
#include "vpos_type.h"
#include "pos_type.h"
#include "xpr_base.h"
#include "for.h"
#include "index_id.h"
#include "xpr.cc.h"

View file

@ -37,7 +37,7 @@ namespace CNORXZ
template <class Xpr>
DPos VXpr<Xpr>::vrootSteps(const IndexId<0>& id) const
{
return DPos(this->rootSteps(ptrId));
return DPos(this->rootSteps(id));
}
/************
@ -45,15 +45,13 @@ namespace CNORXZ
************/
template <class Xpr>
explicit DXpr::DXpr(const Xpr& a) :
ObjHandle<VXprBase>(VXpr<Xpr>(a))
DXpr::DXpr(const Xpr& a) :
ObjHandle<VXprBase>(std::make_unique<VXpr<Xpr>>(a))
{}
template <class PosT>
inline SizeT DXpr::operator()(const UPos& mlast, const PosT& last) const
inline SizeT DXpr::operator()(const UPos& mlast, const DPos& last) const
{
DPosRef dlast(&last);
return mC->vexec(mlast, dlast);
return mC->vexec(mlast, last);
}
inline SizeT DXpr::operator()() const
@ -64,7 +62,7 @@ namespace CNORXZ
template <SizeT I>
inline DPos DXpr::rootSteps(const IndexId<I>& id) const
{
return mC->rootSteps(IndexId<0>(id.id()));
return mC->vrootSteps(IndexId<0>(id.id()));
}
}

View file

@ -64,8 +64,7 @@ namespace CNORXZ
template <class Xpr>
explicit DXpr(const Xpr& a);
template <class PosT>
inline SizeT operator()(const UPos& mlast, const PosT& last) const;
inline SizeT operator()(const UPos& mlast, const DPos& last) const;
inline SizeT operator()() const;
template <SizeT I>

View file

@ -6,6 +6,7 @@
#include "range_base.h"
#include "index_base.h"
#include "xindex.h"
#include "xpr/xpr.h"
namespace CNORXZ
{
@ -33,6 +34,9 @@ namespace CNORXZ
YIndex& operator+=(Int n);
YIndex& operator-=(Int n);
SizeT max() const;
IndexId<0> id() const;
DType operator*() const;
DType operator->() const;
@ -41,14 +45,13 @@ namespace CNORXZ
SizeT dim() const;
Sptr<YRange> range() const;
SizeT getStepSize(PtrId iptr) const;
UPos stepSize(const IndexId<0> id) const;
String stringMeta() const;
DType meta() const;
YIndex& at(const DType& meta);
//DExpr ifor(SizeT step, DExpr ex) const;
//DExpr iforh(SizeT step, DExpr ex) const;
DXpr ifor(const UPos& step, const DXpr& xpr) const;
private:

View file

@ -51,6 +51,16 @@ namespace CNORXZ
return *this;
}
SizeT CIndex::max() const
{
return mRangePtr->size();
}
IndexId<0> CIndex::id() const
{
return IndexId<0>(this->ptrId());
}
SizeT CIndex::operator*() const
{
return IB::mPos;
@ -83,9 +93,9 @@ namespace CNORXZ
return mRangePtr;
}
SizeT CIndex::getStepSize(PtrId iptr) const
UPos CIndex::stepSize(const IndexId<0>& id) const
{
return iptr == this->ptrId() ? 1 : 0;
return UPos(id == this->id() ? 1 : 0);
}
String CIndex::stringMeta() const

View file

@ -116,9 +116,9 @@ namespace CNORXZ
return mI->range();
}
SizeT DIndex::getStepSize(PtrId iptr) const
UPos DIndex::stepSize(const IndexId<0>& id) const
{
return mI->getStepSize(iptr);
return mI->stepSize(id);
}
String DIndex::stringMeta() const
@ -138,7 +138,9 @@ namespace CNORXZ
return *this;
}
//DExpr DIndex::ifor(SizeT step, DExpr ex) const;
//DExpr DIndex::iforh(SizeT step, DExpr ex) const;
DXpr DIndex::ifor(const UPos& step, const DXpr& xpr) const
{
return DXpr(mI->ifor(step, xpr));
}
}

View file

@ -86,6 +86,20 @@ namespace CNORXZ
return *this;
}
SizeT YIndex::max() const
{
SizeT o = 1;
for(auto& i: mIs){
o *= i->max();
}
return o;
}
IndexId<0> YIndex::id() const
{
return IndexId<0>(this->ptrId());
}
DType YIndex::operator*() const
{
assert(0);
@ -122,11 +136,11 @@ namespace CNORXZ
return mRangePtr;
}
SizeT YIndex::getStepSize(PtrId iptr) const
UPos YIndex::stepSize(const IndexId<0> id) const
{
assert(0);
// sub inds !!!
return 0;
return UPos(0);
}
String YIndex::stringMeta() const
@ -156,20 +170,13 @@ namespace CNORXZ
}
return *this;
}
/*
DExpr YIndex::ifor(SizeT step, DExpr ex) const
DXpr YIndex::ifor(const UPos& step, const DXpr& xpr) const
{
assert(0);
return DExpr();
return DXpr();
}
DExpr YIndex::iforh(SizeT step, DExpr ex) const
{
assert(0);
return DExpr();
}
*/
/**********************
* YRangeFactory *
**********************/