Pos_Test Basics works

This commit is contained in:
Christian Zimmermann 2022-09-28 19:09:45 +02:00
parent 321d6cd8fa
commit 872d8f0d4a
27 changed files with 943 additions and 927 deletions

View file

@ -4,7 +4,6 @@
#include "ranges/range_base.h"
#include "ranges/index_base.h"
#include "ranges/xfor/xfor.h"
#include "ranges/xindex.h"
#include "ranges/yrange.h"

View file

@ -85,21 +85,31 @@ namespace CNORXZ
template <class PosT>
class CPosInterface;
// definition: ranges/xfor/pos_type.h
template <class PosT>
class PosInterface;
// definition: ranges/xfor/pos_type.h
// definition: ranges/xfor/vpos_type.h
class VPosBase;
// definition: ranges/xfor/pos_type.h
// definition: ranges/xfor/vpos_type.h
template <class PosT>
class VPos;
// definition: ranges/xfor/pos_type.h
// definition: ranges/xfor/vpos_type.h
template <class PosT>
class VPosRef;
// definition: ranges/xfor/pos_type.h
class UPos;
// definition: ranges/xfor/pos_type.h
template <SizeT N>
class SPos;
// definition: ranges/xfor/pos_type.h
class FPos;
// definition: ranges/xfor/pos_type.h
template <SizeT N, SizeT... Ms>
class SFPos;
// definition: ranges/xfor/pos_type.h
class DPos;
@ -107,7 +117,7 @@ namespace CNORXZ
class DPosRef;
// definition: ranges/xfor/pos_type.h
template <class PosT>
template <class PosT1, class PosT2>
class MPos;
// definition: ranges/xfor/pos_type.h

View file

@ -16,7 +16,6 @@
#include "ranges/rheader.h"
#include "arith.h"
#include "xfor/xfor.h"
#include "type_operations.h"
#include "op_expressions.h"
#include "access.h"

View file

@ -2,7 +2,6 @@
#ifndef __cxz_op_expressions__
#define __cxz_op_expressions__
#include "xfor/xfor.h"
#include "access.h"
namespace CNORXZ

View file

@ -6,7 +6,6 @@
#include "ranges/index_base.h"
#include "ranges/range_base.h"
//#include "xfor/for_type.h"
#include "xfor/xfor.h"
namespace CNORXZ
{

View file

@ -40,7 +40,6 @@ namespace CNORXZ
SizeT dim() const;
RangePtr range() const;
SizeT getStepSize(PtrId iptr) const;
Int getOffset(PtrId iptr) const;
String stringMeta() const;
DType meta() const;

View file

@ -5,7 +5,6 @@
#include "base/base.h"
#include "range_base.h"
#include "xfor/xfor.h"
namespace CNORXZ
{
@ -47,7 +46,6 @@ namespace CNORXZ
auto range() const { return THIS().range(); }
SizeT getStepSize(PtrId iptr) const { return THIS().getStepSize(iptr); }
//SizeT getStepSize(SizeT n) const { return THIS().getStepSize(n); }
Int getOffset(PtrId iptr) const { return THIS().getOffset(iptr); }
String stringMeta() const { return THIS().stringMeta(); }
auto meta() const { return THIS().meta(); }

View file

@ -55,7 +55,6 @@ namespace CNORXZ
SizeT dim();
Sptr<RangeType> range();
SizeT getStepSize(PtrId iptr) const;
Int getOffset(PtrId iptr) const;
String stringMeta() const;
MetaType meta() const;

View file

@ -130,11 +130,6 @@ namespace CNORXZ
return iptr == this->ptrId() ? 1 : 0;
}
template <typename MetaType>
Int UIndex<MetaType>::getOffset(PtrId iptr) const
{
return 0;
}
/*
template <typename MetaType>
template <class Expr>

View file

@ -38,7 +38,6 @@ namespace CNORXZ
SizeT dim() const; // = 1
Sptr<RangeType> range() const;
SizeT getStepSize(PtrId iptr) const;
Int getOffset(PtrId iptr) const;
String stringMeta() const;
const MetaType& meta() const;

View file

@ -7,7 +7,6 @@
#include <tuple>
#include <array>
#include <omp.h>
#include "xfor.h"
namespace CNORXZInternal
{

View file

@ -62,12 +62,12 @@ namespace CNORXZ
constexpr UPos::UPos(SizeT ext) : mExt(ext) {}
inline SizeT UPos::size() const
constexpr SizeT UPos::size() const
{
return 1;
}
inline const SizeT& UPos::val() const
constexpr const SizeT& UPos::val() const
{
return mExt;
}
@ -90,14 +90,6 @@ namespace CNORXZ
return MPos<UPos,PosT>(*this, p1);
}
template <class PosT1, class PosT2, class PosT3>
inline UPos& UPos::set(const CPosInterface<PosT1>& a, const CPosInterface<PosT2>& b,
const CPosInterface<PosT3>& c)
{
(*this) = a + b*c;
return *this;
}
/************
* FPos *
************/
@ -109,26 +101,27 @@ namespace CNORXZ
return 1;
}
inline const SizeT& FPos::val() const
constexpr const SizeT& FPos::val() const
{
return mExt;
}
template <class PosT1>
inline UPos FPos::operator+(const CPosInterface<PosT1>& a) const
constexpr UPos FPos::operator+(const CPosInterface<PosT1>& a) const
{
return UPos(mExt + a.val());
}
inline UPos FPos::operator*(const CPosInterface<PosT1>& a) const
template <class PosT1>
constexpr UPos FPos::operator*(const CPosInterface<PosT1>& a) const
{
return UPos(mExt * mMap[a.val()]);
}
template <class PosT1>
inline auto FPos::extend(const CPosInterface<PosT1>& a) const
constexpr auto FPos::extend(const CPosInterface<PosT1>& a) const
{
return MPos<FPos,PosT>(*this,a);
return MPos<FPos,PosT1>(*this,a);
}
/*************
@ -158,8 +151,8 @@ namespace CNORXZ
template <SizeT N1>
constexpr auto SFPos<N,Ms...>::operator*(const SPos<N1>& a) const
{
static constexpr Array<sizeof...(Ms)> ms({ Ms... });
return SPos<N*std::get<a.val()>(ms)>;
constexpr Arr<SizeT,sizeof...(Ms)> ms({ Ms... });
return SPos<N*std::get<a.val()>(ms)>();
}
template <SizeT N, SizeT... Ms>
@ -171,7 +164,7 @@ namespace CNORXZ
template <SizeT N, SizeT... Ms>
constexpr auto SFPos<N,Ms...>::operator*(const UPos& a) const
{
static constexpr Array<sizeof...(Ms)> ms({ Ms... });
constexpr Arr<SizeT,sizeof...(Ms)> ms({ Ms... });
return UPos(N * ms[a.val()]);
}
@ -188,12 +181,11 @@ namespace CNORXZ
************/
inline DPos::DPos(Uptr<VPosBase>&& a) :
ObjHandle<VPosBase>(std::forward<Uptr<VPosBase>>(a)),
mNextRef(mC->next())
ObjHandle<VPosBase>(std::forward<Uptr<VPosBase>>(a))
{}
template <class PosT>
inline DPos::DPos(const PosT& a) :
inline DPos::DPos(const CPosInterface<PosT>& a) :
ObjHandle<VPosBase>( std::make_unique<PosT>(a) )
{}
@ -202,55 +194,32 @@ namespace CNORXZ
return mC->vsize();
}
inline const SizeT& DPos::val() const
inline SizeT DPos::val() const
{
return mC->vval();
}
inline const DPosRef& DPos::next() const
inline DPosRef DPos::next() const
{
return mNextRef;
}
template <class PosT2>
inline auto DPos::operator+(const MPos<PosT2>& a) const
{
return MPos<PosT2>(val()+a.val(), next()+a.next());
}
inline auto DPos::operator+(const UPos& a) const
{
return UPos(mC->val() + a.val());
}
inline auto DPos::operator+(const DPos& a) const
{
return DPos((*mC) + (*a));
}
inline auto DPos::operator+(const DPosRef& a) const
{
return DPos((*mC) + (*a));
}
inline auto DPos::operator*(SizeT a) const
{
return DPos((*mC)*a);
return DPosRef(mC->vnext());
}
template <class PosT1>
inline DPos DPos::extend(const PosT1& a) const
inline DPos DPos::operator+(const CPosInterface<PosT1>& a) const
{
Uptr<VPosBase> out = mC->vextend()
return DPos(mC->vplus(VPosRef<PosT1>(&a))); // check memory safety!!!
}
template <class PosT1, class PosT2>
inline PosInterface& DPos::set(const CPosInterface<PosT1>& a, const CPosInterface<PosT2>& b, sizeT c)
template <class PosT1>
inline DPos DPos::operator*(const CPosInterface<PosT1>& a) const
{
mC->setVal( a.val() + b.val()*c ) ;
mC->vnext()->set(a.next(),b.next(),c);
return *this;
return DPos(mC->vtimes(VPosRef<PosT1>(&a))); // check memory safety!!!
}
template <class PosT1>
inline DPos DPos::extend(const CPosInterface<PosT1>& a) const
{
return DPos(mC->vextend(a));
}
/***************
@ -258,124 +227,101 @@ namespace CNORXZ
***************/
inline DPosRef::DPosRef(const VPosBase* c) :
mC(c), mNextRef(mC->vnext())
mC(c)
{}
inline const T& DPosRef::operator*() const
{
return *mC;
}
inline const T* DPosRef::operator->() const
{
return mC;
}
inline sizeT DPosRef::size() const
inline SizeT DPosRef::size() const
{
return mC->vsize();
}
inline const SizeT& DPosRef::val() const
inline SizeT DPosRef::val() const
{
return mC->vsize();
return mC->vval();
}
inline const DPosRef& DPosRef::next() const
inline DPosRef DPosRef::next() const
{
return mNextRef;
return DPosRef(mC->vnext());
}
template <class PosT2>
inline auto DPosRef::operator+(const MPos<PosT2>& a) const
template <class PosT1>
inline DPos DPosRef::operator+(const CPosInterface<PosT1>& a) const
{
return MPos<PosT2>(val()+a.val(), next()+a.next());
return DPos(mC->vplus(VPosRef<PosT1>(&a))); // check memory safety!!!
}
inline auto DPosRef::operator+(const UPos& a) const
template <class PosT1>
inline DPos DPosRef::operator*(const CPosInterface<PosT1>& a) const
{
return UPos(val()+a.val());
return DPos(mC->vtimes(VPosRef<PosT1>(&a))); // check memory safety!!!
}
inline auto DPosRef::operator+(const DPos& a) const
template <class PosT1>
inline DPos DPosRef::extend(const CPosInterface<PosT1>& a) const
{
return DPos((*mC)+(*a));
return DPos(mC->vextend(a));
}
inline auto DPosRef::operator+(const DPosRef& a) const
{
return DPos((*mC)+(*a));
}
inline auto DPosRef::operator*(SizeT a) const
{
return DPos((*mC)*a);
}
/************
* MPos *
************/
template <class PosT>
inline MPos<PosT>::MPos(SizeT ext, PosT next) : mExt(ext), mNext(next) {}
template <class PosT>
template <class PosT1>
inline MPos<PosT>::MPos(SizeT y, const PosT1& z) :
mExt(z.val()), mNext(z.val(), z.next()) {}
template <class PosT>
template <class PosT1, class PosT2>
inline MPos<PosT>::MPos(const PosT1& y, const PosT2& z) :
mExt(y.val()), mNext(y.next(), z) {}
constexpr MPos<PosT1,PosT2>::MPos(const CPosInterface<PosT1>& first,
const CPosInterface<PosT2>& next) :
mFirst(first), mNext(next)
{}
template <class PosT>
template <class PosT1>
inline MPos<PosT>::MPos(const MPos<PosT1>& y) :
mExt(y.val()), mNext(y.next()) {}
template <class PosT>
inline const SizeT& MPos<PosT>::val() const
template <class PosT1, class PosT2>
constexpr SizeT MPos<PosT1,PosT2>::size() const
{
return mExt;
return mFirst.size() + mNext.size();
}
template <class PosT>
inline const PosT& MPos<PosT>::next() const
template <class PosT1, class PosT2>
constexpr auto MPos<PosT1,PosT2>::val() const
{
return mFirst.val();
}
template <class PosT1, class PosT2>
constexpr const PosT1& MPos<PosT1,PosT2>::first() const
{
return mFirst;
}
template <class PosT1, class PosT2>
constexpr const PosT2& MPos<PosT1,PosT2>::next() const
{
return mNext;
}
template <class PosT>
inline MPos<PosT> MPos<PosT>::operator+(const MPos<PosT>& in) const
{
return MPos<PosT>(mExt + in.val(), mNext + in.next());
}
template <class PosT>
inline MPos<PosT> MPos<PosT>::operator+(const UPos& in) const
{
return MPos<PosT>(mExt + in.val(), mNext);
}
template <class PosT>
inline MPos<PosT> MPos<PosT>::operator*(SizeT in) const
{
return MPos<PosT>(mExt * in, mNext * in);
}
template <class PosT>
template <class PosT1>
inline auto MPos<PosT>::extend(const PosInterface<PosT1>& y) const
{ return MPos<decltype(mNext.extend(y))>(mExt, mNext.extend(y)); }
template <class PosT>
template <class PosT1, class PosT2>
inline PosInterface& MPos<PosT>::set(const CPosInterface<PosT1>& a,
const CPosInterface<PosT2>& b, sizeT c)
{ return *this = a + b*c; }
//{ mExt = a.val() + b.val()*c ; mNext.set(a.next(),b.next(),c); return *this; }
template <class PosT3, class PosT4>
constexpr auto MPos<PosT1,PosT2>::operator+(const MPos<PosT3,PosT4>& a) const
{
typedef decltype(first()+a.first()) PosT5;
typedef decltype(next()+a.next()) PosT6;
return MPos<PosT5,PosT6>(first()+a.first(), next()+a.next());
}
template <class PosT1, class PosT2>
template <class PosT3>
constexpr auto MPos<PosT1,PosT2>::operator*(const CPosInterface<PosT3>& a) const
{
typedef decltype(first()*a) PosT5;
typedef decltype(next()*a) PosT6;
return MPos<PosT5,PosT6>(first()*a, next()*a);
}
template <class PosT1, class PosT2>
template <class PosT3>
constexpr auto MPos<PosT1,PosT2>::extend(const CPosInterface<PosT3>& p) const
{
return MPos<MPos<PosT1,PosT2>,PosT3>(*this,p);
}
}

View file

@ -27,27 +27,8 @@ namespace CNORXZ
inline auto extend(const CPosInterface<P>& a) const { return THIS().extend(a); }
};
template <class PosT>
class PosInterface : public CPosInterface<PosT>
{
public:
typedef CPosInterface<PosT> PI;
DEFAULT_MEMBERS(PosInterface);
template <class PosT1, class PosT2>
inline PosInterface& set(const CPosInterface<PosT1>& a, const CPosInterface<PosT2>& b,
const CPosInterface<PosT3>& c)
{ return PI::THIS().set(a,b,c); }
template <class PosT1, class PosT2>
inline PosInterface& operator()(const CPosInterface<PosT1>& a, const CPosInterface<PosT2>& b,
const CPosInterface<PosT3>& c)
{ return set(a,b,c); }
};
template <SizeT N>
class SPos : public CPosInterface<SPos>
class SPos : public CPosInterface<SPos<N>>
{
public:
constexpr SPos() = default;
@ -67,7 +48,7 @@ namespace CNORXZ
constexpr auto extend(const CPosInterface<PosT>& a) const;
};
class UPos : public PosInterface<UPos>
class UPos : public CPosInterface<UPos>
{
private:
SizeT mExt = 0;
@ -77,8 +58,8 @@ namespace CNORXZ
constexpr UPos(SizeT ext);
inline SizeT size() const;
inline const SizeT& val() const;
constexpr SizeT size() const;
constexpr const SizeT& val() const;
template <class PosT>
constexpr UPos operator+(const CPosInterface<PosT>& a) const;
@ -89,9 +70,6 @@ namespace CNORXZ
template <class PosT>
constexpr auto extend(const CPosInterface<PosT>& y) const;
template <class PosT1, class PosT2, class PosT3>
inline UPos& set(const CPosInterface<PosT1>& a, const CPosInterface<PosT2>& b,
const CPosInterface<PosT3>& c);
};
class FPos : public CPosInterface<FPos>
@ -106,20 +84,20 @@ namespace CNORXZ
inline FPos(SizeT ext, const SizeT* map);
constexpr SizeT size() const;
inline const SizeT& val() const;
constexpr const SizeT& val() const;
template <class PosT1>
inline UPos operator+(const CPosInterface<PosT1>& a) const;
constexpr UPos operator+(const CPosInterface<PosT1>& a) const;
template <class PosT1>
inline UPos operator*(const CPosInterface<PosT1>& a) const;
constexpr UPos operator*(const CPosInterface<PosT1>& a) const;
template <class PosT1>
inline auto extend(const CPosInterface<PosT1>& a) const;
constexpr auto extend(const CPosInterface<PosT1>& a) const;
};
template <SizeT N, SizeT... Ms>
class SFPos : public CPosInterface<SFPos>
class SFPos : public CPosInterface<SFPos<N,Ms...>>
{
public:
constexpr SFPos() = default;
@ -140,67 +118,54 @@ namespace CNORXZ
};
class DPos : public ObjHandle<VPosBase>,
public PosInterface<DPos>
public CPosInterface<DPos>
{
private:
DPosRef mNextRef;
public:
DEFAULT_MEMBERS(DPos);
inline DPos(Uptr<VPosBase>&& a);
template <class PosT>
inline DPos(const PosT& a);
inline DPos(const CPosInterface<PosT>& a);
inline SizeT size() const;
inline const SizeT& val() const;
inline const DPosRef& next() const;
template <class PosT2>
inline auto operator+(const MPos<PosT2>& a) const;
inline auto operator+(const UPos& a) const;
inline auto operator+(const DPos& a) const;
inline auto operator+(const DPosRef& a) const;
inline auto operator*(SizeT a) const;
inline SizeT val() const;
inline DPosRef next() const;
template <class PosT1>
inline DPos extend(const PosT1& a) const;
inline DPos operator+(const CPosInterface<PosT1>& a) const;
template <class PosT1>
inline DPos operator*(const CPosInterface<PosT1>& a) const;
template <class PosT1>
inline DPos extend(const CPosInterface<PosT1>& a) const;
template <class PosT1, class PosT2>
inline PosInterface& set(const CPosInterface<PosT1>& a,
const CPosInterface<PosT2>& b, sizeT c);
};
class DPosRef : public CPosInterface<DPosRef>
{
private:
DPosRef mNextRef;
const VPosBase* mC;
public:
DEFAULT_MEMBERS(DPosRef);
inline DPosRef(const VPosBase* c);
inline const T& operator*() const;
inline const T* operator->() const;
inline sizeT size() const;
inline const SizeT& val() const;
inline const DPosRef& next() const;
template <class PosT2>
inline auto operator+(const MPos<PosT2>& a) const;
inline auto operator+(const UPos& a) const;
inline auto operator+(const DPos& a) const;
inline auto operator+(const DPosRef& a) const;
inline auto operator*(SizeT a) const;
inline SizeT size() const;
inline SizeT val() const;
inline DPosRef next() const;
template <class PosT1>
inline DPos extend(const PosT1& a) const;
inline DPos operator+(const CPosInterface<PosT1>& a) const;
template <class PosT1>
inline DPos operator*(const CPosInterface<PosT1>& a) const;
template <class PosT1>
inline DPos extend(const CPosInterface<PosT1>& a) const;
};
template <class PosT1, class PosT2>
class MPos : public PosInterface<MPos<PosT1,PosT2>>
class MPos : public CPosInterface<MPos<PosT1,PosT2>>
{
private:
@ -208,27 +173,25 @@ namespace CNORXZ
PosT2 mNext;
public:
//static constexpr SizeT NUM = PosT::SIZE;
//static constexpr SizeT SIZE = NUM + 1;
DEFAULT_MEMBERS(MPos);
constexpr MPos(const CPosInterface<PosT1>& first,
const CPosInterface<PosT2>& next);
inline const SizeT& val() const;
inline const PosT& next() const;
inline auto operator+(const MPos& in) const;
inline auto operator*(SizeT in) const;
template <class PosT3>
inline auto extend(const PosInterface<PosT3>& y) const;
constexpr SizeT size() const;
constexpr auto val() const;
constexpr const PosT1& first() const;
constexpr const PosT2& next() const;
template <class PosT3, class PosT4>
inline PosInterface& set(const CPosInterface<PosT3>& a,
const CPosInterface<PosT4>& b, sizeT c);
constexpr auto operator+(const MPos<PosT3,PosT4>& a) const;
template <class PosT3>
constexpr auto operator*(const CPosInterface<PosT3>& a) const;
template <class PosT3>
constexpr auto extend(const CPosInterface<PosT3>& p) const;
};

View file

@ -11,7 +11,7 @@ namespace CNORXZ
****************/
template <SizeT N>
UPtr<VPosBase> VPosBase::vextend(const SPos<N>& a) const
Uptr<VPosBase> VPosBase::vextend(const SPos<N>& a) const
{
return this->vextend(UPos(N));
}
@ -21,8 +21,8 @@ namespace CNORXZ
************/
template <class PosT>
VPos<PosT>::VPos(const PosInterface<PosT>& a) :
PosT(a.THIS()),
VPos<PosT>::VPos(const CPosInterface<PosT>& a) :
PosT(a.THIS())
{}
template <class PosT>
@ -38,7 +38,7 @@ namespace CNORXZ
}
template <class PosT>
const SizeT& VPos<PosT>::vval() const
SizeT VPos<PosT>::vval() const
{
return PosT::THIS().val();
}
@ -55,12 +55,30 @@ namespace CNORXZ
return nullptr;
}
template <class PosT>
Uptr<VPosBase> VPos<PosT>::vplus(const VPosBase* a) const
{
return std::make_unique<VPos<PosT>>((*this) + DPosRef(a));
}
template <class PosT>
Uptr<VPosBase> VPos<PosT>::vtimes(const VPosBase* a) const
{
return std::make_unique<VPos<PosT>>((*this) * UPos(a->vval()));
}
template <class PosT>
Uptr<VPosBase> VPos<PosT>::vextend(const DPos& a) const
{
return std::make_unique<MPos<PosT,DPos>>(*this,a);
}
template <class PosT>
Uptr<VPosBase> VPos<PosT>::vextend(const DPosRef& a) const
{
return std::make_unique<MPos<PosT,DPosRef>>(*this,a);
}
template <class PosT>
Uptr<VPosBase> VPos<PosT>::vextend(const UPos& a) const
{
@ -79,9 +97,9 @@ namespace CNORXZ
******************/
template <class PosT1, class PosT2>
VPos<MPos<PosT1,PosT2>>::VPos(const PosInterface<MPos<PosT1,PosT2>>& a) :
VPos<MPos<PosT1,PosT2>>::VPos(const CPosInterface<MPos<PosT1,PosT2>>& a) :
MPos<PosT1,PosT2>(a.THIS()),
mFRef(&mFirst), mNRef(&mNext)
mFRef(&MPosT::mFirst), mNRef(&MPosT::mNext)
{}
template <class PosT1, class PosT2>
@ -114,6 +132,18 @@ namespace CNORXZ
return mNRef;
}
template <class PosT1, class PosT2>
Uptr<VPosBase> VPos<MPos<PosT1,PosT2>>::vplus(const VPosBase* a) const
{
return std::make_unique<MPos<PosT1,PosT2>>((*this) + DPosRef(a));
}
template <class PosT1, class PosT2>
Uptr<VPosBase> VPos<MPos<PosT1,PosT2>>::vtimes(const VPosBase* a) const
{
return std::make_unique<MPos<PosT1,PosT2>>((*this) * UPos(a->vval()));
}
template <class PosT1, class PosT2>
Uptr<VPosBase> VPos<MPos<PosT1,PosT2>>::vextend(const DPos& a) const
{
@ -143,8 +173,8 @@ namespace CNORXZ
***************/
template <class PosT>
VPosRef<PosT>::VPosRef(const PosT* c) :
mC(c), mNextRef(&mC->next())
VPosRef<PosT>::VPosRef(const CPosInterface<PosT>* c) :
mC(c)
{}
template <class PosT>
@ -160,29 +190,47 @@ namespace CNORXZ
}
template <class PosT>
const SizeT& VPosRef<PosT>::vval() const
SizeT VPosRef<PosT>::vval() const
{
return mC->val();
}
template <class PosT>
const VPosBase& VPosRef<PosT>::vget() const
const VPosBase* VPosRef<PosT>::vget() const
{
return this;
}
template <class PosT>
const VPosBase& VPosRef<PosT>::vnext() const
const VPosBase* VPosRef<PosT>::vnext() const
{
return nullptr;
}
template <class PosT>
Uptr<VPosBase> VPosRef<PosT>::vplus(const VPosBase* a) const
{
return std::make_unique<VPos<PosT>>((*mC) + DPosRef(a));
}
template <class PosT>
Uptr<VPosBase> VPosRef<PosT>::vtimes(const VPosBase* a) const
{
return std::make_unique<VPos<PosT>>((*mC) * UPos(a->vval()));
}
template <class PosT>
Uptr<VPosBase> VPosRef<PosT>::vextend(const DPos& a) const
{
return std::make_unique<MPos<PosT,DPos>>(*mC,a);
}
template <class PosT>
Uptr<VPosBase> VPosRef<PosT>::vextend(const DPosRef& a) const
{
return std::make_unique<MPos<PosT,DPosRef>>(*mC,a);
}
template <class PosT>
Uptr<VPosBase> VPosRef<PosT>::vextend(const UPos& a) const
{
@ -200,7 +248,7 @@ namespace CNORXZ
*********************/
template <class PosT1, class PosT2>
VPosRef<MPos<PosT1,PosT2>>::VPosRef(const PosT* c) :
VPosRef<MPos<PosT1,PosT2>>::VPosRef(const CPosInterface<MPos<PosT1,PosT2>>* c) :
mC(c), mFRef(&c->get()), mNRef(&c->next())
{}
@ -234,6 +282,18 @@ namespace CNORXZ
return mNRef;
}
template <class PosT1, class PosT2>
Uptr<VPosBase> VPosRef<MPos<PosT1,PosT2>>::vplus(const VPosBase* a) const
{
return std::make_unique<MPos<PosT1,PosT2>>((*mC) + DPosRef(a));
}
template <class PosT1, class PosT2>
Uptr<VPosBase> VPosRef<MPos<PosT1,PosT2>>::vtimes(const VPosBase* a) const
{
return std::make_unique<MPos<PosT1,PosT2>>((*mC) * UPos(a->vval()));
}
template <class PosT1, class PosT2>
Uptr<VPosBase> VPosRef<MPos<PosT1,PosT2>>::vextend(const DPos& a) const
{

View file

@ -13,21 +13,18 @@ namespace CNORXZ
virtual Uptr<VPosBase> copy() const = 0;
virtual SizeT vsize() const = 0;
virtual const SizeT& vval() const = 0;
virtual SizeT vval() const = 0;
virtual const VPosBase* vget() const = 0;
virtual const VPosBase* vnext() const = 0;
virtual Uptr<VPosBase> vplus(const VPosBase* a) const = 0;
virtual Uptr<VPosBase> vtimes(SizeT a) const = 0;
virtual Uptr<VPosBase> vtimes(const VPosBase* a) const = 0;
virtual Uptr<VPosBase> vextend(const DPos& a) const = 0;
virtual Uptr<VPosBase> vextend(const DPosRef& a) const = 0;
virtual Uptr<VPosBase> vextend(const UPos& a) const = 0;
virtual Uptr<VPosBase> vextend(const FPos& a) const = 0;
template <SizeT N>
UPtr<VPosBase> vextend(const SPos<N>& a) const
{
return this->vextend(UPos(N));
}
Uptr<VPosBase> vextend(const SPos<N>& a) const;
};
template <class PosT>
@ -36,13 +33,15 @@ namespace CNORXZ
public:
DEFAULT_MEMBERS(VPos);
VPos(const PosInterface<PosT>& a);
VPos(const CPosInterface<PosT>& a);
virtual Uptr<VPosBase> copy() const override final;
virtual SizeT vsize() const override final;
virtual SizeT vval() const override final;
virtual const VPosBase* vget() const override final;
virtual const VPosBase* vnext() const override final;
virtual Uptr<VPosBase> vplus(const VPosBase* a) const override final;
virtual Uptr<VPosBase> vtimes(const VPosBase* a) const override final;
virtual Uptr<VPosBase> vextend(const DPos& a) const override final;
virtual Uptr<VPosBase> vextend(const DPosRef& a) const override final;
virtual Uptr<VPosBase> vextend(const UPos& a) const override final;
@ -59,13 +58,15 @@ namespace CNORXZ
typedef MPos<PosT1,PosT2> MPosT;
DEFAULT_MEMBERS(VPos);
VPos(const PosInterface<MPos<PosT1,PosT2>>& a);
VPos(const CPosInterface<MPos<PosT1,PosT2>>& a);
virtual Uptr<VPosBase> copy() const override final;
virtual SizeT vsize() const override final;
virtual SizeT vval() const override final;
virtual const VPosBase* vget() const override final;
virtual const VPosBase* vnext() const override final;
virtual Uptr<VPosBase> vplus(const VPosBase* a) const override final;
virtual Uptr<VPosBase> vtimes(const VPosBase* a) const override final;
virtual Uptr<VPosBase> vextend(const DPos& a) const override final;
virtual Uptr<VPosBase> vextend(const DPosRef& a) const override final;
virtual Uptr<VPosBase> vextend(const UPos& a) const override final;
@ -80,13 +81,15 @@ namespace CNORXZ
public:
DEFAULT_MEMBERS(VPosRef);
VPosRef(const PosT* c);
VPosRef(const CPosInterface<PosT>* c);
virtual Uptr<VPosBase> copy() const override final;
virtual SizeT vsize() const override final;
virtual SizeT vval() const override final;
virtual const VPosBase* vget() const override final;
virtual const VPosBase* vnext() const override final;
virtual Uptr<VPosBase> vplus(const VPosBase* a) const override final;
virtual Uptr<VPosBase> vtimes(const VPosBase* a) const override final;
virtual Uptr<VPosBase> vextend(const DPos& a) const override final;
virtual Uptr<VPosBase> vextend(const DPosRef& a) const override final;
virtual Uptr<VPosBase> vextend(const UPos& a) const override final;
@ -105,13 +108,15 @@ namespace CNORXZ
typedef MPos<PosT1,PosT2> MPosT;
DEFAULT_MEMBERS(VPosRef);
VPosRef(const PosT* c);
VPosRef(const CPosInterface<MPos<PosT1,PosT2>>* c);
virtual Uptr<VPosBase> copy() const override final;
virtual SizeT vsize() const override final;
virtual SizeT vval() const override final;
virtual const VPosBase* vget() const override final;
virtual const VPosBase* vnext() const override final;
virtual Uptr<VPosBase> vplus(const VPosBase* a) const override final;
virtual Uptr<VPosBase> vtimes(const VPosBase* a) const override final;
virtual Uptr<VPosBase> vextend(const DPos& a) const override final;
virtual Uptr<VPosBase> vextend(const DPosRef& a) const override final;
virtual Uptr<VPosBase> vextend(const UPos& a) const override final;

View file

@ -0,0 +1,627 @@
#ifndef __cxz_xfor_h__
#define __cxz_xfor_h__
#include <omp.h>
#include "base/base.h"
#include "for_type.h"
#include "for_utils.h"
#include "exttype.h"
namespace CNORXZ
{
// 'HIDDEN FOR' CLASS for nested for loops in contractions a.s.o.
// (NO COUNTING OF MASTER POSITION !!!!!)
template <class Xpr, class PosT>
class ExprInterface
{
public:
DEFAULT_MEMBERS(ExprInterface);
Xpr& THIS() { return static_cast<Xpr&>(*this); }
const Xpr& THIS() const { return static_cast<const Xpr&>(*this); }
//Sptr<Expr> copy() const { THIS().copy(); }
void operator()(SizeT mlast, PosT last) { THIS()(mlast, last); }
void operator()(SizeT mlast = 0) { THIS()(mlast); }
PosT rootSteps(PtrId ptrId = 0) const { return THIS().rootSteps(ptrId); }
PosT extension() const { return THIS().extenrion(); }
};
class VExprBase
{
public:
DEFAULT_MEMBERS(VExprBase);
virtual Uptr<VExprBase> copy() const = 0;
virtual void vexec(SizeT mlast, DPos last) = 0;
virtual void vexec(SizeT mlast) = 0;
virtual DPos vrootSteps(PtrId ptrId) const = 0;
virtual DPos vextension() const = 0;
};
template <class Xpr, class PosT>
class VExpr : public VExprBase, public Xpr
{
public:
typedef ExprInterface<Xpr,PosT> EI;
DEFAULT_MEMBERS(VExpr);
VExpr(const ExprInterface<Xpr,PosT>& a) : Xpr(a.THIS()) {}
virtual Uptr<VExprBase> copy() const override final { return std::make_unique<VExpr>(*this); }
virtual void vexec(SizeT mlast, DPos last) override final { EI::THIS()(mlast,last); }
virtual void vexec(SizeT mlast) override final { EI::THIS()(mlast); }
virtual DPos vrootSteps(PtrId ptrId) const override final { return EI::THIS().rootSteps(ptrId); }
virtual DPos vextension() const override final { return EI::THIS().extension(); }
};
class DExpr : public ObjHandle<VExprBase>,
public ExprInterface<DExpr,DPos>
{
public:
DEFAULT_MEMBERS(DExpr);
inline void operator()(SizeT mlast, DPos last) { mC->vexec(mlast, last); }
inline void operator()(SizeT mlast) { mC->vexec(mlast); }
inline DPos rootSteps(PtrId ptrId) const { return mC->vrootSteps(ptrId); }
inline DPos extension() const { return mC->vextension(); }
};
/*
template <ForType FT = ForType::DEFAULT>
struct PosForward
{
static inline size_t valuex(size_t last, size_t step, size_t pos)
{
return last + pos * step;
}
static inline size_t value(size_t last, size_t max, size_t pos)
{
return last * max + pos;
}
};
template <>
struct PosForward<ForType::HIDDEN>
{
static inline size_t valuex(size_t last, size_t step, size_t pos)
{
return last;
}
static inline size_t value(size_t last, size_t max, size_t pos)
{
return last;
}
};
template <class IndexClass, class Expr>
class SubExpr : public ExpressionBase
{
private:
SubExpr() = default;
const IndexClass* mIndPtr;
PtrId mSIPtr;
size_t mSPos;
size_t mMax;
Expr mExpr;
typedef decltype(mkExt(0).extend(mExpr.rootSteps())) ExtType;
ExtType mExt;
const Vector<SizeT>* mSubSet;
mutable ExtType mRootSteps;
public:
typedef ExpressionBase EB;
static constexpr size_t LAYER = Expr::LAYER + 1;
static constexpr size_t SIZE = Expr::SIZE + 1;
//static constexpr size_t NHLAYER = Expr::NHLAYER + 1;
DEFAULT_MEMBERS_X(SubExpr);
SubExpr(const Sptr<IndexClass>& indPtr,
std::intptr_t siptr,
const vector<size_t>* subset, Expr expr);
SubExpr(const IndexClass* indPtr, std::intptr_t siptr,
const vector<size_t>* subset, Expr expr);
inline void operator()(size_t mlast, DExt last) override final;
inline void operator()(size_t mlast, ExtType last) ;
inline void operator()(size_t mlast = 0) override final;
DExt dRootSteps(std::intptr_t iPtrNum = 0) const override final;
DExt dExtension() const override final;
auto rootSteps(std::intptr_t iPtrNum = 0) const -> ExtType;
auto extension() const -> ExtType;
};
template <ForType FT, size_t LAYER>
struct NHLayer
{
template <class Expr>
static constexpr size_t get()
{
return Expr::NHLAYER + 1;
}
};
template <size_t LAYER>
struct NHLayer<ForType::HIDDEN,LAYER>
{
template <class Expr>
static constexpr size_t get()
{
return 0;
}
};
template <>
struct NHLayer<ForType::DEFAULT,1>
{
template <class Expr>
static constexpr size_t get()
{
return Expr::LAYER;
}
};
template <class IndexClass, class Expr, ForType FT, size_t DIV>
class For : public ExpressionBase
{
private:
For() = default;
typedef typename IndexClass::RangeType RangeType;
const IndexClass* mIndPtr;
size_t mSPos;
size_t mMax;
size_t mStep;
Expr mExpr;
typedef decltype(mExpr.rootSteps()) ExtType;
ExtType mExt;
mutable ExtType mRootSteps;
public:
typedef ExpressionBase EB;
static constexpr size_t LAYER = Expr::LAYER + 1;
static constexpr size_t SIZE = Expr::SIZE;
//static constexpr size_t MAX = RangeType::SIZE / DIV;
//static constexpr size_t NHLAYER = (FT == ForType::HIDDEN) ? 0 : Expr::NHLAYER + 1;
DEFAULT_MEMBERS(For);
For(const Sptr<IndexClass>& indPtr,
size_t step, Expr expr);
For(const IndexClass* indPtr,
size_t step, Expr expr);
inline void operator()(size_t mlast, DExt last) override final;
inline void operator()(size_t mlast, ExtType last) ;
inline void operator()(size_t mlast = 0) override final;
PFor<IndexClass,Expr> parallel() const;
DExt dRootSteps(std::intptr_t iPtrNum = 0) const override final;
DExt dExtension() const override final;
auto rootSteps(std::intptr_t iPtrNum = 0) const -> ExtType;
auto extension() const -> ExtType;
};
class DynamicExpression : public ExpressionBase
{
private:
size_t mThreadId = 0;
Sptr<ExpressionBase> mNext;
DynamicExpression() : mThreadId(omp_get_thread_num()) {}
public:
static constexpr size_t LAYER = 0;
static constexpr size_t SIZE = 0;
static constexpr size_t NHLAYER = 0;
DynamicExpression(const DynamicExpression& in) :
mThreadId(omp_get_thread_num()),
mNext( (static_cast<int>(in.mThreadId) == omp_get_thread_num()) ?
in.mNext : in.mNext->deepCopy()) {}
DynamicExpression(DynamicExpression&& in) :
mThreadId(omp_get_thread_num()),
mNext( (static_cast<int>(in.mThreadId) == omp_get_thread_num()) ?
in.mNext : in.mNext->deepCopy()) {}
DynamicExpression& operator=(const DynamicExpression& in)
{
mThreadId = omp_get_thread_num();
mNext = (static_cast<int>(in.mThreadId) == omp_get_thread_num()) ?
in.mNext : in.mNext->deepCopy();
return *this;
}
DynamicExpression& operator=(DynamicExpression&& in)
{
mThreadId = omp_get_thread_num();
mNext = (static_cast<int>(in.mThreadId) == omp_get_thread_num()) ?
in.mNext : in.mNext->deepCopy();
return *this;
}
DynamicExpression(const Sptr<ExpressionBase>& next) :
mNext(next)
{}
template <class Expr>
DynamicExpression(const ExpressionBase& next) :
mNext(std::make_shared<Expr>(next))
{}
template <class Expr>
DynamicExpression(Expr ex) : mNext( std::make_shared<Expr>(ex) ) {}
virtual Sptr<ExpressionBase> deepCopy() const override final
{
return std::make_shared<DynamicExpression>(*this);
}
inline void operator()(size_t mlast, DExt last) override final;
inline void operator()(size_t mlast, DExtT last) { (*this)(mlast,last.get()); }
inline void operator()(size_t mlast = 0) override final;
inline DExt dRootSteps(std::intptr_t iPtrNum = 0) const override final;
inline DExt dExtension() const override final;
inline DExtT rootSteps(std::intptr_t iPtrNum = 0) const { return DExtT(dRootSteps(iPtrNum)); }
inline DExtT extension() const { return DExtT(dExtension()); }
};
*/
}
/* ========================= *
* --- TEMPLATE CODE --- *
* ========================= */
namespace CNORXZ
{
/*****************
* F o r *
*****************/
/*
template <class IndexClass, class Expr, ForType FT, size_t DIV>
For<IndexClass,Expr,FT,DIV>::For(const Sptr<IndexClass>& indPtr,
size_t step, Expr expr) :
mIndPtr(indPtr.get()), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()), mStep(step),
mExpr(expr), mExt(mExpr.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr )))
{
assert(mMax % DIV == 0);
assert(mIndPtr != nullptr);
}
template <class IndexClass, class Expr, ForType FT, size_t DIV>
For<IndexClass,Expr,FT,DIV>::For(const IndexClass* indPtr,
size_t step, Expr expr) :
mIndPtr(indPtr), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()), mStep(step),
mExpr(expr), mExt(mExpr.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr )))
{
//VCHECK(mMax);
//VCHECK(DIV);
//assert(mMax % DIV == 0);
assert(mIndPtr != nullptr);
}
template <class IndexClass, class Expr, ForType FT, size_t DIV>
inline void For<IndexClass,Expr,FT,DIV>::operator()(size_t mlast, DExt last)
{
operator()(mlast, std::dynamic_pointer_cast<ExtT<ExtType>>(last)->ext());
//operator()(mlast, *reinterpret_cast<ExtType const*>(last.first));
}
template <class IndexClass, class Expr, ForType FT, size_t DIV>
inline void For<IndexClass,Expr,FT,DIV>::operator()(size_t mlast,
ExtType last)
{
typedef typename IndexClass::RangeType RangeType;
for(size_t pos = 0u; pos != ForBound<RangeType::ISSTATIC>::template bound<RangeType::SIZE,DIV>(mMax); ++pos){
const size_t mnpos = PosForward<FT>::valuex(mlast, mStep, pos);
const ExtType npos = last + mExt*pos;
mExpr(mnpos, npos);
}
}
template <class IndexClass, class Expr, ForType FT, size_t DIV>
inline void For<IndexClass,Expr,FT,DIV>::operator()(size_t mlast)
{
typedef typename IndexClass::RangeType RangeType;
ExtType last = rootSteps();
last.zero();
for(size_t pos = 0u; pos != ForBound<RangeType::ISSTATIC>::template bound<RangeType::SIZE,DIV>(mMax); ++pos){
const size_t mnpos = PosForward<FT>::valuex(mlast, mStep, pos);
const ExtType npos = last + mExt*pos;
mExpr(mnpos, npos);
}
}
template <class IndexClass, class Expr, ForType FT, size_t DIV>
auto For<IndexClass,Expr,FT,DIV>::rootSteps(std::intptr_t iPtrNum) const
-> ExtType
{
return mExpr.rootSteps(iPtrNum);
}
template <class IndexClass, class Expr, ForType FT, size_t DIV>
auto For<IndexClass,Expr,FT,DIV>::extension() const
-> ExtType
{
return mExt;
}
template <class IndexClass, class Expr, ForType FT, size_t DIV>
DExt For<IndexClass,Expr,FT,DIV>::dRootSteps(std::intptr_t iPtrNum) const
{
return std::make_shared<ExtT<ExtType>>(rootSteps(iPtrNum));
//mRootSteps = rootSteps(iPtrNum);
//return std::make_pair<size_t const*,size_t>(reinterpret_cast<size_t const*>(&mRootSteps),
// sizeof(ExtType)/sizeof(size_t));
}
template <class IndexClass, class Expr, ForType FT, size_t DIV>
DExt For<IndexClass,Expr,FT,DIV>::dExtension() const
{
return std::make_shared<ExtT<ExtType>>(mExt);
//return std::make_pair<size_t const*,size_t>(reinterpret_cast<size_t const*>(&mExt),
// sizeof(ExtType)/sizeof(size_t));
}
template <class IndexClass, class Expr, ForType FT, size_t DIV>
PFor<IndexClass,Expr,DIV> For<IndexClass,Expr,FT,DIV>::parallel() const
{
static_assert(FT == ForType::DEFAULT, "hidden for not parallelizable");
return PFor<IndexClass,Expr,DIV>(mIndPtr, mStep, mExpr);
}
*/
/******************
* P F o r *
******************/
/*
template <class IndexClass, class Expr, size_t DIV>
PFor<IndexClass,Expr,DIV>::PFor(const Sptr<IndexClass>& indPtr,
size_t step, Expr expr) :
mIndPtr(indPtr.get()), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()), mStep(step),
mExpr(expr), mExt(mExpr.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr )))
{
//assert(mMax % DIV == 0);
assert(mIndPtr != nullptr);
}
template <class IndexClass, class Expr, size_t DIV>
PFor<IndexClass,Expr,DIV>::PFor(const IndexClass* indPtr,
size_t step, Expr expr) :
mIndPtr(indPtr), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()), mStep(step),
mExpr(expr), mExt(mExpr.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr )))
{
assert(mMax % DIV == 0);
assert(mIndPtr != nullptr);
}
template <class IndexClass, class Expr, size_t DIV>
inline void PFor<IndexClass,Expr,DIV>::operator()(size_t mlast, DExt last)
{
operator()(mlast, std::dynamic_pointer_cast<ExtT<ExtType>>(last)->ext());
//operator()(mlast, *reinterpret_cast<ExtType const*>(last.first));
}
template <class IndexClass, class Expr, size_t DIV>
inline void PFor<IndexClass,Expr,DIV>::operator()(size_t mlast,
ExtType last)
{
CHECK;
typedef typename IndexClass::RangeType RangeType;
int pos = 0;
size_t mnpos = 0;
ExtType npos;
#pragma omp parallel shared(mExpr) private(pos,mnpos,npos)
{
auto expr = mExpr;
#pragma omp for nowait
for(pos = 0; pos < static_cast<int>(ForBound<RangeType::ISSTATIC>::template bound<RangeType::SIZE,DIV>(mMax)); pos++){
mnpos = PosForward<ForType::DEFAULT>::valuex(mlast, mStep, pos);
npos = last + mExt*static_cast<size_t>(pos);
expr(mnpos, npos);
}
}
}
template <class IndexClass, class Expr, size_t DIV>
inline void PFor<IndexClass,Expr,DIV>::operator()(size_t mlast)
{
CHECK;
ExtType last = rootSteps();
last.zero();
int pos = 0;
size_t mnpos = 0;
ExtType npos = rootSteps();
npos.zero();
#pragma omp parallel shared(mExpr) private(pos,mnpos,npos)
{
auto expr = mExpr;
#pragma omp for nowait
for(pos = 0; pos < static_cast<int>(ForBound<RangeType::ISSTATIC>::template bound<RangeType::SIZE,DIV>(mMax)); pos++){
mnpos = PosForward<ForType::DEFAULT>::valuex(mlast, mStep, pos);
npos = last + mExt*static_cast<size_t>(pos);
expr(mnpos, npos);
}
}
}
template <class IndexClass, class Expr, size_t DIV>
auto PFor<IndexClass,Expr,DIV>::rootSteps(std::intptr_t iPtrNum) const
-> ExtType
{
return mExpr.rootSteps(iPtrNum);
}
template <class IndexClass, class Expr, size_t DIV>
auto PFor<IndexClass,Expr,DIV>::extension() const
-> ExtType
{
return mExt;
}
template <class IndexClass, class Expr, size_t DIV>
DExt PFor<IndexClass,Expr,DIV>::dRootSteps(std::intptr_t iPtrNum) const
{
return std::make_shared<ExtT<ExtType>>(rootSteps(iPtrNum));
//mRootSteps = rootSteps(iPtrNum);
//return std::make_pair<size_t const*,size_t>(reinterpret_cast<size_t const*>(&mRootSteps),
// sizeof(ExtType)/sizeof(size_t));
}
template <class IndexClass, class Expr, size_t DIV>
DExt PFor<IndexClass,Expr,DIV>::dExtension() const
{
return std::make_shared<ExtT<ExtType>>(mExt);
//return std::make_pair<size_t const*,size_t>(reinterpret_cast<size_t const*>(&mExt),
// sizeof(ExtType)/sizeof(size_t));
}
*/
/****************
* SubExpr *
****************/
/*
template <class IndexClass, class Expr>
SubExpr<IndexClass,Expr>::SubExpr(const Sptr<IndexClass>& indPtr,
std::intptr_t siptr,
const vector<size_t>* subset, Expr expr) :
mIndPtr(indPtr.get()), mSIPtr(siptr), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()),
mExpr(expr),
mExt( mkExt(0).extend( mExpr.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr )) ) ),
mSubSet(subset)
{
assert(mIndPtr != nullptr);
}
template <class IndexClass, class Expr>
SubExpr<IndexClass,Expr>::SubExpr(const IndexClass* indPtr, std::intptr_t siptr,
const vector<size_t>* subset, Expr expr) :
mIndPtr(indPtr), mSIPtr(siptr), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()),
mExpr(expr),
mExt( mkExt(0).extend( mExpr.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr )) ) ),
mSubSet(subset)
{
assert(mIndPtr != nullptr);
}
template <class IndexClass, class Expr>
inline void SubExpr<IndexClass,Expr>::operator()(size_t mlast, DExt last)
{
operator()(mlast, std::dynamic_pointer_cast<ExtT<ExtType>>(last)->ext());
//operator()(mlast, *reinterpret_cast<ExtType const*>(last.first));
}
template <class IndexClass, class Expr>
inline void SubExpr<IndexClass,Expr>::operator()(size_t mlast,
ExtType last)
{
const size_t pos = (*mSubSet)[last.val()];
const size_t mnpos = mlast;
const ExtType npos = last + mExt*pos;
mExpr(mnpos, getX<1>( npos ));
}
template <class IndexClass, class Expr>
inline void SubExpr<IndexClass,Expr>::operator()(size_t mlast)
{
ExtType last = rootSteps();
last.zero();
const size_t pos = (*mSubSet)[last.val()];
const size_t mnpos = mlast;
const ExtType npos = last + mExt*pos;
mExpr(mnpos, getX<1>( npos ));
}
template <class IndexClass, class Expr>
auto SubExpr<IndexClass,Expr>::rootSteps(std::intptr_t iPtrNum) const
-> ExtType
{
return mkExt(iPtrNum == mSIPtr ? 1 : 0).extend(mExpr.rootSteps(iPtrNum));
}
template <class IndexClass, class Expr>
auto SubExpr<IndexClass,Expr>::extension() const
-> ExtType
{
return mExt;
}
template <class IndexClass, class Expr>
DExt SubExpr<IndexClass,Expr>::dRootSteps(std::intptr_t iPtrNum) const
{
return std::make_shared<ExtT<ExtType>>(rootSteps(iPtrNum));
//mRootSteps = rootSteps(iPtrNum);
//return std::make_pair<size_t const*,size_t>(reinterpret_cast<size_t const*>(&mRootSteps),
//sizeof(ExtType)/sizeof(size_t));
}
template <class IndexClass, class Expr>
DExt SubExpr<IndexClass,Expr>::dExtension() const
{
return std::make_shared<ExtT<ExtType>>(mExt);
//return std::make_pair<size_t const*,size_t>(reinterpret_cast<size_t const*>(&mExt),
// sizeof(ExtType)/sizeof(size_t));
}
*/
/***************************
* DynamicExpression *
***************************/
/*
inline void DynamicExpression::operator()(size_t mlast, DExt last)
{
(*mNext)(mlast,last);
}
inline void DynamicExpression::operator()(size_t mlast)
{
(*mNext)(mlast);
}
inline DExt DynamicExpression::dRootSteps(std::intptr_t iPtrNum) const
{
return mNext->dRootSteps(iPtrNum);
}
inline DExt DynamicExpression::dExtension() const
{
return mNext->dExtension();
}
*/
} // namespace CNORXZInternal
#endif

View file

@ -0,0 +1,3 @@
#include "vpos_type.cc.h"
#include "pos_type.cc.h"

View file

@ -1,627 +1,5 @@
#ifndef __cxz_xfor_h__
#define __cxz_xfor_h__
#include "vpos_type.h"
#include "pos_type.h"
#include <omp.h>
#include "base/base.h"
#include "for_type.h"
#include "for_utils.h"
#include "exttype.h"
namespace CNORXZ
{
// 'HIDDEN FOR' CLASS for nested for loops in contractions a.s.o.
// (NO COUNTING OF MASTER POSITION !!!!!)
template <class Xpr, class PosT>
class ExprInterface
{
public:
DEFAULT_MEMBERS(ExprInterface);
Xpr& THIS() { return static_cast<Xpr&>(*this); }
const Xpr& THIS() const { return static_cast<const Xpr&>(*this); }
//Sptr<Expr> copy() const { THIS().copy(); }
void operator()(SizeT mlast, PosT last) { THIS()(mlast, last); }
void operator()(SizeT mlast = 0) { THIS()(mlast); }
PosT rootSteps(PtrId ptrId = 0) const { return THIS().rootSteps(ptrId); }
PosT extension() const { return THIS().extenrion(); }
};
class VExprBase
{
public:
DEFAULT_MEMBERS(VExprBase);
virtual Uptr<VExprBase> copy() const = 0;
virtual void vexec(SizeT mlast, DPos last) = 0;
virtual void vexec(SizeT mlast) = 0;
virtual DPos vrootSteps(PtrId ptrId) const = 0;
virtual DPos vextension() const = 0;
};
template <class Xpr, class PosT>
class VExpr : public VExprBase, public Xpr
{
public:
typedef ExprInterface<Xpr,PosT> EI;
DEFAULT_MEMBERS(VExpr);
VExpr(const ExprInterface<Xpr,PosT>& a) : Xpr(a.THIS()) {}
virtual Uptr<VExprBase> copy() const override final { return std::make_unique<VExpr>(*this); }
virtual void vexec(SizeT mlast, DPos last) override final { EI::THIS()(mlast,last); }
virtual void vexec(SizeT mlast) override final { EI::THIS()(mlast); }
virtual DPos vrootSteps(PtrId ptrId) const override final { return EI::THIS().rootSteps(ptrId); }
virtual DPos vextension() const override final { return EI::THIS().extension(); }
};
class DExpr : public ObjHandle<VExprBase>,
public ExprInterface<DExpr,DPos>
{
public:
DEFAULT_MEMBERS(DExpr);
inline void operator()(SizeT mlast, DPos last) { mC->vexec(mlast, last); }
inline void operator()(SizeT mlast) { mC->vexec(mlast); }
inline DPos rootSteps(PtrId ptrId) const { return mC->vrootSteps(ptrId); }
inline DPos extension() const { return mC->vextension(); }
};
/*
template <ForType FT = ForType::DEFAULT>
struct PosForward
{
static inline size_t valuex(size_t last, size_t step, size_t pos)
{
return last + pos * step;
}
static inline size_t value(size_t last, size_t max, size_t pos)
{
return last * max + pos;
}
};
template <>
struct PosForward<ForType::HIDDEN>
{
static inline size_t valuex(size_t last, size_t step, size_t pos)
{
return last;
}
static inline size_t value(size_t last, size_t max, size_t pos)
{
return last;
}
};
template <class IndexClass, class Expr>
class SubExpr : public ExpressionBase
{
private:
SubExpr() = default;
const IndexClass* mIndPtr;
PtrId mSIPtr;
size_t mSPos;
size_t mMax;
Expr mExpr;
typedef decltype(mkExt(0).extend(mExpr.rootSteps())) ExtType;
ExtType mExt;
const Vector<SizeT>* mSubSet;
mutable ExtType mRootSteps;
public:
typedef ExpressionBase EB;
static constexpr size_t LAYER = Expr::LAYER + 1;
static constexpr size_t SIZE = Expr::SIZE + 1;
//static constexpr size_t NHLAYER = Expr::NHLAYER + 1;
DEFAULT_MEMBERS_X(SubExpr);
SubExpr(const Sptr<IndexClass>& indPtr,
std::intptr_t siptr,
const vector<size_t>* subset, Expr expr);
SubExpr(const IndexClass* indPtr, std::intptr_t siptr,
const vector<size_t>* subset, Expr expr);
inline void operator()(size_t mlast, DExt last) override final;
inline void operator()(size_t mlast, ExtType last) ;
inline void operator()(size_t mlast = 0) override final;
DExt dRootSteps(std::intptr_t iPtrNum = 0) const override final;
DExt dExtension() const override final;
auto rootSteps(std::intptr_t iPtrNum = 0) const -> ExtType;
auto extension() const -> ExtType;
};
template <ForType FT, size_t LAYER>
struct NHLayer
{
template <class Expr>
static constexpr size_t get()
{
return Expr::NHLAYER + 1;
}
};
template <size_t LAYER>
struct NHLayer<ForType::HIDDEN,LAYER>
{
template <class Expr>
static constexpr size_t get()
{
return 0;
}
};
template <>
struct NHLayer<ForType::DEFAULT,1>
{
template <class Expr>
static constexpr size_t get()
{
return Expr::LAYER;
}
};
template <class IndexClass, class Expr, ForType FT, size_t DIV>
class For : public ExpressionBase
{
private:
For() = default;
typedef typename IndexClass::RangeType RangeType;
const IndexClass* mIndPtr;
size_t mSPos;
size_t mMax;
size_t mStep;
Expr mExpr;
typedef decltype(mExpr.rootSteps()) ExtType;
ExtType mExt;
mutable ExtType mRootSteps;
public:
typedef ExpressionBase EB;
static constexpr size_t LAYER = Expr::LAYER + 1;
static constexpr size_t SIZE = Expr::SIZE;
//static constexpr size_t MAX = RangeType::SIZE / DIV;
//static constexpr size_t NHLAYER = (FT == ForType::HIDDEN) ? 0 : Expr::NHLAYER + 1;
DEFAULT_MEMBERS(For);
For(const Sptr<IndexClass>& indPtr,
size_t step, Expr expr);
For(const IndexClass* indPtr,
size_t step, Expr expr);
inline void operator()(size_t mlast, DExt last) override final;
inline void operator()(size_t mlast, ExtType last) ;
inline void operator()(size_t mlast = 0) override final;
PFor<IndexClass,Expr> parallel() const;
DExt dRootSteps(std::intptr_t iPtrNum = 0) const override final;
DExt dExtension() const override final;
auto rootSteps(std::intptr_t iPtrNum = 0) const -> ExtType;
auto extension() const -> ExtType;
};
class DynamicExpression : public ExpressionBase
{
private:
size_t mThreadId = 0;
Sptr<ExpressionBase> mNext;
DynamicExpression() : mThreadId(omp_get_thread_num()) {}
public:
static constexpr size_t LAYER = 0;
static constexpr size_t SIZE = 0;
static constexpr size_t NHLAYER = 0;
DynamicExpression(const DynamicExpression& in) :
mThreadId(omp_get_thread_num()),
mNext( (static_cast<int>(in.mThreadId) == omp_get_thread_num()) ?
in.mNext : in.mNext->deepCopy()) {}
DynamicExpression(DynamicExpression&& in) :
mThreadId(omp_get_thread_num()),
mNext( (static_cast<int>(in.mThreadId) == omp_get_thread_num()) ?
in.mNext : in.mNext->deepCopy()) {}
DynamicExpression& operator=(const DynamicExpression& in)
{
mThreadId = omp_get_thread_num();
mNext = (static_cast<int>(in.mThreadId) == omp_get_thread_num()) ?
in.mNext : in.mNext->deepCopy();
return *this;
}
DynamicExpression& operator=(DynamicExpression&& in)
{
mThreadId = omp_get_thread_num();
mNext = (static_cast<int>(in.mThreadId) == omp_get_thread_num()) ?
in.mNext : in.mNext->deepCopy();
return *this;
}
DynamicExpression(const Sptr<ExpressionBase>& next) :
mNext(next)
{}
template <class Expr>
DynamicExpression(const ExpressionBase& next) :
mNext(std::make_shared<Expr>(next))
{}
template <class Expr>
DynamicExpression(Expr ex) : mNext( std::make_shared<Expr>(ex) ) {}
virtual Sptr<ExpressionBase> deepCopy() const override final
{
return std::make_shared<DynamicExpression>(*this);
}
inline void operator()(size_t mlast, DExt last) override final;
inline void operator()(size_t mlast, DExtT last) { (*this)(mlast,last.get()); }
inline void operator()(size_t mlast = 0) override final;
inline DExt dRootSteps(std::intptr_t iPtrNum = 0) const override final;
inline DExt dExtension() const override final;
inline DExtT rootSteps(std::intptr_t iPtrNum = 0) const { return DExtT(dRootSteps(iPtrNum)); }
inline DExtT extension() const { return DExtT(dExtension()); }
};
*/
}
/* ========================= *
* --- TEMPLATE CODE --- *
* ========================= */
namespace CNORXZ
{
/*****************
* F o r *
*****************/
/*
template <class IndexClass, class Expr, ForType FT, size_t DIV>
For<IndexClass,Expr,FT,DIV>::For(const Sptr<IndexClass>& indPtr,
size_t step, Expr expr) :
mIndPtr(indPtr.get()), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()), mStep(step),
mExpr(expr), mExt(mExpr.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr )))
{
assert(mMax % DIV == 0);
assert(mIndPtr != nullptr);
}
template <class IndexClass, class Expr, ForType FT, size_t DIV>
For<IndexClass,Expr,FT,DIV>::For(const IndexClass* indPtr,
size_t step, Expr expr) :
mIndPtr(indPtr), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()), mStep(step),
mExpr(expr), mExt(mExpr.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr )))
{
//VCHECK(mMax);
//VCHECK(DIV);
//assert(mMax % DIV == 0);
assert(mIndPtr != nullptr);
}
template <class IndexClass, class Expr, ForType FT, size_t DIV>
inline void For<IndexClass,Expr,FT,DIV>::operator()(size_t mlast, DExt last)
{
operator()(mlast, std::dynamic_pointer_cast<ExtT<ExtType>>(last)->ext());
//operator()(mlast, *reinterpret_cast<ExtType const*>(last.first));
}
template <class IndexClass, class Expr, ForType FT, size_t DIV>
inline void For<IndexClass,Expr,FT,DIV>::operator()(size_t mlast,
ExtType last)
{
typedef typename IndexClass::RangeType RangeType;
for(size_t pos = 0u; pos != ForBound<RangeType::ISSTATIC>::template bound<RangeType::SIZE,DIV>(mMax); ++pos){
const size_t mnpos = PosForward<FT>::valuex(mlast, mStep, pos);
const ExtType npos = last + mExt*pos;
mExpr(mnpos, npos);
}
}
template <class IndexClass, class Expr, ForType FT, size_t DIV>
inline void For<IndexClass,Expr,FT,DIV>::operator()(size_t mlast)
{
typedef typename IndexClass::RangeType RangeType;
ExtType last = rootSteps();
last.zero();
for(size_t pos = 0u; pos != ForBound<RangeType::ISSTATIC>::template bound<RangeType::SIZE,DIV>(mMax); ++pos){
const size_t mnpos = PosForward<FT>::valuex(mlast, mStep, pos);
const ExtType npos = last + mExt*pos;
mExpr(mnpos, npos);
}
}
template <class IndexClass, class Expr, ForType FT, size_t DIV>
auto For<IndexClass,Expr,FT,DIV>::rootSteps(std::intptr_t iPtrNum) const
-> ExtType
{
return mExpr.rootSteps(iPtrNum);
}
template <class IndexClass, class Expr, ForType FT, size_t DIV>
auto For<IndexClass,Expr,FT,DIV>::extension() const
-> ExtType
{
return mExt;
}
template <class IndexClass, class Expr, ForType FT, size_t DIV>
DExt For<IndexClass,Expr,FT,DIV>::dRootSteps(std::intptr_t iPtrNum) const
{
return std::make_shared<ExtT<ExtType>>(rootSteps(iPtrNum));
//mRootSteps = rootSteps(iPtrNum);
//return std::make_pair<size_t const*,size_t>(reinterpret_cast<size_t const*>(&mRootSteps),
// sizeof(ExtType)/sizeof(size_t));
}
template <class IndexClass, class Expr, ForType FT, size_t DIV>
DExt For<IndexClass,Expr,FT,DIV>::dExtension() const
{
return std::make_shared<ExtT<ExtType>>(mExt);
//return std::make_pair<size_t const*,size_t>(reinterpret_cast<size_t const*>(&mExt),
// sizeof(ExtType)/sizeof(size_t));
}
template <class IndexClass, class Expr, ForType FT, size_t DIV>
PFor<IndexClass,Expr,DIV> For<IndexClass,Expr,FT,DIV>::parallel() const
{
static_assert(FT == ForType::DEFAULT, "hidden for not parallelizable");
return PFor<IndexClass,Expr,DIV>(mIndPtr, mStep, mExpr);
}
*/
/******************
* P F o r *
******************/
/*
template <class IndexClass, class Expr, size_t DIV>
PFor<IndexClass,Expr,DIV>::PFor(const Sptr<IndexClass>& indPtr,
size_t step, Expr expr) :
mIndPtr(indPtr.get()), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()), mStep(step),
mExpr(expr), mExt(mExpr.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr )))
{
//assert(mMax % DIV == 0);
assert(mIndPtr != nullptr);
}
template <class IndexClass, class Expr, size_t DIV>
PFor<IndexClass,Expr,DIV>::PFor(const IndexClass* indPtr,
size_t step, Expr expr) :
mIndPtr(indPtr), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()), mStep(step),
mExpr(expr), mExt(mExpr.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr )))
{
assert(mMax % DIV == 0);
assert(mIndPtr != nullptr);
}
template <class IndexClass, class Expr, size_t DIV>
inline void PFor<IndexClass,Expr,DIV>::operator()(size_t mlast, DExt last)
{
operator()(mlast, std::dynamic_pointer_cast<ExtT<ExtType>>(last)->ext());
//operator()(mlast, *reinterpret_cast<ExtType const*>(last.first));
}
template <class IndexClass, class Expr, size_t DIV>
inline void PFor<IndexClass,Expr,DIV>::operator()(size_t mlast,
ExtType last)
{
CHECK;
typedef typename IndexClass::RangeType RangeType;
int pos = 0;
size_t mnpos = 0;
ExtType npos;
#pragma omp parallel shared(mExpr) private(pos,mnpos,npos)
{
auto expr = mExpr;
#pragma omp for nowait
for(pos = 0; pos < static_cast<int>(ForBound<RangeType::ISSTATIC>::template bound<RangeType::SIZE,DIV>(mMax)); pos++){
mnpos = PosForward<ForType::DEFAULT>::valuex(mlast, mStep, pos);
npos = last + mExt*static_cast<size_t>(pos);
expr(mnpos, npos);
}
}
}
template <class IndexClass, class Expr, size_t DIV>
inline void PFor<IndexClass,Expr,DIV>::operator()(size_t mlast)
{
CHECK;
ExtType last = rootSteps();
last.zero();
int pos = 0;
size_t mnpos = 0;
ExtType npos = rootSteps();
npos.zero();
#pragma omp parallel shared(mExpr) private(pos,mnpos,npos)
{
auto expr = mExpr;
#pragma omp for nowait
for(pos = 0; pos < static_cast<int>(ForBound<RangeType::ISSTATIC>::template bound<RangeType::SIZE,DIV>(mMax)); pos++){
mnpos = PosForward<ForType::DEFAULT>::valuex(mlast, mStep, pos);
npos = last + mExt*static_cast<size_t>(pos);
expr(mnpos, npos);
}
}
}
template <class IndexClass, class Expr, size_t DIV>
auto PFor<IndexClass,Expr,DIV>::rootSteps(std::intptr_t iPtrNum) const
-> ExtType
{
return mExpr.rootSteps(iPtrNum);
}
template <class IndexClass, class Expr, size_t DIV>
auto PFor<IndexClass,Expr,DIV>::extension() const
-> ExtType
{
return mExt;
}
template <class IndexClass, class Expr, size_t DIV>
DExt PFor<IndexClass,Expr,DIV>::dRootSteps(std::intptr_t iPtrNum) const
{
return std::make_shared<ExtT<ExtType>>(rootSteps(iPtrNum));
//mRootSteps = rootSteps(iPtrNum);
//return std::make_pair<size_t const*,size_t>(reinterpret_cast<size_t const*>(&mRootSteps),
// sizeof(ExtType)/sizeof(size_t));
}
template <class IndexClass, class Expr, size_t DIV>
DExt PFor<IndexClass,Expr,DIV>::dExtension() const
{
return std::make_shared<ExtT<ExtType>>(mExt);
//return std::make_pair<size_t const*,size_t>(reinterpret_cast<size_t const*>(&mExt),
// sizeof(ExtType)/sizeof(size_t));
}
*/
/****************
* SubExpr *
****************/
/*
template <class IndexClass, class Expr>
SubExpr<IndexClass,Expr>::SubExpr(const Sptr<IndexClass>& indPtr,
std::intptr_t siptr,
const vector<size_t>* subset, Expr expr) :
mIndPtr(indPtr.get()), mSIPtr(siptr), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()),
mExpr(expr),
mExt( mkExt(0).extend( mExpr.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr )) ) ),
mSubSet(subset)
{
assert(mIndPtr != nullptr);
}
template <class IndexClass, class Expr>
SubExpr<IndexClass,Expr>::SubExpr(const IndexClass* indPtr, std::intptr_t siptr,
const vector<size_t>* subset, Expr expr) :
mIndPtr(indPtr), mSIPtr(siptr), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()),
mExpr(expr),
mExt( mkExt(0).extend( mExpr.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr )) ) ),
mSubSet(subset)
{
assert(mIndPtr != nullptr);
}
template <class IndexClass, class Expr>
inline void SubExpr<IndexClass,Expr>::operator()(size_t mlast, DExt last)
{
operator()(mlast, std::dynamic_pointer_cast<ExtT<ExtType>>(last)->ext());
//operator()(mlast, *reinterpret_cast<ExtType const*>(last.first));
}
template <class IndexClass, class Expr>
inline void SubExpr<IndexClass,Expr>::operator()(size_t mlast,
ExtType last)
{
const size_t pos = (*mSubSet)[last.val()];
const size_t mnpos = mlast;
const ExtType npos = last + mExt*pos;
mExpr(mnpos, getX<1>( npos ));
}
template <class IndexClass, class Expr>
inline void SubExpr<IndexClass,Expr>::operator()(size_t mlast)
{
ExtType last = rootSteps();
last.zero();
const size_t pos = (*mSubSet)[last.val()];
const size_t mnpos = mlast;
const ExtType npos = last + mExt*pos;
mExpr(mnpos, getX<1>( npos ));
}
template <class IndexClass, class Expr>
auto SubExpr<IndexClass,Expr>::rootSteps(std::intptr_t iPtrNum) const
-> ExtType
{
return mkExt(iPtrNum == mSIPtr ? 1 : 0).extend(mExpr.rootSteps(iPtrNum));
}
template <class IndexClass, class Expr>
auto SubExpr<IndexClass,Expr>::extension() const
-> ExtType
{
return mExt;
}
template <class IndexClass, class Expr>
DExt SubExpr<IndexClass,Expr>::dRootSteps(std::intptr_t iPtrNum) const
{
return std::make_shared<ExtT<ExtType>>(rootSteps(iPtrNum));
//mRootSteps = rootSteps(iPtrNum);
//return std::make_pair<size_t const*,size_t>(reinterpret_cast<size_t const*>(&mRootSteps),
//sizeof(ExtType)/sizeof(size_t));
}
template <class IndexClass, class Expr>
DExt SubExpr<IndexClass,Expr>::dExtension() const
{
return std::make_shared<ExtT<ExtType>>(mExt);
//return std::make_pair<size_t const*,size_t>(reinterpret_cast<size_t const*>(&mExt),
// sizeof(ExtType)/sizeof(size_t));
}
*/
/***************************
* DynamicExpression *
***************************/
/*
inline void DynamicExpression::operator()(size_t mlast, DExt last)
{
(*mNext)(mlast,last);
}
inline void DynamicExpression::operator()(size_t mlast)
{
(*mNext)(mlast);
}
inline DExt DynamicExpression::dRootSteps(std::intptr_t iPtrNum) const
{
return mNext->dRootSteps(iPtrNum);
}
inline DExt DynamicExpression::dExtension() const
{
return mNext->dExtension();
}
*/
} // namespace CNORXZInternal
#endif
#include "xfor.cc.h"

