index_id
This commit is contained in:
parent
3eea7f2314
commit
6fc3a50fa9
7 changed files with 166 additions and 115 deletions
|
@ -36,19 +36,19 @@ namespace CNORXZ
|
|||
bool operator>(const IndexInterface& in) const;
|
||||
bool operator<=(const IndexInterface& in) const;
|
||||
bool operator>=(const IndexInterface& in) const;
|
||||
auto operator*() const { return THIS().operator*(); }
|
||||
auto operator->() const { return THIS().operator->(); }
|
||||
decltype(auto) operator*() const { return THIS().operator*(); }
|
||||
decltype(auto) operator->() const { return THIS().operator->(); }
|
||||
|
||||
Int pp(PtrId idxPtrNum) { return THIS().pp(idxPtrNum); }
|
||||
Int mm(PtrId idxPtrNum) { return THIS().mm(idxPtrNum); }
|
||||
|
||||
SizeT dim() const { return THIS().dim(); }
|
||||
auto range() const { return THIS().range(); }
|
||||
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); }
|
||||
|
||||
String stringMeta() const { return THIS().stringMeta(); }
|
||||
auto meta() const { return THIS().meta(); }
|
||||
decltype(auto) meta() const { return THIS().meta(); }
|
||||
I& at(const MetaType& meta) { return THIS().at(meta); }
|
||||
/*
|
||||
template <class Expr>
|
||||
|
|
|
@ -12,18 +12,18 @@ namespace CNORXZ
|
|||
* For *
|
||||
***********/
|
||||
|
||||
template <class Xpr>
|
||||
constexpr For<Xpr>::For(SizeT size, PtrId iptrId, SizeT step, const Xpr& xpr) :
|
||||
template <SizeT L, class Xpr>
|
||||
constexpr For<L,Xpr>::For(SizeT size, const IndexId<L>& id, SizeT step, const Xpr& xpr) :
|
||||
mSize(size),
|
||||
mIptrId(iptrId),
|
||||
mId(id),
|
||||
mStep(step),
|
||||
mXpr(xpr),
|
||||
mExt(mXpr.rootSteps(mIptrId))
|
||||
mExt(mXpr.rootSteps(mId))
|
||||
{}
|
||||
|
||||
template <class Xpr>
|
||||
template <SizeT L, class Xpr>
|
||||
template <class PosT1, class PosT2>
|
||||
inline SizeT For<Xpr>::operator()(const PosT1& mlast, const PosT2& last) const
|
||||
inline SizeT For<L,Xpr>::operator()(const PosT1& mlast, const PosT2& last) const
|
||||
{
|
||||
for(SizeT i = 0; i != mSize; ++i){
|
||||
const auto mpos = mlast + mStep * UPos(i);
|
||||
|
@ -33,8 +33,8 @@ namespace CNORXZ
|
|||
return 0;
|
||||
}
|
||||
|
||||
template <class Xpr>
|
||||
inline SizeT For<Xpr>::operator()() const
|
||||
template <SizeT L, class Xpr>
|
||||
inline SizeT For<L,Xpr>::operator()() const
|
||||
{
|
||||
for(SizeT i = 0; i != mSize; ++i){
|
||||
const SizeT mpos = mStep * UPos(i);
|
||||
|
@ -44,17 +44,11 @@ namespace CNORXZ
|
|||
return 0;
|
||||
}
|
||||
|
||||
template <class Xpr>
|
||||
inline auto For<Xpr>::rootSteps(PtrId ptrId) const
|
||||
template <SizeT L, class Xpr>
|
||||
template <SizeT I>
|
||||
inline decltype(auto) For<L,Xpr>::rootSteps(const IndexId<I>& id) const
|
||||
{
|
||||
return mXpr.rootSteps(ptrId);
|
||||
}
|
||||
|
||||
template <class Xpr>
|
||||
template <SizeT L>
|
||||
constexpr auto For<Xpr>::staticRootSteps(PtrId ptrId) const
|
||||
{
|
||||
return mXpr.template staticRootSteps<L>(ptrId);
|
||||
return mXpr.rootSteps(id);
|
||||
}
|
||||
|
||||
|
||||
|
@ -63,10 +57,10 @@ namespace CNORXZ
|
|||
*************/
|
||||
|
||||
template <SizeT N, SizeT L, SizeT S, class Xpr>
|
||||
constexpr SLFor<N,L,S,Xpr>::SLFor(PtrId iptrId, const Xpr& xpr) :
|
||||
mIptrId(iptrId),
|
||||
constexpr SLFor<N,L,S,Xpr>::SLFor(const IndexId<L>& id, const Xpr& xpr) :
|
||||
mId(id),
|
||||
mXpr(xpr),
|
||||
mExt(mXpr.template staticRootSteps<L>(mIptrId))
|
||||
mExt(mXpr.RootSteps(mId))
|
||||
{}
|
||||
|
||||
template <SizeT N, SizeT L, SizeT S, class Xpr>
|
||||
|
@ -83,16 +77,10 @@ namespace CNORXZ
|
|||
}
|
||||
|
||||
template <SizeT N, SizeT L, SizeT S, class Xpr>
|
||||
constexpr auto SLFor<N,L,S,Xpr>::rootSteps(PtrId ptrId) const
|
||||
template <SizeT I>
|
||||
constexpr decltype(auto) SLFor<N,L,S,Xpr>::rootSteps(const IndexId<I>& id) const
|
||||
{
|
||||
return mXpr.rootSteps(ptrId);
|
||||
}
|
||||
|
||||
template <SizeT N, SizeT L, SizeT S, class Xpr>
|
||||
template <SizeT L2>
|
||||
constexpr auto SLFor<N,L,S,Xpr>::staticRootSteps(PtrId ptrId) const
|
||||
{
|
||||
return mXpr.template staticRootSteps<L2>(ptrId);
|
||||
return mXpr.rootSteps(id);
|
||||
}
|
||||
|
||||
template <SizeT N, SizeT L, SizeT S, class Xpr>
|
||||
|
@ -133,18 +121,18 @@ namespace CNORXZ
|
|||
* TFor *
|
||||
************/
|
||||
|
||||
template <class Xpr>
|
||||
constexpr TFor<Xpr>::TFor(SizeT size, PtrId iptrId, SizeT step, const Xpr& xpr) :
|
||||
template <SizeT L, class Xpr>
|
||||
constexpr TFor<L,Xpr>::TFor(SizeT size, const IndexId<L>& id, SizeT step, const Xpr& xpr) :
|
||||
mSize(size),
|
||||
mIptrId(iptrId),
|
||||
mId(id),
|
||||
mStep(step),
|
||||
mXpr(xpr),
|
||||
mExt(mXpr.rootSteps(mIptrId))
|
||||
mExt(mXpr.rootSteps(mId))
|
||||
{}
|
||||
|
||||
template <class Xpr>
|
||||
template <SizeT L, class Xpr>
|
||||
template <class PosT1, class PosT2>
|
||||
inline SizeT TFor<Xpr>::operator()(const PosT1& mlast, const PosT2& last) const
|
||||
inline SizeT TFor<L,Xpr>::operator()(const PosT1& mlast, const PosT2& last) const
|
||||
{
|
||||
int i = 0;
|
||||
#pragma omp parallel shared(mXpr) private(i)
|
||||
|
@ -152,17 +140,16 @@ namespace CNORXZ
|
|||
auto xpr = mXpr;
|
||||
#pragma omp for
|
||||
for(i = 0; i < mSize; i++){
|
||||
const UPos I(i);
|
||||
const auto mpos = mlast + mStep * I;
|
||||
const auto pos = last + mExt * I;
|
||||
const auto mpos = mlast + mStep * UPos(i);
|
||||
const auto pos = last + mExt * UPos(i);
|
||||
mXpr(mpos, pos);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <class Xpr>
|
||||
inline SizeT TFor<Xpr>::operator()() const
|
||||
template <SizeT L, class Xpr>
|
||||
inline SizeT TFor<L,Xpr>::operator()() const
|
||||
{
|
||||
int i = 0;
|
||||
#pragma omp parallel shared(mXpr) private(i)
|
||||
|
@ -170,26 +157,19 @@ namespace CNORXZ
|
|||
auto xpr = mXpr;
|
||||
#pragma omp for
|
||||
for(i = 0; i < static_cast<int>(mSize); i++){
|
||||
const UPos I(i);
|
||||
const auto mpos = mStep * I;
|
||||
const auto pos = mExt * I;
|
||||
const auto mpos = mStep * UPos(i);
|
||||
const auto pos = mExt * UPos(i);
|
||||
mXpr(mpos, pos);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <class Xpr>
|
||||
inline auto TFor<Xpr>::rootSteps(PtrId ptrId) const
|
||||
template <SizeT L, class Xpr>
|
||||
template <SizeT I>
|
||||
inline decltype(auto) TFor<L,Xpr>::rootSteps(const IndexId<I>& id) const
|
||||
{
|
||||
return mXpr.rootSteps(ptrId);
|
||||
}
|
||||
|
||||
template <class Xpr>
|
||||
template <SizeT L2>
|
||||
inline auto TFor<Xpr>::staticRootSteps(PtrId ptrId) const
|
||||
{
|
||||
return mXpr.template staticRootSteps<L2>(ptrId);
|
||||
return mXpr.rootSteps(id);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -7,43 +7,29 @@
|
|||
|
||||
namespace CNORXZ
|
||||
{
|
||||
/*
|
||||
template <class ForT, class Xpr>
|
||||
class ForInterface : public XprInterface<ForInterface<ForT,Xpr>>
|
||||
{
|
||||
public:
|
||||
DEFAULT_MEMBERS(ForInterface);
|
||||
|
||||
inline auto rootSteps(PtrId ptrId) const;
|
||||
|
||||
template <SizeT L>
|
||||
constexpr auto staticRootSteps(PtrId ptrId) const;
|
||||
};
|
||||
*/
|
||||
template <class Xpr>
|
||||
class For : public XprInterface<For<Xpr>>
|
||||
template <SizeT L, class Xpr>
|
||||
class For : public XprInterface<For<L,Xpr>>
|
||||
{
|
||||
public:
|
||||
DEFAULT_MEMBERS(For);
|
||||
|
||||
constexpr For(SizeT size, PtrId iptrId, SizeT step, const Xpr& xpr);
|
||||
constexpr For(SizeT size, const IndexId<L>& id, SizeT step, const Xpr& xpr);
|
||||
|
||||
template <class PosT1, class PosT2>
|
||||
inline SizeT operator()(const PosT1& mlast, const PosT2& last) const;
|
||||
|
||||
inline SizeT operator()() const;
|
||||
|
||||
inline auto rootSteps(PtrId ptrId) const;
|
||||
template <SizeT I>
|
||||
inline decltype(auto) rootSteps(const IndexId<I>& id) const;
|
||||
|
||||
template <SizeT L>
|
||||
constexpr auto staticRootSteps(PtrId ptrId) const;
|
||||
|
||||
private:
|
||||
SizeT mSize = 0;
|
||||
PtrId mIptrId = 0;
|
||||
IndexId<L> mId;
|
||||
Xpr mXpr;
|
||||
UPos mStep;
|
||||
typedef decltype(mXpr.rootSteps(0)) PosT;
|
||||
typedef decltype(mXpr.rootSteps(mId)) PosT;
|
||||
PosT mExt;
|
||||
|
||||
};
|
||||
|
@ -55,17 +41,15 @@ namespace CNORXZ
|
|||
public:
|
||||
DEFAULT_MEMBERS(SLFor);
|
||||
|
||||
constexpr SLFor(PtrId iptrId, const Xpr& xpr);
|
||||
constexpr SLFor(const IndexId<L>& id, const Xpr& xpr);
|
||||
|
||||
template <class PosT1, class PosT2>
|
||||
constexpr SizeT operator()(const PosT1& mlast, const PosT2& last) const;
|
||||
|
||||
constexpr SizeT operator()() const;
|
||||
|
||||
constexpr auto rootSteps(PtrId ptrId) const;
|
||||
|
||||
template <SizeT L2>
|
||||
constexpr auto staticRootSteps(PtrId ptrId) const;
|
||||
template <SizeT I>
|
||||
constexpr decltype(auto) rootSteps(const IndexId<I>& id) const;
|
||||
|
||||
private:
|
||||
|
||||
|
@ -74,40 +58,38 @@ namespace CNORXZ
|
|||
|
||||
template <SizeT I>
|
||||
constexpr SizeT exec() const;
|
||||
|
||||
PtrId mIptrId = 0;
|
||||
|
||||
IndexId<L> mId;
|
||||
Xpr mXpr;
|
||||
typedef decltype(mXpr.template staticRootSteps<L>(0)) PosT;
|
||||
typedef decltype(mXpr.RootSteps(mId)) PosT;
|
||||
PosT mExt;
|
||||
|
||||
};
|
||||
|
||||
|
||||
// multi-threading
|
||||
template <class Xpr>
|
||||
class TFor : public XprInterface<TFor<Xpr>>
|
||||
template <SizeT L, class Xpr>
|
||||
class TFor : public XprInterface<TFor<L,Xpr>>
|
||||
{
|
||||
public:
|
||||
DEFAULT_MEMBERS(TFor);
|
||||
|
||||
constexpr TFor(SizeT size, PtrId iptrId, SizeT step, const Xpr& xpr);
|
||||
constexpr TFor(SizeT size, const IndexId<L>& id, SizeT step, const Xpr& xpr);
|
||||
|
||||
template <class PosT1, class PosT2>
|
||||
inline SizeT operator()(const PosT1& mlast, const PosT2& last) const;
|
||||
|
||||
inline SizeT operator()() const;
|
||||
|
||||
inline auto rootSteps(PtrId ptrId) const;
|
||||
|
||||
template <SizeT L2>
|
||||
inline auto staticRootSteps(PtrId ptrId) const;
|
||||
template <SizeT I>
|
||||
inline decltype(auto) rootSteps(const IndexId<I>& id) const;
|
||||
|
||||
private:
|
||||
SizeT mSize = 0;
|
||||
PtrId mIptrId = 0;
|
||||
IndexId<L> mId = 0;
|
||||
Xpr mXpr;
|
||||
UPos mStep;
|
||||
typedef decltype(mXpr.rootSteps(0)) PosT;
|
||||
typedef decltype(mXpr.rootSteps(mId)) PosT;
|
||||
PosT mExt;
|
||||
|
||||
};
|
||||
|
|
65
src/include/ranges/xpr/index_id.cc.h
Normal file
65
src/include/ranges/xpr/index_id.cc.h
Normal file
|
@ -0,0 +1,65 @@
|
|||
|
||||
#ifndef __cxz_index_id_cc_h__
|
||||
#define __cxz_index_id_cc_h__
|
||||
|
||||
#include "index_id.h"
|
||||
|
||||
namespace CNORXZ
|
||||
{
|
||||
|
||||
template <SizeT I>
|
||||
explicit constexpr IndexId<I>::IndexId(PtrId id) :
|
||||
mId(id)
|
||||
{}
|
||||
|
||||
template <SizeT I>
|
||||
constexpr const PtrId& IndexId<I>::id() const
|
||||
{
|
||||
return mId;
|
||||
}
|
||||
|
||||
template <SizeT I>
|
||||
template <SizeT J>
|
||||
constexpr decltype(auto) IndexId<I>::operator==(const IndexId<J>& a) const
|
||||
{
|
||||
if constexpr(I != 0 and J != 0){
|
||||
if constexpr(I == J){
|
||||
CXZ_ASSERT(mId == a.id(),
|
||||
"got different index ids for equal static index label");
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
CXZ_ASSERT(mId == a.id(),
|
||||
"got equal index ids for different static index label");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return mId == a.id();
|
||||
}
|
||||
}
|
||||
|
||||
template <SizeT I>
|
||||
template <SizeT J>
|
||||
constexpr decltype(auto) IndexId<I>::operator!=(const IndexId<J>& a) const
|
||||
{
|
||||
if constexpr(I != 0 and J != 0){
|
||||
if constexpr(I == J){
|
||||
CXZ_ASSERT(mId == a.id(),
|
||||
"got different index ids for equal static index label");
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
CXZ_ASSERT(mId == a.id(),
|
||||
"got equal index ids for different static index label");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return mId != a.id();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
32
src/include/ranges/xpr/index_id.h
Normal file
32
src/include/ranges/xpr/index_id.h
Normal file
|
@ -0,0 +1,32 @@
|
|||
|
||||
#ifndef __cxz_index_id_h__
|
||||
#define __cxz_index_id_h__
|
||||
|
||||
#include "base/base.h"
|
||||
|
||||
namespace CNORXZ
|
||||
{
|
||||
|
||||
// if I == 0: no static comparison; fall back to usual runtime comparison of mId
|
||||
template <SizeT I = 0>
|
||||
class IndexId
|
||||
{
|
||||
private:
|
||||
PtrId mId = 0;
|
||||
|
||||
public:
|
||||
DEFAULT_MEMBERS(IndexId);
|
||||
|
||||
explicit constexpr IndexId(PtrId id);
|
||||
|
||||
constexpr const PtrId& id() const;
|
||||
|
||||
template <SizeT J>
|
||||
constexpr decltype(auto) operator==(const IndexId<J>& a) const;
|
||||
|
||||
template <SizeT J>
|
||||
constexpr decltype(auto) operator!=(const IndexId<J>& a) const;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
|
@ -35,7 +35,7 @@ namespace CNORXZ
|
|||
}
|
||||
|
||||
template <class Xpr>
|
||||
DPos VXpr<Xpr>::vrootSteps(PtrId ptrId) const
|
||||
DPos VXpr<Xpr>::vrootSteps(const IndexId<0>& id) const
|
||||
{
|
||||
return DPos(this->rootSteps(ptrId));
|
||||
}
|
||||
|
@ -61,15 +61,10 @@ namespace CNORXZ
|
|||
return mC->vexec();
|
||||
}
|
||||
|
||||
inline DPos DXpr::rootSteps(PtrId ptrId) const
|
||||
template <SizeT I>
|
||||
inline DPos DXpr::rootSteps(const IndexId<I>& id) const
|
||||
{
|
||||
return mC->rootSteps(ptrId);
|
||||
}
|
||||
|
||||
template <SizeT N>
|
||||
inline DPos DXpr::staticRootSteps(PtrId ptrId) const
|
||||
{
|
||||
return this->rootSteps(ptrId);
|
||||
return mC->rootSteps(IndexId<0>(id.id()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include "base/base.h"
|
||||
#include "pos_type.h"
|
||||
#include "index_id.h"
|
||||
|
||||
namespace CNORXZ
|
||||
{
|
||||
|
@ -22,10 +23,8 @@ namespace CNORXZ
|
|||
|
||||
inline SizeT operator()() const { return THIS()(); }
|
||||
|
||||
inline auto rootSteps(PtrId ptrId) const { return THIS().rootSteps(ptrId); }
|
||||
|
||||
template <SizeT N>
|
||||
constexpr auto staticRootSteps(PtrId ptrId) const { return THIS().template staticRootSteps<N>(ptrId); }
|
||||
template <SizeT I>
|
||||
inline decltype(auto) rootSteps(const IndexId<I>& id) const { return THIS().rootSteps(id); }
|
||||
};
|
||||
|
||||
class VXprBase
|
||||
|
@ -38,7 +37,7 @@ namespace CNORXZ
|
|||
virtual SizeT vexec(const UPos& mlast, const DPos& last) const = 0;
|
||||
virtual SizeT vexec() const = 0;
|
||||
|
||||
virtual DPos vrootSteps(PtrId ptrId) const = 0;
|
||||
virtual DPos vrootSteps(const IndexId<0>& id) const = 0;
|
||||
};
|
||||
|
||||
template <class Xpr>
|
||||
|
@ -53,7 +52,7 @@ namespace CNORXZ
|
|||
virtual SizeT vexec(const UPos& mlast, const DPos& last) const override final;
|
||||
virtual SizeT vexec() const override final;
|
||||
|
||||
virtual DPos vrootSteps(PtrId ptrId) const override final;
|
||||
virtual DPos vrootSteps(const IndexId<0>& id) const override final;
|
||||
};
|
||||
|
||||
class DXpr : public ObjHandle<VXprBase>,
|
||||
|
@ -69,10 +68,8 @@ namespace CNORXZ
|
|||
inline SizeT operator()(const UPos& mlast, const PosT& last) const;
|
||||
inline SizeT operator()() const;
|
||||
|
||||
inline DPos rootSteps(PtrId ptrId) const;
|
||||
|
||||
template <SizeT N>
|
||||
inline DPos staticRootSteps(PtrId ptrId) const; // fallback to rootSteps
|
||||
template <SizeT I>
|
||||
inline DPos rootSteps(const IndexId<I>& id) const;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue