21 inline DPack YIndex::mkIndices()
const
24 for(SizeT
i = 0;
i != mRange->dim(); ++
i){
25 auto rp = mRange->sub(
i);
27 o[
i] =
rp->begin().xptr();
29 return DPack(std::move(o));
36 for(SizeT
i = o.size();
i != 0; --
i){
39 b *= mIs[
j]->pmax().val();
48 for(SizeT
i = o.size();
i != 0; --
i){
51 b *= mIs[
j]->lmax().val();
59 std::transform(
is.begin(),
is.end(), o.begin(), [](
const auto&
e) { return e->range(); });
63 inline void YIndex::mkPos()
68 mLex += mIs[
i]->
lex() * mLexFormat[
i].val();
73 inline void YIndex::up(SizeT
i)
78 if(
i != 0
and idx->lex() ==
idx->lmax().val()-1){
80 mLex -= mLexFormat[
i].val() *
idx->lex();
86 mLex += mLexFormat[
i].val();
90 inline void YIndex::down(
SizeT i)
94 (*idx) =
idx->lmax().val()-1;
96 mLex += mLexFormat[
i].val() *
idx->lex();
101 mLex -= mLexFormat[
i].val();
105 inline decltype(
auto) YIndex::mkIFor(SizeT
i,
const DXpr<None>&
xpr, NoF&&
f)
const
107 if(
i == mIs.size()-1){
108 return mIs[
i]->ifor(
xpr, std::forward<NoF>(
f) );
113 return mIs[
i]->ifor( mkIFor(
i+1,
xpr, std::move(
f1)), std::move(
f2) );
117 inline SizeT YIndex::mkPMax()
const
120 for(SizeT
i = 0;
i != mIs.
size(); ++
i){
121 o += (mIs[
i]->pmax().val()-1) * mFormat[
i].val();
126 inline SizeT YIndex::mkLMax()
const
128 return std::accumulate(mIs.
all().begin(), mIs.
all().end(),1,
129 [](
const auto&
res,
const auto&
el) { return res * el->lmax().val(); } );
142 mLexFormat(
i.mLexFormat),
155 mLexFormat =
i.mLexFormat;
158 return *
this =
i.lex();
166 mLexFormat(mkLexFormat()),
178 mLexFormat(mkLexFormat()),
190 mLexFormat(mkLexFormat()),
202 mLexFormat(mkLexFormat()),
219 *mIs[
i] = (
lex() / mLexFormat[
i].val()) % mIs[
i]->
lmax().
val();
266 if(
static_cast<Int>(
lex()) +
n < 0){
269 return *
this =
static_cast<Int>(
lex()) +
n;
274 if(
static_cast<Int>(
lex()) -
n < 0){
277 return *
this =
static_cast<Int>(
lex()) -
n;
307 return mRange->dim();
319 const auto u = mIs[
i]->stepSize(
id) * mFormat[
i];
331 std::accumulate(std::next(mIs.
all().begin()), mIs.
all().end(), mIs[0]->stringMeta(),
332 [&](
const auto&
s,
const auto&
e)
333 { return s + dlim + e->stringMeta(); } ) +
340 std::transform(mIs.
all().begin(), mIs.
all().end(),
v.begin(),
341 [](
const auto& x) { return x->meta(); });
348 <<
meta.size() <<
") different from expected size ("
349 << mIs.
size() <<
")");
359 return mkIFor(0,
xpr, std::forward<NoF>(
f));
383 <<
last.dim() <<
") than begin index (" <<
dim() <<
")");
386 v[
i] = mIs[
i]->prange(
last.pack()[
i] );
396 dfv[
j] = mIs[
j]->deepFormat();
397 std::for_each(
dfv[
j].begin(),
dfv[
j].end(),
398 [&](
SizeT& x) { x *= mFormat[
j].val(); } );
404 std::copy(
dfv[
j].begin(),
dfv[
j].end(), o.begin()+
off);
415 dmv[
j] = mIs[
j]->deepMax();
421 std::copy(
dmv[
j].begin(),
dmv[
j].end(), o.begin()+
off);
431 CXZ_ASSERT(
f.size() ==
s.size(),
"input error: f.size() != s.size()");
434 <<
lmax().val() <<
", got " <<
s[0]);
443 CXZ_ASSERT(
j !=
s.size(),
"incompatible index formats");
444 xi *= mIs[
i]->lmax().val();
447 CXZ_ERROR(
"reformating with lower-dimensional formats is not possible; use sub-indices instead");
453 CXZ_ASSERT(
j !=
s.size(),
"incompatible index formats");
462 std::copy(
f.begin()+
j0,
f.begin()+
j,
nf.begin());
464 std::for_each(
nf.begin(),
nf.end(), [&](
SizeT& x)
465 { CXZ_ASSERT(x % nformat[i].val() == 0,
"incompatible"); x /= nformat[i].val(); } );
466 std::copy(
s.begin()+
j0,
s.begin()+
j,
ns.begin());
467 mIs[
i]->reformat(
nf,
ns);
483 if(mFormat[
j].val() !=
b){
486 b *= mIs[
j]->pmax().val();
513 <<
", which is out of scope; maximum position in range is " <<
idx->lmax().
val() );
536 return std::make_shared<YIndex>(pack.
all());
541 return std::make_shared<YIndex>(
is);
560 void YRangeFactory::make()
563 std::transform(mRVec.begin(), mRVec.end(),
k.begin(),
564 [&](
const RangePtr& r) { return r->id(); } );
566 if(
mProd ==
nullptr){
567 mProd = std::shared_ptr<YRange>
568 (
new YRange( std::move(mRVec) ) );
584 if(mRVec.size() == 0){
610 for(
auto rit = mRVec.end()-1;;--
rit){
615 if(
rit == mRVec.begin()){
636 CXZ_ASSERT(r->dim() ==
this->dim(),
"cannot extend range of dimension "
637 <<
this->dim() <<
" by range of dimension " << r->dim());
639 if(this->
dim() == 1
and r->sub(0) ==
nullptr){
640 rvec[0] = mRVec[0]->extend( r );
644 rvec[
i] = mRVec[
i]->extend( r->sub(
i) );
653 std::transform(mRVec.begin(), mRVec.end(),
k.begin(),
654 [&](
const RangePtr& r) { return r->id(); } );
677 return std::dynamic_pointer_cast<YRange>(
YRangeFactory({r}).create() );
#define CXZ_ERROR(errmsg)
#define CXZ_ASSERT(statement, errmsg)
const Vector< XIndexPtr > & all() const
RangePtr fromCreated(const TypeInfo &info, const Vector< Uuid > &rids) const
void addToCreated(const TypeInfo &info, const Vector< Uuid > &rids, const RangePtr &r)
constexpr const SizeT & val() const
YIndex operator-(Int n) const
Vector< SizeT > deepMax() const
YIndex operator+(Int n) const
const YFormat & format() const
RangePtr prange(const YIndex &last) const
const YFormat & lexFormat() const
YIndex & operator=(YIndex &&i)=default
const DPack & pack() const
bool formatIsTrivial() const
YIndex & at(const Vector< DType > &meta)
UPos stepSize(const IndexId< 0 > id) const
Vector< DType > operator*() const
DXpr< None > ifor(const DXpr< None > &xpr, NoF &&f) const
YIndex & operator-=(Int n)
YIndex & setSub(SizeT ind, SizeT lex)
String stringMeta() const
YIndex & operator+=(Int n)
Sptr< YRange > range() const
Vector< DType > meta() const
Vector< SizeT > deepFormat() const
YIndex & setFormat(const YFormat &bs)
YIndex & reformat(const Vector< SizeT > &f, const Vector< SizeT > &s)
virtual MArray< RangePtr > sub() const override final
virtual const TypeInfo & type() const override final
virtual RangePtr extend(const RangePtr &r) const override final
virtual SizeT size() const override final
virtual SizeT dim() const override final
virtual String stringMeta(SizeT pos) const override final
virtual const TypeInfo & metaType() const override final
RangePtr yrange(const Vector< RangePtr > &rs)
Sptr< RangeBase > RangePtr
Sptr< YIndex > yindexPtr(const DPack &is)
std::vector< T, Allocator< T > > Vector
decltype(auto) xpr(const Sptr< I > &i)
Sptr< Range > rangeCast(const RangePtr r)
YIndex yindex(const DPack &pack)
std::shared_ptr< T > Sptr
static Sptr< Range > func(const RangePtr &r)