View file

@ -122,12 +122,6 @@ namespace CNORXZ
return mI->getStepSize(iptr);
}
template <class Index, typename Meta>
Int XIndex<Index,Meta>::getOffset(PtrId iptr) const
{
return mI->getOffset(iptr);
}
template <class Index, typename Meta>
String XIndex<Index,Meta>::stringMeta() const
{

View file

@ -33,7 +33,6 @@ namespace CNORXZ
virtual SizeT dim() const = 0;
virtual RangePtr range() const = 0;
virtual SizeT getStepSize(PtrId iptr) const = 0;
virtual Int getOffset(PtrId iptr) const = 0;
virtual String stringMeta() const = 0;
virtual DType meta() const = 0;
@ -82,7 +81,6 @@ namespace CNORXZ
virtual SizeT dim() const override final;
virtual RangePtr range() const override final;
virtual SizeT getStepSize(PtrId iptr) const override final;
virtual Int getOffset(PtrId iptr) const override final;
virtual String stringMeta() const override final;
virtual DType meta() const override final;

View file

@ -6,7 +6,6 @@
#include "range_base.h"
#include "index_base.h"
#include "xindex.h"
#include "xfor/xfor.h"
namespace CNORXZ
{
@ -43,7 +42,6 @@ namespace CNORXZ
SizeT dim() const;
Sptr<YRange> range() const;
SizeT getStepSize(PtrId iptr) const;
Int getOffset(PtrId iptr) const;
String stringMeta() const;
DType meta() const;

View file

@ -88,11 +88,6 @@ namespace CNORXZ
return iptr == this->ptrId() ? 1 : 0;
}
Int CIndex::getOffset(PtrId iptr) const
{
return 0;
}
String CIndex::stringMeta() const
{
return toString(IB::mPos);

View file

@ -121,11 +121,6 @@ namespace CNORXZ
return mI->getStepSize(iptr);
}
Int DIndex::getOffset(PtrId iptr) const
{
return mI->getOffset(iptr);
}
String DIndex::stringMeta() const
{
return mI->stringMeta();

View file

@ -129,13 +129,6 @@ namespace CNORXZ
return 0;
}
Int YIndex::getOffset(PtrId iptr) const
{
assert(0);
// sub inds !!!
return 0;
}
String YIndex::stringMeta() const
{
String out = "[";

View file

@ -12,10 +12,15 @@ add_library(test_lib STATIC ${test_SOURCES})
#target_link_libraries(iutest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz)
#add_test(NAME iutest COMMAND iutest)
add_executable(xfutest xfor_unit_test.cc)
add_dependencies(xfutest cnorxz)
target_link_libraries(xfutest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz test_lib)
add_test(NAME xfutest COMMAND xfutest)
add_executable(rutest range_unit_test.cc)
add_dependencies(rutest cnorxz)
target_link_libraries(rutest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz test_lib)
add_test(NAME rutest COMMAND dautest)
add_test(NAME rutest COMMAND rutest)
#add_executable(autest ranges/anonymous_unit_test.cc)
#add_dependencies(autest cnorxz)

View file

@ -8,7 +8,8 @@
//#include "cnorxz.h"
#include "ranges/ranges.h"
namespace {
namespace
{
using namespace CNORXZ;

View file

@ -0,0 +1,60 @@
#include "gtest/gtest.h"
#include "ranges/xfor/xfor.h"
namespace
{
using namespace CNORXZ;
class Pos_Test : public ::testing::Test
{
protected:
Pos_Test()
{
mUp1 = UPos(7);
mUp2 = UPos(3);
}
UPos mUp1;
UPos mUp2;
SPos<4> mS4p;
SPos<2> mS2p;
};
TEST_F(Pos_Test, Basics)
{
EXPECT_EQ( mUp1.size(), 1 );
EXPECT_EQ( mUp2.size(), 1 );
EXPECT_EQ( mS4p.size(), 1 );
EXPECT_EQ( mS2p.size(), 1 );
EXPECT_EQ( mUp1.val(), 7 );
EXPECT_EQ( mUp2.val(), 3 );
EXPECT_EQ( mS4p.val(), 4 );
EXPECT_EQ( mS2p.val(), 2 );
auto s6p = mS4p + mS2p;
auto s8p = mS4p * mS2p;
auto up3 = mS4p * mUp1;
auto up4 = mUp1 * mS2p;
auto up5 = mS4p + mUp1;
auto up6 = mUp1 + mS2p;
EXPECT_EQ( s6p.size(), 1 );
EXPECT_EQ( s8p.size(), 1 );
EXPECT_EQ( up3.size(), 1 );
EXPECT_EQ( up4.size(), 1 );
EXPECT_EQ( up5.size(), 1 );
EXPECT_EQ( up6.size(), 1 );
EXPECT_EQ( s6p.val(), 6 );
EXPECT_EQ( s8p.val(), 8 );
EXPECT_EQ( up3.val(), 4*7 );
EXPECT_EQ( up4.val(), 7*2 );
EXPECT_EQ( up5.val(), 4+7 );
EXPECT_EQ( up6.val(), 7+2 );
}
}