yrange: replace blockSizes by yformat
This commit is contained in:
parent
b1f9a38af7
commit
346f92f267
2 changed files with 48 additions and 61 deletions
|
@ -7,6 +7,8 @@
|
||||||
#include "index_base.h"
|
#include "index_base.h"
|
||||||
#include "xindex.h"
|
#include "xindex.h"
|
||||||
#include "xpr/xpr.h"
|
#include "xpr/xpr.h"
|
||||||
|
#include "index_format.h"
|
||||||
|
#include "index_pack.h"
|
||||||
|
|
||||||
namespace CNORXZ
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
|
@ -25,9 +27,9 @@ namespace CNORXZ
|
||||||
YIndex& operator=(const YIndex& i);
|
YIndex& operator=(const YIndex& i);
|
||||||
|
|
||||||
YIndex(const Vector<XIndexPtr>& is);
|
YIndex(const Vector<XIndexPtr>& is);
|
||||||
YIndex(const Vector<SizeT>& bs, const Vector<XIndexPtr>& is);
|
YIndex(const YFormat& bs, const Vector<XIndexPtr>& is);
|
||||||
YIndex(const RangePtr& range, SizeT lexpos = 0);
|
YIndex(const RangePtr& range, SizeT lexpos = 0);
|
||||||
YIndex(const RangePtr& range, const Vector<SizeT>& bs, SizeT lexpos = 0);
|
YIndex(const RangePtr& range, const YFormat& bs, SizeT lexpos = 0);
|
||||||
|
|
||||||
YIndex& operator=(SizeT lexpos);
|
YIndex& operator=(SizeT lexpos);
|
||||||
YIndex& operator++();
|
YIndex& operator++();
|
||||||
|
@ -52,22 +54,19 @@ namespace CNORXZ
|
||||||
DType meta() const;
|
DType meta() const;
|
||||||
YIndex& at(const DType& meta);
|
YIndex& at(const DType& meta);
|
||||||
|
|
||||||
Sptr<DIndex> format(const Sptr<DIndex>& ind) const;
|
|
||||||
Sptr<DIndex> slice(const Sptr<DIndex>& ind) const;
|
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
YIndex& operator()(const Sptr<YIndex>& i);
|
YIndex& operator()(const Sptr<YIndex>& i);
|
||||||
YIndex& operator()();
|
YIndex& operator()();
|
||||||
|
|
||||||
const Vector<XIndexPtr>& pack() const;
|
const Vector<XIndexPtr>& pack() const;
|
||||||
const Vector<SizeT>& blockSizes() const;
|
const YFormat& format() const;
|
||||||
const Vector<SizeT>& lexBlockSizes() const;
|
const YFormat& lexFormat() const;
|
||||||
YIndex& setBlockSizes(const Vector<SizeT>& bs);
|
YIndex& setFormat(const YFormat& bs);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
inline Vector<SizeT> mkBlockSizes() const;
|
inline Vector<SizeT> mkFormat() const;
|
||||||
inline Vector<SizeT> mkLexBlockSizes() const;
|
inline Vector<SizeT> mkLexFormat() const;
|
||||||
inline Vector<RangePtr> mkRangeVec(const Vector<XIndexPtr>& is) const;
|
inline Vector<RangePtr> mkRangeVec(const Vector<XIndexPtr>& is) const;
|
||||||
inline void mkPos();
|
inline void mkPos();
|
||||||
inline Vector<XIndexPtr> mkIndices() const;
|
inline Vector<XIndexPtr> mkIndices() const;
|
||||||
|
@ -81,8 +80,8 @@ namespace CNORXZ
|
||||||
|
|
||||||
Sptr<YRange> mRange;
|
Sptr<YRange> mRange;
|
||||||
Vector<XIndexPtr> mIs;
|
Vector<XIndexPtr> mIs;
|
||||||
Vector<SizeT> mBlockSizes; // dim() elements only!!!
|
YFormat mFormat; // dim() elements only!!!
|
||||||
Vector<SizeT> mLexBlockSizes; // dim() elements only!!!
|
YFormat mLexFormat; // dim() elements only!!!
|
||||||
SizeT mLex = 0;
|
SizeT mLex = 0;
|
||||||
UPos mPMax = 0;
|
UPos mPMax = 0;
|
||||||
UPos mLMax = 0;
|
UPos mLMax = 0;
|
||||||
|
|
|
@ -18,7 +18,7 @@ namespace CNORXZ
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Vector<SizeT> YIndex::mkBlockSizes() const
|
inline Vector<SizeT> YIndex::mkFormat() const
|
||||||
{
|
{
|
||||||
Vector<SizeT> o(mIs.size());
|
Vector<SizeT> o(mIs.size());
|
||||||
SizeT b = 1;
|
SizeT b = 1;
|
||||||
|
@ -30,7 +30,7 @@ namespace CNORXZ
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Vector<SizeT> YIndex::mkLexBlockSizes() const
|
inline Vector<SizeT> YIndex::mkLexFormat() const
|
||||||
{
|
{
|
||||||
Vector<SizeT> o(mIs.size());
|
Vector<SizeT> o(mIs.size());
|
||||||
SizeT b = 1;
|
SizeT b = 1;
|
||||||
|
@ -54,8 +54,8 @@ namespace CNORXZ
|
||||||
mLex = 0;
|
mLex = 0;
|
||||||
IB::mPos = 0;
|
IB::mPos = 0;
|
||||||
for(SizeT i = 0; i != dim(); ++i){
|
for(SizeT i = 0; i != dim(); ++i){
|
||||||
mLex += mIs[i]->lex() * mLexBlockSizes[i];
|
mLex += mIs[i]->lex() * mLexFormat[i].val();
|
||||||
IB::mPos += mIs[i]->pos() * mBlockSizes[i];
|
IB::mPos += mIs[i]->pos() * mFormat[i].val();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,14 +65,14 @@ namespace CNORXZ
|
||||||
// it is guaranteed that the last accessible position
|
// it is guaranteed that the last accessible position
|
||||||
// is one less than the max position (=end)
|
// is one less than the max position (=end)
|
||||||
if(i != 0 and idx->lex() == idx->lmax().val()-1){
|
if(i != 0 and idx->lex() == idx->lmax().val()-1){
|
||||||
IB::mPos -= mBlockSizes[i] * idx->pos();
|
IB::mPos -= mFormat[i].val() * idx->pos();
|
||||||
mLex -= mLexBlockSizes[i] * idx->lex();
|
mLex -= mLexFormat[i].val() * idx->lex();
|
||||||
(*idx) = 0;
|
(*idx) = 0;
|
||||||
up(i-1);
|
up(i-1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
IB::mPos += mBlockSizes[i];
|
IB::mPos += mFormat[i].val();
|
||||||
mLex += mLexBlockSizes[i];
|
mLex += mLexFormat[i].val();
|
||||||
++(*idx);
|
++(*idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,13 +81,13 @@ namespace CNORXZ
|
||||||
auto& idx = mIs[i];
|
auto& idx = mIs[i];
|
||||||
if(i != 0 and idx->pos() == 0){
|
if(i != 0 and idx->pos() == 0){
|
||||||
(*idx) = idx->lmax().val()-1;
|
(*idx) = idx->lmax().val()-1;
|
||||||
IB::mPos += mBlockSizes[i] * idx->pos();
|
IB::mPos += mFormat[i].val() * idx->pos();
|
||||||
mLex += mLexBlockSizes[i] * idx->lex();
|
mLex += mLexFormat[i].val() * idx->lex();
|
||||||
down(i-1);
|
down(i-1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
IB::mPos -= mBlockSizes[i];
|
IB::mPos -= mFormat[i].val();
|
||||||
mLex -= mLexBlockSizes[i];
|
mLex -= mLexFormat[i].val();
|
||||||
--(*idx);
|
--(*idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ namespace CNORXZ
|
||||||
{
|
{
|
||||||
SizeT o = 0;
|
SizeT o = 0;
|
||||||
for(SizeT i = 0; i != mIs.size(); ++i){
|
for(SizeT i = 0; i != mIs.size(); ++i){
|
||||||
o += (mIs[i]->pmax().val()-1) * mBlockSizes[i];
|
o += (mIs[i]->pmax().val()-1) * mFormat[i].val();
|
||||||
}
|
}
|
||||||
return o+1;
|
return o+1;
|
||||||
}
|
}
|
||||||
|
@ -128,8 +128,8 @@ namespace CNORXZ
|
||||||
IndexInterface<YIndex,DType>(i),
|
IndexInterface<YIndex,DType>(i),
|
||||||
mRange(rangeCast<YRange>(i.range())),
|
mRange(rangeCast<YRange>(i.range())),
|
||||||
mIs(mkIndices()),
|
mIs(mkIndices()),
|
||||||
mBlockSizes(mkBlockSizes()),
|
mFormat(mkFormat()),
|
||||||
mLexBlockSizes(mkLexBlockSizes()),
|
mLexFormat(mkLexFormat()),
|
||||||
mPMax(mkPMax()),
|
mPMax(mkPMax()),
|
||||||
mLMax(mkLMax())
|
mLMax(mkLMax())
|
||||||
{
|
{
|
||||||
|
@ -141,8 +141,8 @@ namespace CNORXZ
|
||||||
IndexInterface<YIndex,DType>::operator=(i);
|
IndexInterface<YIndex,DType>::operator=(i);
|
||||||
mRange = rangeCast<YRange>(i.range());
|
mRange = rangeCast<YRange>(i.range());
|
||||||
mIs = mkIndices();
|
mIs = mkIndices();
|
||||||
mBlockSizes = mkBlockSizes();
|
mFormat = mkFormat();
|
||||||
mLexBlockSizes = mkLexBlockSizes();
|
mLexFormat = mkLexFormat();
|
||||||
mPMax = mkPMax();
|
mPMax = mkPMax();
|
||||||
mLMax = mkLMax();
|
mLMax = mkLMax();
|
||||||
return *this = i.lex();
|
return *this = i.lex();
|
||||||
|
@ -152,20 +152,20 @@ namespace CNORXZ
|
||||||
IndexInterface<YIndex,DType>(0),
|
IndexInterface<YIndex,DType>(0),
|
||||||
mRange(std::dynamic_pointer_cast<YRange>(yrange(mkRangeVec(is)))),
|
mRange(std::dynamic_pointer_cast<YRange>(yrange(mkRangeVec(is)))),
|
||||||
mIs(is),
|
mIs(is),
|
||||||
mBlockSizes(mkBlockSizes()),
|
mFormat(mkFormat()),
|
||||||
mLexBlockSizes(mkLexBlockSizes()),
|
mLexFormat(mkLexFormat()),
|
||||||
mPMax(mkPMax()),
|
mPMax(mkPMax()),
|
||||||
mLMax(mkLMax())
|
mLMax(mkLMax())
|
||||||
{
|
{
|
||||||
mkPos();
|
mkPos();
|
||||||
}
|
}
|
||||||
|
|
||||||
YIndex::YIndex(const Vector<SizeT>& bs, const Vector<XIndexPtr>& is) :
|
YIndex::YIndex(const YFormat& bs, const Vector<XIndexPtr>& is) :
|
||||||
IndexInterface<YIndex,DType>(0),
|
IndexInterface<YIndex,DType>(0),
|
||||||
mRange(std::dynamic_pointer_cast<YRange>(yrange(mkRangeVec(is)))),
|
mRange(std::dynamic_pointer_cast<YRange>(yrange(mkRangeVec(is)))),
|
||||||
mIs(is),
|
mIs(is),
|
||||||
mBlockSizes(bs),
|
mFormat(bs),
|
||||||
mLexBlockSizes(mkLexBlockSizes()),
|
mLexFormat(mkLexFormat()),
|
||||||
mPMax(mkPMax()),
|
mPMax(mkPMax()),
|
||||||
mLMax(mkLMax())
|
mLMax(mkLMax())
|
||||||
{
|
{
|
||||||
|
@ -176,20 +176,20 @@ namespace CNORXZ
|
||||||
IndexInterface<YIndex,DType>(0),
|
IndexInterface<YIndex,DType>(0),
|
||||||
mRange(rangeCast<YRange>(range)),
|
mRange(rangeCast<YRange>(range)),
|
||||||
mIs(mkIndices()),
|
mIs(mkIndices()),
|
||||||
mBlockSizes(mkBlockSizes()),
|
mFormat(mkFormat()),
|
||||||
mLexBlockSizes(mkLexBlockSizes()),
|
mLexFormat(mkLexFormat()),
|
||||||
mPMax(mkPMax()),
|
mPMax(mkPMax()),
|
||||||
mLMax(mkLMax())
|
mLMax(mkLMax())
|
||||||
{
|
{
|
||||||
*this = lexpos;
|
*this = lexpos;
|
||||||
}
|
}
|
||||||
|
|
||||||
YIndex::YIndex(const RangePtr& range, const Vector<SizeT>& bs, SizeT lexpos) :
|
YIndex::YIndex(const RangePtr& range, const YFormat& bs, SizeT lexpos) :
|
||||||
IndexInterface<YIndex,DType>(0),
|
IndexInterface<YIndex,DType>(0),
|
||||||
mRange(rangeCast<YRange>(range)),
|
mRange(rangeCast<YRange>(range)),
|
||||||
mIs(mkIndices()),
|
mIs(mkIndices()),
|
||||||
mBlockSizes(bs),
|
mFormat(bs),
|
||||||
mLexBlockSizes(mkLexBlockSizes()),
|
mLexFormat(mkLexFormat()),
|
||||||
mPMax(mkPMax()),
|
mPMax(mkPMax()),
|
||||||
mLMax(mkLMax())
|
mLMax(mkLMax())
|
||||||
{
|
{
|
||||||
|
@ -206,8 +206,8 @@ namespace CNORXZ
|
||||||
mLex = lexpos;
|
mLex = lexpos;
|
||||||
IB::mPos = 0;
|
IB::mPos = 0;
|
||||||
for(SizeT i = 0; i != mIs.size(); ++i){
|
for(SizeT i = 0; i != mIs.size(); ++i){
|
||||||
*mIs[i] = (lex() / mLexBlockSizes[i]) % mIs[i]->lmax().val();
|
*mIs[i] = (lex() / mLexFormat[i].val()) % mIs[i]->lmax().val();
|
||||||
IB::mPos += mBlockSizes[i] * mIs[i]->pos();
|
IB::mPos += mFormat[i].val() * mIs[i]->pos();
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@ -301,7 +301,7 @@ namespace CNORXZ
|
||||||
{
|
{
|
||||||
SizeT o = 0;
|
SizeT o = 0;
|
||||||
for(SizeT i = 0; i != mIs.size(); ++i){
|
for(SizeT i = 0; i != mIs.size(); ++i){
|
||||||
const auto u = mIs[i]->stepSize(id) * UPos(mBlockSizes[i]);
|
const auto u = mIs[i]->stepSize(id) * mFormat[i];
|
||||||
o += u.val();
|
o += u.val();
|
||||||
}
|
}
|
||||||
return UPos(o);
|
return UPos(o);
|
||||||
|
@ -334,23 +334,11 @@ namespace CNORXZ
|
||||||
IB::mPos = 0;
|
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];
|
IB::mPos += mIs[i]->pos() * mFormat[i].val();
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Sptr<DIndex> YIndex::format(const Sptr<DIndex>& ind) const
|
|
||||||
{
|
|
||||||
CXZ_ERROR("IMPLEMENT!!!");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
Sptr<DIndex> YIndex::slice(const Sptr<DIndex>& ind) const
|
|
||||||
{
|
|
||||||
CXZ_ERROR("IMPLEMENT!!!");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
DXpr<SizeT> YIndex::ifor(const DXpr<SizeT>& xpr, std::function<SizeT(SizeT,SizeT)>&& f) const
|
DXpr<SizeT> YIndex::ifor(const DXpr<SizeT>& xpr, std::function<SizeT(SizeT,SizeT)>&& f) const
|
||||||
{
|
{
|
||||||
return mkIFor(0, xpr, std::forward<std::function<SizeT(SizeT,SizeT)>>(f));
|
return mkIFor(0, xpr, std::forward<std::function<SizeT(SizeT,SizeT)>>(f));
|
||||||
|
@ -374,19 +362,19 @@ namespace CNORXZ
|
||||||
return mIs;
|
return mIs;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Vector<SizeT>& YIndex::blockSizes() const
|
const YFormat& YIndex::format() const
|
||||||
{
|
{
|
||||||
return mBlockSizes;
|
return mFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Vector<SizeT>& YIndex::lexBlockSizes() const
|
const YFormat& YIndex::lexFormat() const
|
||||||
{
|
{
|
||||||
return mLexBlockSizes;
|
return mLexFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
YIndex& YIndex::setBlockSizes(const Vector<SizeT>& bs)
|
YIndex& YIndex::setFormat(const YFormat& bs)
|
||||||
{
|
{
|
||||||
mBlockSizes = bs;
|
mFormat = bs;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue