remove old files + first yr_test (to be extended)

This commit is contained in:
Christian Zimmermann 2022-11-17 01:26:35 +01:00
parent 3e54485b12
commit da4bf39c83
18 changed files with 431 additions and 444 deletions

View file

@ -11,6 +11,7 @@
#include <map> #include <map>
#include <typeinfo> #include <typeinfo>
#include <utility> #include <utility>
#include <numeric>
namespace CNORXZ namespace CNORXZ
{ {
@ -20,6 +21,7 @@ namespace CNORXZ
typedef std::intptr_t PtrId; typedef std::intptr_t PtrId;
typedef int32_t Int; typedef int32_t Int;
typedef int64_t LInt;
typedef uint64_t SizeT; typedef uint64_t SizeT;
typedef double Double; typedef double Double;
typedef Double Real; typedef Double Real;

View file

@ -9,7 +9,7 @@ namespace CNORXZ
template <class Xpr, class F> template <class Xpr, class F>
decltype(auto) CIndex::ifor(const Xpr& xpr, F&& f) const decltype(auto) CIndex::ifor(const Xpr& xpr, F&& f) const
{ {
return For<0,Xpr,F>(this->max(), this->id(), xpr, std::forward<F>(f)); return For<0,Xpr,F>(this->pmax(), this->id(), xpr, std::forward<F>(f));
} }
} }

View file

@ -19,7 +19,7 @@ namespace CNORXZ
CIndex(const RangePtr& range, SizeT pos = 0); CIndex(const RangePtr& range, SizeT pos = 0);
CIndex& operator=(SizeT pos); CIndex& operator=(SizeT lexpos);
CIndex& operator++(); CIndex& operator++();
CIndex& operator--(); CIndex& operator--();
CIndex operator+(Int n) const; CIndex operator+(Int n) const;
@ -27,7 +27,9 @@ namespace CNORXZ
CIndex& operator+=(Int n); CIndex& operator+=(Int n);
CIndex& operator-=(Int n); CIndex& operator-=(Int n);
SizeT max() const; SizeT lex() const;
SizeT pmax() const;
SizeT lmax() const;
IndexId<0> id() const; IndexId<0> id() const;
SizeT operator*() const; SizeT operator*() const;

View file

@ -24,7 +24,7 @@ namespace CNORXZ
template <class Index, typename Meta> template <class Index, typename Meta>
DIndex(const IndexInterface<Index,Meta>& i); DIndex(const IndexInterface<Index,Meta>& i);
DIndex& operator=(SizeT pos); DIndex& operator=(SizeT lexpos);
DIndex& operator++(); DIndex& operator++();
DIndex& operator--(); DIndex& operator--();
DIndex operator+(Int n) const; DIndex operator+(Int n) const;
@ -32,7 +32,9 @@ namespace CNORXZ
DIndex& operator+=(Int n); DIndex& operator+=(Int n);
DIndex& operator-=(Int n); DIndex& operator-=(Int n);
SizeT max() const; SizeT lex() const;
SizeT pmax() const;
SizeT lmax() const;
IndexId<0> id() const; IndexId<0> id() const;
DType operator*() const; DType operator*() const;
@ -48,6 +50,8 @@ namespace CNORXZ
DXpr<SizeT> ifor(const DXpr<SizeT>& xpr, std::function<SizeT(SizeT,SizeT)>&& f) const; DXpr<SizeT> ifor(const DXpr<SizeT>& xpr, std::function<SizeT(SizeT,SizeT)>&& f) const;
const XIndexPtr& xptr() const;
private: private:
XIndexPtr mI; XIndexPtr mI;
}; };

View file

@ -20,17 +20,18 @@ namespace CNORXZ
I& THIS() { return static_cast<I&>(*this); } I& THIS() { return static_cast<I&>(*this); }
const I& THIS() const { return static_cast<const I&>(*this); } const I& THIS() const { return static_cast<const I&>(*this); }
I& operator=(SizeT pos) { return THIS() = pos; }
I& operator++() { return ++THIS(); } I& operator++() { return ++THIS(); }
I& operator--() { return --THIS();} I& operator--() { return --THIS();}
I operator+(Int n) const { return THIS() + n; } I operator+(Int n) const { return THIS() + n; }
I operator-(Int n) const { return THIS() - n; } I operator-(Int n) const { return THIS() - n; }
I& operator+=(Int n) { return THIS() += n; } I& operator+=(Int n) { return THIS() += n; }
I& operator-=(Int n) { return THIS() -= n; } I& operator-=(Int n) { return THIS() -= n; }
Int operator-(const IndexInterface& i) const { return mPos - i.mPos; } Int operator-(const IndexInterface& i) const { return lex() - i.lex(); }
SizeT pos() const; SizeT pos() const; // 'memory' pos
SizeT max() const { return THIS().max(); } SizeT lex() const { return THIS().lex(); } // lexicographic pos
SizeT pmax() const { return THIS().pmax(); } // memory pos max
SizeT lmax() const { return THIS().lmax(); } // lexicographic pos max
PtrId ptrId() const; PtrId ptrId() const;
decltype(auto) id() const { return THIS().id(); } decltype(auto) id() const { return THIS().id(); }

View file

@ -12,12 +12,12 @@ namespace CNORXZ
template <class... Indices> template <class... Indices>
template <SizeT... Is> template <SizeT... Is>
constexpr decltype(auto) MIndex<Indices...>::mkIPack(SizeT pos, Isq<Is...> is) const constexpr decltype(auto) MIndex<Indices...>::mkIPack(Isq<Is...> is) const
{ {
static_assert(sizeof...(Is) == NI, static_assert(sizeof...(Is) == NI,
"sequence size does not match number of indices"); "sequence sioze does not match number of indices");
CXZ_ASSERT( ( (mRange->sub(Is) != nullptr) and ... ), CXZ_ASSERT( ( (mRange->sub(Is) != nullptr) and ... ),
"no subranges available" ); "subranges not available" );
return std::make_tuple( std::make_shared<Indices>( mRange->sub(Is) )... ); return std::make_tuple( std::make_shared<Indices>( mRange->sub(Is) )... );
} }
@ -28,7 +28,7 @@ namespace CNORXZ
return std::make_tuple return std::make_tuple
( iter<Is,NI> ( iter<Is,NI>
// replace UPos by SPos where possible !!! // replace UPos by SPos where possible !!!
( [&](auto i) { return UPos(std::get<i>(ipack)->max()); }, ( [&](auto i) { return UPos(std::get<i>(ipack)->pmax()); },
[&](const auto&... as) { return (as * ...); } )..., [&](const auto&... as) { return (as * ...); } )...,
SPos<1>() ); SPos<1>() );
} }
@ -39,7 +39,7 @@ namespace CNORXZ
{ {
auto& i = std::get<I>(mIPack); auto& i = std::get<I>(mIPack);
if constexpr(I != 0){ if constexpr(I != 0){
if(i->pos() == i->max()-1){ if(i->lex() == i->lmax()-1){
IB::mPos -= std::get<I>(mBlockSizes).val() * i->pos(); IB::mPos -= std::get<I>(mBlockSizes).val() * i->pos();
(*i) = 0; (*i) = 0;
up<I-1>(); up<I-1>();
@ -56,8 +56,8 @@ namespace CNORXZ
{ {
auto& i = std::get<I>(mIPack); auto& i = std::get<I>(mIPack);
if constexpr(I != 0){ if constexpr(I != 0){
if(i->pos() == 0){ if(i->lex() == 0){
(*i) = i->max()-1; (*i) = i->lmax()-1;
IB::mPos += std::get<I>(mBlockSizes).val() * i->pos(); IB::mPos += std::get<I>(mBlockSizes).val() * i->pos();
down<I-1>(); down<I-1>();
return; return;
@ -85,37 +85,46 @@ namespace CNORXZ
template <class... Indices> template <class... Indices>
MIndex<Indices...>::MIndex(const MIndex& i) : MIndex<Indices...>::MIndex(const MIndex& i) :
IndexInterface<MIndex<Indices...>,Tuple<typename Indices::MetaType...>>(i.pos()), IndexInterface<MIndex<Indices...>,Tuple<typename Indices::MetaType...>>(0),
mRange(rangeCast<RangeType>(i.range())), mRange(rangeCast<RangeType>(i.range())),
mIPack(mkIPack(IB::mPos, Isqr<0,NI>{})), mIPack(mkIPack(Isqr<0,NI>{})),
mBlockSizes(mkBlockSizes(mIPack,Isqr<0,NI-1>{})) mBlockSizes(mkBlockSizes(mIPack,Isqr<0,NI-1>{}))
{} {
mPMax = iter<0,NI>( [&](auto i) { return std::get<i>(mIPack)->pmax(); },
[](auto... e) { return (e * ...); });
*this = i.pos();
}
template <class... Indices> template <class... Indices>
MIndex<Indices...>& MIndex<Indices...>::operator=(const MIndex& i) MIndex<Indices...>& MIndex<Indices...>::operator=(const MIndex& i)
{ {
IndexInterface<MIndex<Indices...>,Tuple<typename Indices::MetaType...>>::operator=(i); IndexInterface<MIndex<Indices...>,Tuple<typename Indices::MetaType...>>::operator=(0);
mRange = rangeCast<RangeType>(i.range()); mRange = rangeCast<RangeType>(i.range());
mIPack = mkIPack(IB::mPos, Isqr<0,NI>{}); mIPack = mkIPack(Isqr<0,NI>{});
mBlockSizes = mkBlockSizes(mIPack,Isqr<0,NI-1>{}); mBlockSizes = mkBlockSizes(mIPack,Isqr<0,NI-1>{});
return *this; mPMax = iter<0,NI>( [&](auto i) { return std::get<i>(mIPack)->pmax(); },
[](auto... e) { return (e * ...); });
return *this = i.pos();
} }
template <class... Indices> template <class... Indices>
MIndex<Indices...>::MIndex(const RangePtr& range, SizeT pos) : MIndex<Indices...>::MIndex(const RangePtr& range, SizeT lexpos) :
IndexInterface<MIndex<Indices...>,Tuple<typename Indices::MetaType...>>(0), IndexInterface<MIndex<Indices...>,Tuple<typename Indices::MetaType...>>(0),
mRange(rangeCast<RangeType>(range)), mRange(rangeCast<RangeType>(range)),
mIPack(mkIPack(IB::mPos, Isqr<0,NI>{})), mIPack(mkIPack(Isqr<0,NI>{})),
mBlockSizes(mkBlockSizes(mIPack,Isqr<0,NI-1>{})) mBlockSizes(mkBlockSizes(mIPack,Isqr<0,NI-1>{}))
{ {
(*this) = pos; mPMax = iter<0,NI>( [&](auto i) { return std::get<i>(mIPack)->pmax(); },
[](auto... e) { return (e * ...); });
*this = lexpos;
} }
template <class... Indices> template <class... Indices>
MIndex<Indices...>& MIndex<Indices...>::operator=(SizeT pos) MIndex<Indices...>& MIndex<Indices...>::operator=(SizeT lexpos)
{ {
IB::mPos = pos; // Adapt in GMIndex
iter<0,NI>( [&](auto i) { *std::get<i>(mIPack) = (IB::mPos / std::get<i>(mBlockSizes).val()) % std::get<i>(mIPack)->max(); }, NoF{} ); IB::mPos = lexpos;
iter<0,NI>( [&](auto i) { *std::get<i>(mIPack) = (IB::mPos / std::get<i>(mBlockSizes).val()) % std::get<i>(mIPack)->pmax(); }, NoF{} );
return *this; return *this;
} }
@ -123,8 +132,7 @@ namespace CNORXZ
MIndex<Indices...>& MIndex<Indices...>::operator++() MIndex<Indices...>& MIndex<Indices...>::operator++()
{ {
// End state is defined by high-index being end while all other indices are zero // End state is defined by high-index being end while all other indices are zero
auto& i0 = std::get<0>(mIPack); if(lex() != lmax()){
if(i0->pos() != i0->max()){
up<NI-1>(); up<NI-1>();
} }
return *this; return *this;
@ -133,7 +141,7 @@ namespace CNORXZ
template <class... Indices> template <class... Indices>
MIndex<Indices...>& MIndex<Indices...>::operator--() MIndex<Indices...>& MIndex<Indices...>::operator--()
{ {
if(IB::mPos != 0){ if(lex() != 0){
down<NI-1>(); down<NI-1>();
} }
return *this; return *this;
@ -156,12 +164,12 @@ namespace CNORXZ
template <class... Indices> template <class... Indices>
MIndex<Indices...>& MIndex<Indices...>::operator+=(Int n) MIndex<Indices...>& MIndex<Indices...>::operator+=(Int n)
{ {
if(-n > static_cast<long int>(IB::mPos)){ if(-n > static_cast<long int>(lex())){
(*this) = 0; (*this) = 0;
} }
const SizeT p = IB::mPos + n; const SizeT p = lex() + n;
if(p > max()){ if(p > lmax()){
(*this) = max(); (*this) = lmax();
} }
(*this) = p; (*this) = p;
return *this; return *this;
@ -170,21 +178,33 @@ namespace CNORXZ
template <class... Indices> template <class... Indices>
MIndex<Indices...>& MIndex<Indices...>::operator-=(Int n) MIndex<Indices...>& MIndex<Indices...>::operator-=(Int n)
{ {
if(n > static_cast<long int>(IB::mPos)){ if(n > static_cast<long int>(lex())){
(*this) = 0; (*this) = 0;
} }
const SizeT p = IB::mPos + n; const SizeT p = lex() + n;
if(p > max()){ if(p > lmax()){
(*this) = max(); (*this) = lmax();
} }
(*this) = p; (*this) = p;
return *this; return *this;
} }
template <class... Indices> template <class... Indices>
SizeT MIndex<Indices...>::max() const SizeT MIndex<Indices...>::lex() const
{ {
return mRange->size(); return IB::mPos;
}
template <class... Indices>
SizeT MIndex<Indices...>::pmax() const
{
return mPMax;
}
template <class... Indices>
SizeT MIndex<Indices...>::lmax() const
{
return mPMax;
} }
template <class... Indices> template <class... Indices>

View file

@ -27,12 +27,13 @@ namespace CNORXZ
// NO DEFAULT HERE !!! // NO DEFAULT HERE !!!
// ( have to assign sub-indices (ptr!) correctly ) // ( have to assign sub-indices (ptr!) correctly )
MIndex() = default; MIndex() = default;
MIndex(const MIndex& i);
MIndex& operator=(const MIndex& i);
MIndex(MIndex&& i) = default; MIndex(MIndex&& i) = default;
MIndex& operator=(MIndex&& i) = default; MIndex& operator=(MIndex&& i) = default;
MIndex(const RangePtr& range, SizeT pos = 0); MIndex(const MIndex& i);
MIndex& operator=(const MIndex& i);
MIndex(const RangePtr& range, SizeT lexpos = 0);
MIndex& operator=(SizeT pos); MIndex& operator=(SizeT pos);
MIndex& operator++(); MIndex& operator++();
@ -42,7 +43,9 @@ namespace CNORXZ
MIndex& operator+=(Int n); MIndex& operator+=(Int n);
MIndex& operator-=(Int n); MIndex& operator-=(Int n);
SizeT max() const; SizeT lex() const;
SizeT pmax() const;
SizeT lmax() const;
IndexId<0> id() const; IndexId<0> id() const;
MetaType operator*() const; MetaType operator*() const;
@ -71,7 +74,7 @@ namespace CNORXZ
static constexpr decltype(auto) mkBlockSizes(const IndexPack& ipack, Isq<Is...> is); static constexpr decltype(auto) mkBlockSizes(const IndexPack& ipack, Isq<Is...> is);
template <SizeT... Is> template <SizeT... Is>
constexpr decltype(auto) mkIPack(SizeT pos, Isq<Is...> is) const; constexpr decltype(auto) mkIPack(Isq<Is...> is) const;
template <SizeT I> template <SizeT I>
inline void up(); inline void up();
@ -86,6 +89,7 @@ namespace CNORXZ
IndexPack mIPack; IndexPack mIPack;
typedef RemoveRef<decltype(mkBlockSizes(mIPack,Isqr<0,NI-1>{}))> BlockTuple; typedef RemoveRef<decltype(mkBlockSizes(mIPack,Isqr<0,NI-1>{}))> BlockTuple;
BlockTuple mBlockSizes; BlockTuple mBlockSizes;
SizeT mPMax = 0; // = LMax here, add new variable in GMIndex!
}; };
// modified blockSizes; to be used for Slices; can be created from MIndices // modified blockSizes; to be used for Slices; can be created from MIndices
@ -101,7 +105,7 @@ namespace CNORXZ
constexpr decltype(auto) ifor(const Xpr& xpr, F&& f) const; constexpr decltype(auto) ifor(const Xpr& xpr, F&& f) const;
private: private:
BlockType mBlockSizes; BlockType mLexBlockSizes;
template <SizeT... Is> template <SizeT... Is>
constexpr decltype(auto) mkPos(Isq<Is...> is) const; constexpr decltype(auto) mkPos(Isq<Is...> is) const;

View file

@ -1,285 +0,0 @@
#ifndef __cxz_range_helper_h__
#define __cxz_range_helper_h__
namespace CNORXZ
{
namespace RangeHelper
{
template <size_t I, class... Indices>
int ppx(std::tuple<std::shared_ptr<Indices>...>& ip,
std::array<size_t,sizeof...(Indices)+1>& bs,
std::intptr_t idxPtrNum)
{
auto& siPtr = std::get<I>(ip);
if(reinterpret_cast<std::intptr_t>(siPtr.get()) == idxPtrNum){
if constexpr(I != 0){
return ppx<I-1>(ip, bs, idxPtrNum);
}
else {
return std::get<0>(bs);
}
}
else {
const int tmp = siPtr->pp(idxPtrNum);
if constexpr(I != 0){
if(siPtr->pos() == siPtr->max()){
(*siPtr) = 0;
return ppx<I-1>(ip, bs, idxPtrNum) - siPtr->max() + 1;
}
}
return tmp * std::get<I+1>(bs);
}
}
template <size_t I, class... Indices>
int mmx(std::tuple<std::shared_ptr<Indices>...>& ip,
std::array<size_t,sizeof...(Indices)+1>& bs,
std::intptr_t idxPtrNum)
{
auto& siPtr = std::get<I>(ip);
if(reinterpret_cast<std::intptr_t>(siPtr.get()) == idxPtrNum){
if constexpr(I != 0){
return mmx<I-1>(ip, bs, idxPtrNum);
}
else {
return std::get<0>(bs);
}
}
else {
const int tmp = siPtr->mm(idxPtrNum);
if constexpr(I != 0){
if(siPtr->pos() == siPtr->max()){
(*siPtr) = siPtr->max() - 1;
return mmx<I-1>(ip, bs, idxPtrNum) - siPtr->max() + 1;
}
}
return tmp * std::get<I+1>(bs);
}
}
template <size_t N, class... Indices>
inline size_t makePos(const std::tuple<std::shared_ptr<Indices>...>& iPtrTup,
const std::array<size_t,sizeof...(Indices)+1>& blockSize)
{
if constexpr(N != 0){
return makePos<N-1>(iPtrTup, blockSize) +
std::get<N>(iPtrTup)->pos() * std::get<N+1>(blockSize);
}
else {
return std::get<0>(iPtrTup)->pos() * std::get<1>(blockSize);
}
}
template <class Range>
inline void resolveSetRange(std::shared_ptr<Range>& rp, const vector<std::shared_ptr<RangeBase> >& orig,
size_t origpos, size_t size)
{
assert(size == 1);
rp = std::dynamic_pointer_cast<Range>( orig[origpos] ); // catch bad cast here!!
}
template <class Range>
inline void setRangeToVec(vector<std::shared_ptr<RangeBase> >& v,
std::shared_ptr<Range> r)
{
v.insert(v.begin(), r);
}
template <size_t N, class IndexPack>
void setIndexPack(IndexPack& iPack, size_t pos)
{
auto& i = *std::get<N>(iPack).get();
const size_t ownPos = pos % i.max();
i = ownPos;
if constexpr(N != 0){
setIndexPack<N-1>(iPack, (pos - ownPos) / i.max() );
}
}
template <size_t N, class... Ranges>
inline size_t getMeta(const std::tuple<std::shared_ptr<Ranges>...>& space,
const std::tuple<typename Ranges::IndexType::MetaType...>& meta)
{
if constexpr(N != 0){
return getMeta<N-1>(space,meta) * std::get<N>(space)->size() +
std::get<N>(space)->getMeta(std::get<N>(meta));
}
else {
return std::get<0>(space)->getMeta(std::get<0>(meta));
}
}
template <size_t N, class... Ranges>
inline void getTypeNum(vector<size_t>& res, const std::tuple<std::shared_ptr<Ranges>...>& stp)
{
auto& r = *std::get<N>(stp);
auto tn = r.typeNum();
res.insert(res.begin(), tn.begin(), tn.end());
if constexpr(N != 0){
getTypeNum<N-1>(res, stp);
}
}
template <size_t N, class IndexPack, class BlockArray, class Exprs>
auto mkFor(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs)
{
constexpr size_t S = std::tuple_size<IndexPack>::value;
if constexpr(N < S-1){
return std::get<N>(ipack)
->ifor( step*std::get<N+1>(ba), mkFor<N+1>(step, ipack, ba, exs) );
}
else {
return std::get<N>(ipack)->ifor( step*std::get<N+1>(ba), exs);
}
}
template <size_t N, class IndexPack, class BlockArray, class Exprs>
auto mkForh(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs)
{
constexpr size_t S = std::tuple_size<IndexPack>::value;
if constexpr(N < S-1){
return std::get<N>(ipack)
->iforh( step*std::get<N+1>(ba), mkForh<N+1>(step, ipack, ba, exs) );
}
else {
return std::get<N>(ipack)->iforh( step*std::get<N+1>(ba), exs);
}
}
template <size_t N, class IndexPack, class BlockArray, class Exprs>
auto mkPFor(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs)
{
constexpr size_t S = std::tuple_size<IndexPack>::value;
if constexpr(N < S-1){
return std::get<N>(ipack)
->pifor( step*std::get<N+1>(ba), mkFor<N+1>(step, ipack, ba, exs) );
// mkFor is correct here, because we want to multithread only the FIRST index!!
}
else {
return std::get<N>(ipack)->pifor( step*std::get<N+1>(ba), exs);
}
}
template <size_t N, class RangeTuple, typename... SIZET>
inline void resolveRangeType(const vector<std::shared_ptr<RangeBase> >& orig,
RangeTuple& rtp, size_t off, size_t size, SIZET... sizes)
{
constexpr size_t tps = std::tuple_size<RangeTuple>::value;
::CNORXZ::RangeHelper::resolveSetRange(std::get<N>(rtp), orig, off, size);
if constexpr(N < tps-1){
resolveRangeType<N+1>(orig, rtp, off+size, sizes...);
}
}
template <size_t N, class RangeTuple>
inline void resolveRangeType(const vector<std::shared_ptr<RangeBase> >& orig,
RangeTuple& rtp, size_t off, size_t size)
{
constexpr size_t tps = std::tuple_size<RangeTuple>::value;
::CNORXZ::RangeHelper::resolveSetRange(std::get<N>(rtp), orig, off, size);
}
template <size_t N, class MetaType, class... Ranges>
inline size_t getCMeta(MetaType* xtarget, size_t pos,
const std::tuple<std::shared_ptr<Ranges>...>& stp, size_t off)
{
//constexpr size_t NN = sizeof...(Ranges);
auto& r = *std::get<N>(stp);
const size_t ownPos = pos % r.size();
const size_t s = r.cmetaSize();
off -= s;
r.cmeta(reinterpret_cast<char*>(&std::get<N>(*xtarget)), ownPos);
if constexpr(N != 0){
return s + getCMeta<N-1>(xtarget, (pos - ownPos) / r.size(), stp, off);
}
else {
assert(off == 0);
return s;
}
}
template <size_t N, class... Ranges>
inline size_t getCMetaSize(const std::tuple<std::shared_ptr<Ranges>...>& stp)
{
auto& r = *std::get<N>(stp);
if constexpr(N < sizeof...(Ranges)-1){
return r.cmetaSize() + getCMetaSize<N+1>(stp);
}
else {
return r.cmetaSize();
}
}
template <size_t N, class MIndex>
inline std::string getStringMeta(const MIndex& mi)
{
if constexpr(N < MIndex::sDim()-1){
return mi.template getPtr<N>()->stringMeta() + "," + getStringMeta<N+1>(mi);
}
else {
return mi.template getPtr<N>()->stringMeta();
}
}
template <class Index>
inline size_t getStepSize(const Index& ii, std::intptr_t j);
template <size_t N, class Index>
inline void getStepSizeX(const Index& ii, std::intptr_t j, size_t& ss, size_t& sx)
{
const auto& ni = ii.template get<N>();
const size_t max = ni.max();
const size_t tmp = getStepSize(ni, j);
ss += tmp * ii.template getBlockSize<N+1>();
sx *= max;
if constexpr(N != 0){
getStepSizeX<N-1>(ii, j, ss, sx);
}
}
template <class Index>
inline size_t getStepSize(const Index& ii, std::intptr_t j)
{
constexpr IndexType IT = Index::sType();
if constexpr(IT == IndexType::SINGLE){
const std::intptr_t ip = reinterpret_cast<std::intptr_t>(&ii);
return ip == j ? 1 : 0;
}
else {
size_t ss = 0;
size_t sx = 1;
constexpr size_t DIM = Index::sDim();
getStepSizeX<DIM-1>(ii, j, ss, sx);
return ss;
}
}
template <size_t N, size_t SIZE, class Range, class... Ranges>
inline bool compareSpaceTypes(const vector<std::shared_ptr<RangeBase> >& rbvec)
{
if constexpr(N != 0){
return rbvec[SIZE-N-1]->spaceType() == Range::STYPE and compareSpaceTypes<N-1,SIZE,Ranges...>(rbvec);
}
else {
return rbvec[SIZE-N-1]->spaceType() == Range::STYPE;
}
}
template <size_t N, class... Ranges>
inline void setSpace(const vector<std::shared_ptr<RangeBase> >& rbvec,
std::tuple<std::shared_ptr<Ranges>...>& stp)
{
typedef typename std::remove_reference<decltype(*std::get<N>( stp ))>::type RType;
std::get<N>( stp ) = std::dynamic_pointer_cast<RType>( rbvec[N] );
if constexpr(N != 0){
setSpace<N-1>(rbvec, stp);
}
}
} // namespace RangeHelper
} // namespace CNORXZ
#endif

View file

@ -22,9 +22,9 @@ namespace CNORXZ
{} {}
template <typename MetaType> template <typename MetaType>
UIndex<MetaType>& UIndex<MetaType>::operator=(size_t pos) UIndex<MetaType>& UIndex<MetaType>::operator=(size_t lexpos)
{ {
IB::mPos = pos; IB::mPos = lexpos;
return *this; return *this;
} }
@ -69,7 +69,19 @@ namespace CNORXZ
} }
template <typename MetaType> template <typename MetaType>
SizeT UIndex<MetaType>::max() const SizeT UIndex<MetaType>::lex() const
{
return IB::mPos;
}
template <typename MetaType>
SizeT UIndex<MetaType>::pmax() const
{
return mRangePtr->size();
}
template <typename MetaType>
SizeT UIndex<MetaType>::lmax() const
{ {
return mRangePtr->size(); return mRangePtr->size();
} }
@ -128,7 +140,7 @@ namespace CNORXZ
template <class Xpr, class F> template <class Xpr, class F>
decltype(auto) UIndex<MetaType>::ifor(const Xpr& xpr, F&& f) const decltype(auto) UIndex<MetaType>::ifor(const Xpr& xpr, F&& f) const
{ {
return For<0,Xpr,F>(this->max(), this->id(), xpr, std::forward<F>(f)); return For<0,Xpr,F>(this->pmax(), this->id(), xpr, std::forward<F>(f));
} }
/********************** /**********************

View file

@ -22,7 +22,7 @@ namespace CNORXZ
UIndex(const RangePtr& range, SizeT pos = 0); UIndex(const RangePtr& range, SizeT pos = 0);
UIndex& operator=(SizeT pos); UIndex& operator=(SizeT lexpos);
UIndex& operator++(); UIndex& operator++();
UIndex& operator--(); UIndex& operator--();
UIndex operator+(Int n) const; UIndex operator+(Int n) const;
@ -30,7 +30,9 @@ namespace CNORXZ
UIndex& operator+=(Int n); UIndex& operator+=(Int n);
UIndex& operator-=(Int n); UIndex& operator-=(Int n);
SizeT max() const; SizeT lex() const;
SizeT pmax() const;
SizeT lmax() const;
IndexId<0> id() const; IndexId<0> id() const;
const MetaT& operator*() const; const MetaT& operator*() const;

View file

@ -32,9 +32,10 @@ namespace CNORXZ
} }
template <class Index, typename Meta> template <class Index, typename Meta>
XIndex<Index,Meta>& XIndex<Index,Meta>::operator=(SizeT pos) XIndex<Index,Meta>& XIndex<Index,Meta>::operator=(SizeT lexpos)
{ {
*mI = pos; mI->THIS() = lexpos;
assert(mI->lex() == lexpos);
return *this; return *this;
} }
@ -79,9 +80,21 @@ namespace CNORXZ
} }
template <class Index, typename Meta> template <class Index, typename Meta>
SizeT XIndex<Index,Meta>::max() const SizeT XIndex<Index,Meta>::lex() const
{ {
return mI->max(); return mI->lex();
}
template <class Index, typename Meta>
SizeT XIndex<Index,Meta>::pmax() const
{
return mI->pmax();
}
template <class Index, typename Meta>
SizeT XIndex<Index,Meta>::lmax() const
{
return mI->lmax();
} }
template <class Index, typename Meta> template <class Index, typename Meta>
@ -136,9 +149,9 @@ namespace CNORXZ
template <class Index, typename Meta> template <class Index, typename Meta>
DXpr<SizeT> XIndex<Index,Meta>::ifor(const DXpr<SizeT>& xpr, DXpr<SizeT> XIndex<Index,Meta>::ifor(const DXpr<SizeT>& xpr,
std::function<SizeT(SizeT,SizeT)>&& f) const const std::function<SizeT(SizeT,SizeT)>& f) const
{ {
return DXpr<SizeT>(mI->ifor(xpr, std::forward<std::function<SizeT(SizeT,SizeT)>>(f))); return DXpr<SizeT>(mI->ifor(xpr, f));
} }
} }

View file

@ -17,7 +17,7 @@ namespace CNORXZ
virtual XIndexPtr copy() const = 0; virtual XIndexPtr copy() const = 0;
virtual SizeT pos() const = 0; virtual SizeT pos() const = 0;
virtual XIndexBase& operator=(SizeT pos) = 0; virtual XIndexBase& operator=(SizeT lexpos) = 0;
virtual XIndexBase& operator++() = 0; virtual XIndexBase& operator++() = 0;
virtual XIndexBase& operator--() = 0; virtual XIndexBase& operator--() = 0;
virtual XIndexPtr operator+(Int n) const = 0; virtual XIndexPtr operator+(Int n) const = 0;
@ -25,7 +25,9 @@ namespace CNORXZ
virtual XIndexBase& operator+=(Int n) = 0; virtual XIndexBase& operator+=(Int n) = 0;
virtual XIndexBase& operator-=(Int n) = 0; virtual XIndexBase& operator-=(Int n) = 0;
virtual SizeT max() const = 0; virtual SizeT lex() const = 0;
virtual SizeT pmax() const = 0;
virtual SizeT lmax() const = 0;
virtual IndexId<0> id() const = 0; virtual IndexId<0> id() const = 0;
virtual DType operator*() const = 0; virtual DType operator*() const = 0;
@ -39,7 +41,7 @@ namespace CNORXZ
virtual XIndexBase& at(const DType& meta) = 0; virtual XIndexBase& at(const DType& meta) = 0;
virtual DXpr<SizeT> ifor(const DXpr<SizeT>& xpr, virtual DXpr<SizeT> ifor(const DXpr<SizeT>& xpr,
std::function<SizeT(SizeT,SizeT)>&& f) const = 0; const std::function<SizeT(SizeT,SizeT)>& f) const = 0;
}; };
//Sptr<XIndexBase>& operator++(Sptr<XIndexBase>& i); //Sptr<XIndexBase>& operator++(Sptr<XIndexBase>& i);
@ -63,7 +65,7 @@ namespace CNORXZ
virtual XIndexPtr copy() const override final; virtual XIndexPtr copy() const override final;
virtual SizeT pos() const override final; virtual SizeT pos() const override final;
virtual XIndex& operator=(SizeT pos) override final; virtual XIndex& operator=(SizeT lexpos) override final;
virtual XIndex& operator++() override final; virtual XIndex& operator++() override final;
virtual XIndex& operator--() override final; virtual XIndex& operator--() override final;
virtual XIndexPtr operator+(Int n) const override final; virtual XIndexPtr operator+(Int n) const override final;
@ -71,7 +73,9 @@ namespace CNORXZ
virtual XIndex& operator+=(Int n) override final; virtual XIndex& operator+=(Int n) override final;
virtual XIndex& operator-=(Int n) override final; virtual XIndex& operator-=(Int n) override final;
virtual SizeT max() const override final; virtual SizeT lex() const override final;
virtual SizeT pmax() const override final;
virtual SizeT lmax() const override final;
virtual IndexId<0> id() const override final; virtual IndexId<0> id() const override final;
virtual DType operator*() const override final; virtual DType operator*() const override final;
@ -85,7 +89,7 @@ namespace CNORXZ
virtual XIndexBase& at(const DType& meta) override final; virtual XIndexBase& at(const DType& meta) override final;
virtual DXpr<SizeT> ifor(const DXpr<SizeT>& xpr, virtual DXpr<SizeT> ifor(const DXpr<SizeT>& xpr,
std::function<SizeT(SizeT,SizeT)>&& f) const override final; const std::function<SizeT(SizeT,SizeT)>& f) const override final;
private: private:
IndexPtr<Index,Meta> mI; IndexPtr<Index,Meta> mI;

View file

@ -10,10 +10,6 @@
namespace CNORXZ namespace CNORXZ
{ {
// YRange!!!!
// Future DynamicIndex
//class YIndex : public XIndexBase
class YIndex : public IndexInterface<YIndex,DType> class YIndex : public IndexInterface<YIndex,DType>
{ {
public: public:
@ -21,21 +17,26 @@ namespace CNORXZ
typedef YRange RangeType; typedef YRange RangeType;
typedef DType MetaType; typedef DType MetaType;
DEFAULT_MEMBERS(YIndex); YIndex() = default;
YIndex(const RangePtr& range, SizeT pos = 0); YIndex(YIndex&& i) = default;
YIndex(const RangePtr& range, const Vector<XIndexPtr>& is, SizeT pos = 0); YIndex& operator=(YIndex&& i) = default;
YIndex& sync(); // remove!!! YIndex(const YIndex& i);
YIndex& operator=(const YIndex& i);
YIndex& operator=(SizeT pos); YIndex(const RangePtr& range, SizeT lexpos);
YIndex& operator=(SizeT lexpos);
YIndex& operator++(); YIndex& operator++();
YIndex& operator--(); YIndex& operator--();
YIndex operator+(Int n) const; YIndex operator+(Int n) const; // equivalent to applying n times ++
YIndex operator-(Int n) const; YIndex operator-(Int n) const;
YIndex& operator+=(Int n); YIndex& operator+=(Int n);
YIndex& operator-=(Int n); YIndex& operator-=(Int n);
SizeT max() const; SizeT lex() const;
SizeT pmax() const;
SizeT lmax() const;
IndexId<0> id() const; IndexId<0> id() const;
DType operator*() const; DType operator*() const;
@ -48,14 +49,28 @@ namespace CNORXZ
DType meta() const; DType meta() const;
YIndex& at(const DType& meta); YIndex& at(const DType& meta);
DXpr<SizeT> ifor(const DXpr<SizeT>& xpr, std::function<SizeT(SizeT,SizeT)>&& f) const; DXpr<SizeT> ifor(const DXpr<SizeT>& xpr, const std::function<SizeT(SizeT,SizeT)>& f) const;
private: private:
inline Vector<SizeT> mkBlockSizes() const;
inline Vector<SizeT> mkLexBlockSizes() const;
inline Vector<XIndexPtr> mkIndices() const;
inline void up(SizeT i);
inline void down(SizeT i);
inline decltype(auto) mkIFor(SizeT i, const DXpr<SizeT>& xpr,
const std::function<SizeT(SizeT,SizeT)>& f) const;
Sptr<YRange> mRangePtr; inline SizeT mkPMax() const;
inline SizeT mkLMax() const;
SizeT mLPos = 0;
Sptr<YRange> mRange;
Vector<XIndexPtr> mIs; Vector<XIndexPtr> mIs;
Vector<SizeT> mBlockSizes; // dim() elements only!!! Vector<SizeT> mBlockSizes; // dim() elements only!!!
Vector<SizeT> mLexBlockSizes; // dim() elements only!!!
SizeT mLex = 0;
SizeT mPMax = 0;
SizeT mLMax = 0;
}; };
class YRangeFactory : public RangeFactoryBase class YRangeFactory : public RangeFactoryBase
@ -82,6 +97,7 @@ namespace CNORXZ
friend YRangeFactory; friend YRangeFactory;
virtual RangePtr sub(SizeT i) const override final;
virtual SizeT size() const override final; virtual SizeT size() const override final;
virtual SizeT dim() const override final; virtual SizeT dim() const override final;
virtual String stringMeta(SizeT pos) const override final; virtual String stringMeta(SizeT pos) const override final;

View file

@ -11,9 +11,9 @@ namespace CNORXZ
IndexInterface<CIndex,SizeT>(pos), mRangePtr(rangeCast<RangeType>(range)) IndexInterface<CIndex,SizeT>(pos), mRangePtr(rangeCast<RangeType>(range))
{} {}
CIndex& CIndex::operator=(SizeT pos) CIndex& CIndex::operator=(SizeT lexpos)
{ {
IB::mPos = pos; IB::mPos = lexpos;
return *this; return *this;
} }
@ -51,7 +51,17 @@ namespace CNORXZ
return *this; return *this;
} }
SizeT CIndex::max() const SizeT CIndex::lex() const
{
return IB::mPos;
}
SizeT CIndex::lmax() const
{
return mRangePtr->size();
}
SizeT CIndex::pmax() const
{ {
return mRangePtr->size(); return mRangePtr->size();
} }

View file

@ -37,9 +37,9 @@ namespace CNORXZ
mI(i) mI(i)
{} {}
DIndex& DIndex::operator=(SizeT pos) DIndex& DIndex::operator=(SizeT lexpos)
{ {
*mI = pos; *mI = lexpos;
IB::mPos = mI->pos(); IB::mPos = mI->pos();
return *this; return *this;
} }
@ -82,6 +82,26 @@ namespace CNORXZ
return *this; return *this;
} }
SizeT DIndex::lex() const
{
return mI->lex();
}
SizeT DIndex::pmax() const
{
return mI->pmax();
}
SizeT DIndex::lmax() const
{
return mI->lmax();
}
IndexId<0> DIndex::id() const
{
return mI->id();
}
DType DIndex::operator*() const DType DIndex::operator*() const
{ {
return *(*mI); return *(*mI);
@ -124,4 +144,8 @@ namespace CNORXZ
return DXpr<SizeT>(mI->ifor(xpr, std::forward<std::function<SizeT(SizeT,SizeT)>>(f)) ); return DXpr<SizeT>(mI->ifor(xpr, std::forward<std::function<SizeT(SizeT,SizeT)>>(f)) );
} }
const XIndexPtr& DIndex::xptr() const
{
return mI;
}
} }

View file

@ -83,7 +83,7 @@ namespace CNORXZ
RangePtr operator*(const RangePtr& a, const RangePtr& b) RangePtr operator*(const RangePtr& a, const RangePtr& b)
{ {
assert(0); // check segfault + "flatten" yrange (no yrange of yranges etc) //assert(0); // check segfault + "flatten" yrange (no yrange of yranges etc)
return YRangeFactory({a,b}).create(); return YRangeFactory({a,b}).create();
} }

View file

@ -3,96 +3,216 @@
namespace CNORXZ namespace CNORXZ
{ {
/*************************
* YIndex (private) *
*************************/
inline Vector<XIndexPtr> YIndex::mkIndices() const
{
Vector<XIndexPtr> o(mRange->dim(), nullptr);
for(SizeT i = 0; i != mRange->dim(); ++i){
auto rp = mRange->sub(i);
CXZ_ASSERT(rp != nullptr, "subranges not available");
o[i] = rp->begin().xptr();
}
return o;
}
inline Vector<SizeT> YIndex::mkBlockSizes() const
{
Vector<SizeT> o(mIs.size());
SizeT b = 1;
for(SizeT i = o.size(); i != 0; --i){
const SizeT j = i-1;
o[j] = b;
b *= mIs[j]->pmax();
}
return o;
}
inline Vector<SizeT> YIndex::mkLexBlockSizes() const
{
Vector<SizeT> o(mIs.size());
SizeT b = 1;
for(SizeT i = o.size(); i != 0; --i){
const SizeT j = i-1;
o[j] = b;
b *= mIs[j]->lmax();
}
return o;
}
inline void YIndex::up(SizeT i)
{
auto& idx = mIs[i];
// it is guaranteed that the last accessible position
// is one less than the max position (=end)
if(i != 0 and idx->lex() == idx->lmax()-1){
IB::mPos -= mBlockSizes[i] * idx->pos();
(*idx) = 0;
up(i-1);
return;
}
IB::mPos += mBlockSizes[i];
++(*idx);
}
inline void YIndex::down(SizeT i)
{
auto& idx = mIs[i];
if(i != 0 and idx->pos() == 0){
(*idx) = idx->lmax()-1;
IB::mPos += mBlockSizes[i] * idx->pos();
down(i-1);
return;
}
IB::mPos += mBlockSizes[i];
--(*idx);
}
inline decltype(auto) YIndex::mkIFor(SizeT i, const DXpr<SizeT>& xpr,
const std::function<SizeT(SizeT,SizeT)>& f) const
{
if(i == mIs.size()-1){
return mIs[i]->ifor( xpr, f );
}
else {
return mIs[i]->ifor( mkIFor(i+1, xpr, f), f );
}
}
inline SizeT YIndex::mkPMax() const
{
SizeT o = 0;
for(SizeT i = 0; i != mIs.size(); ++i){
o += (mIs[i]->pmax()-1) * mBlockSizes[i];
}
return o+1;
}
inline SizeT YIndex::mkLMax() const
{
return std::accumulate(mIs.begin(), mIs.end(),1,
[](const auto& res, const auto& el) { return res * el->lmax(); } );
}
/*************** /***************
* YIndex * * YIndex *
***************/ ***************/
YIndex::YIndex(const RangePtr& range, SizeT pos) : YIndex::YIndex(const YIndex& i) :
IndexInterface<YIndex,DType>(pos), IndexInterface<YIndex,DType>(i),
mRangePtr(rangeCast<YRange>(range)), mIs(mRangePtr->dim()), mRange(rangeCast<YRange>(i.range())),
mBlockSizes(mRangePtr->dim()) mIs(mkIndices()),
mBlockSizes(mkBlockSizes()),
mLexBlockSizes(mkLexBlockSizes()),
mPMax(mkPMax()),
mLMax(mkLMax())
{ {
assert(0); *this = i.lex();
// init ...!!!
} }
YIndex::YIndex(const RangePtr& range, const Vector<XIndexPtr>& is, SizeT pos) : YIndex& YIndex::operator=(const YIndex& i)
IndexInterface<YIndex,DType>(pos),
mRangePtr(rangeCast<YRange>(range)), mIs(is),
mBlockSizes(mRangePtr->dim())
{ {
CXZ_ASSERT(mIs.size() == mRangePtr->dim(), "obtained wrong number of indices"); IndexInterface<YIndex,DType>::operator=(i);
assert(0); mRange = rangeCast<YRange>(i.range());
// init ...!!! mIs = mkIndices();
mBlockSizes = mkBlockSizes();
mLexBlockSizes = mkLexBlockSizes();
mPMax = mkPMax();
mLMax = mkLMax();
return *this = i.lex();
} }
YIndex& YIndex::sync() YIndex::YIndex(const RangePtr& range, SizeT lexpos) :
IndexInterface<YIndex,DType>(0),
mRange(rangeCast<YRange>(range)),
mIs(mkIndices()),
mBlockSizes(mkBlockSizes()),
mLexBlockSizes(mkLexBlockSizes()),
mPMax(mkPMax()),
mLMax(mkLMax())
{ {
assert(0); *this = lexpos;
return *this;
} }
YIndex& YIndex::operator=(SizeT pos) YIndex& YIndex::operator=(SizeT lexpos)
{ {
IB::mPos = pos; mLex = lexpos;
assert(0); if(lexpos == lmax()){
// sub inds... (LAZY!!!) !!! IB::mPos = pmax();
return *this;
}
IB::mPos = 0;
for(SizeT i = 0; i != mIs.size(); ++i){
*mIs[i] = (lex() / mLexBlockSizes[i]) % mIs[i]->lmax();
IB::mPos += mBlockSizes[i] * mIs[i]->pos();
}
return *this; return *this;
} }
YIndex& YIndex::operator++() YIndex& YIndex::operator++()
{ {
assert(0); auto& i0 = mIs[0];
// increment sub inds (LAZY!!!) !!! if(i0->lex() != i0->lmax()){
++mPos; up(mIs.size()-1);
}
// no else! up() changes i0!
if(i0->lex() == i0->lmax()){
IB::mPos = pmax();
}
return *this; return *this;
} }
YIndex& YIndex::operator--() YIndex& YIndex::operator--()
{ {
assert(0); auto& i0 = mIs[0];
// decrement sub inds (LAZY!!!) !!! if(i0->lex() == i0->lmax()){
--mPos; IB::mPos = mBlockSizes[0] * i0->pmax();
}
if(lex() != 0){
down(mIs.size()-1);
}
return *this; return *this;
} }
YIndex YIndex::operator+(Int n) const YIndex YIndex::operator+(Int n) const
{ {
assert(0); YIndex o(*this);
// sub inds !!! return o += n;
return YIndex(mRangePtr, IB::mPos + n);
} }
YIndex YIndex::operator-(Int n) const YIndex YIndex::operator-(Int n) const
{ {
assert(0); YIndex o(*this);
// sub inds !!! return o -= n;
return YIndex(mRangePtr, IB::mPos - n);
} }
YIndex& YIndex::operator+=(Int n) YIndex& YIndex::operator+=(Int n)
{ {
assert(0); return *this = lex() + n;
// sub inds !!!
IB::mPos += n;
return *this;
} }
YIndex& YIndex::operator-=(Int n) YIndex& YIndex::operator-=(Int n)
{ {
assert(0);
// sub inds !!! return *this = lex() - n;
IB::mPos -= n;
return *this;
} }
SizeT YIndex::max() const SizeT YIndex::lex() const
{ {
SizeT o = 1; return mLex;
for(auto& i: mIs){ }
o *= i->max();
} SizeT YIndex::pmax() const
return o; {
return mPMax;
}
SizeT YIndex::lmax() const
{
return mLMax;
} }
IndexId<0> YIndex::id() const IndexId<0> YIndex::id() const
@ -102,42 +222,45 @@ namespace CNORXZ
DType YIndex::operator*() const DType YIndex::operator*() const
{ {
assert(0); return meta();
return DType();
} }
SizeT YIndex::dim() const SizeT YIndex::dim() const
{ {
return mRangePtr->dim(); return mRange->dim();
} }
Sptr<YRange> YIndex::range() const Sptr<YRange> YIndex::range() const
{ {
return mRangePtr; return mRange;
} }
UPos YIndex::stepSize(const IndexId<0> id) const UPos YIndex::stepSize(const IndexId<0> id) const
{ {
assert(0); SizeT o = 0;
// sub inds !!! for(SizeT i = 0; i != mIs.size(); ++i){
return UPos(0); const auto u = mIs[i]->stepSize(id) * UPos(mBlockSizes[i]);
o += u.val();
}
return UPos(o);
} }
String YIndex::stringMeta() const String YIndex::stringMeta() const
{ {
String out = "["; const String blim = "[";
auto it = mIs.begin(); const String elim = "]";
for(; it != mIs.end()-1; ++it){ const String dlim = ",";
out += (*it)->stringMeta() + ","; return blim +
} std::accumulate(std::next(mIs.begin()), mIs.end(), mIs[0]->stringMeta(),
out += (*it)->stringMeta() + "]"; [&](const auto& s, const auto& e)
return out; { return s + dlim + e->stringMeta(); } ) +
elim;
} }
DType YIndex::meta() const DType YIndex::meta() const
{ {
Vector<DType> v(mIs.size()); Vector<DType> v(mIs.size());
std::transform(mIs.begin(), mIs.end(), v.begin(), [](auto& x) { return x->meta(); }); std::transform(mIs.begin(), mIs.end(), v.begin(), [](const auto& x) { return x->meta(); });
return DType(v); return DType(v);
} }
@ -145,17 +268,17 @@ namespace CNORXZ
{ {
auto& v = std::any_cast<const Vector<DType>&>(meta.get()); auto& v = std::any_cast<const Vector<DType>&>(meta.get());
assert(v.size() == mIs.size()); assert(v.size() == mIs.size());
IB::mPos = 0;
for(SizeT i = 0; i != mIs.size(); ++i){ for(SizeT i = 0; i != mIs.size(); ++i){
mIs[i]->at(v[i]); mIs[i]->at(v[i]);
IB::mPos += mIs[i]->pos() * mBlockSizes[i];
} }
return *this; return *this;
} }
DXpr<SizeT> YIndex::ifor(const DXpr<SizeT>& xpr, std::function<SizeT(SizeT,SizeT)>&& f) const DXpr<SizeT> YIndex::ifor(const DXpr<SizeT>& xpr, const std::function<SizeT(SizeT,SizeT)>& f) const
{ {
assert(0); return mkIFor(0, xpr, f);
f(0,0);
return DXpr<SizeT>();
} }
/********************** /**********************
@ -176,7 +299,7 @@ namespace CNORXZ
void YRangeFactory::make() void YRangeFactory::make()
{ {
Vector<PtrId> key; Vector<PtrId> key(mRVec.size());
std::transform(mRVec.begin(), mRVec.end(), key.begin(), std::transform(mRVec.begin(), mRVec.end(), key.begin(),
[&](const RangePtr& r) { return r->id(); } ); [&](const RangePtr& r) { return r->id(); } );
mProd = this->fromCreated(typeid(YRange), key); mProd = this->fromCreated(typeid(YRange), key);
@ -191,6 +314,11 @@ namespace CNORXZ
* YRange * * YRange *
***************/ ***************/
RangePtr YRange::sub(SizeT i) const
{
return mRVec[i];
}
SizeT YRange::size() const SizeT YRange::size() const
{ {
SizeT out = 1; SizeT out = 1;

View file

@ -52,6 +52,21 @@ namespace
SizeT mSize; SizeT mSize;
}; };
class YR_Test : public ::testing::Test
{
protected:
YR_Test()
{
mMeta = { "test", "strings", "foo" };
std::sort(mMeta.begin(), mMeta.end(), std::less<String>());
mSize = 7;
}
Vector<String> mMeta;
SizeT mSize;
};
TEST_F(CR_Test, Basics) TEST_F(CR_Test, Basics)
{ {
auto cr = CRangeFactory(mSize).create(); auto cr = CRangeFactory(mSize).create();
@ -176,6 +191,21 @@ namespace
} }
} }
TEST_F(YR_Test, Basics)
{
auto cr = CRangeFactory(mSize).create();
auto ur = URangeFactory<String>(mMeta).create();
auto yr = cr * ur;
EXPECT_EQ(yr->size(), mMeta.size()*mSize);
EXPECT_EQ(yr->dim(), 2u);
EXPECT_TRUE(yr->begin() != yr->end());
EXPECT_FALSE(yr->begin() == yr->end());
EXPECT_EQ(yr->begin().pos(), 0u);
EXPECT_EQ(yr->end().pos(), yr->size());
}
// RCast_Test // RCast_Test
} }