This commit is contained in:
parent
00eb2d2fb1
commit
4b9c8e94dc
18 changed files with 113 additions and 13 deletions
|
@ -130,11 +130,21 @@ namespace CNORXZ
|
|||
}
|
||||
else {
|
||||
if(i->formatIsTrivial()){
|
||||
// try to apply container format
|
||||
auto aformat = begin().deepFormat();
|
||||
CXZ_ERROR("IMPLEMENT " << toString(aformat));
|
||||
// try to apply container format.
|
||||
// if the reformat changes the index type in any manner
|
||||
// the format is not applicable:
|
||||
if constexpr(std::is_same<decltype(i->reformat( Vector<SizeT>(), Vector<SizeT>() )),Index>::value){
|
||||
auto beg = begin();
|
||||
auto aformat = beg.deepFormat();
|
||||
auto amax = beg.deepMax();
|
||||
auto fi = i->reformat( aformat, amax );
|
||||
return coproot(*this, moveToPtr( fi ) );
|
||||
}
|
||||
else {
|
||||
this->checkFormatCompatibility(*i);
|
||||
return coproot(*this, i);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// check if format is compatible
|
||||
this->checkFormatCompatibility(*i);
|
||||
|
@ -313,11 +323,21 @@ namespace CNORXZ
|
|||
}
|
||||
else {
|
||||
if(i->formatIsTrivial()){
|
||||
// try to apply container format
|
||||
auto aformat = begin().deepFormat();
|
||||
CXZ_ERROR("IMPLEMENT " << toString(aformat));
|
||||
// try to apply container format.
|
||||
// if the reformat changes the index type in any manner
|
||||
// the format is not applicable:
|
||||
if constexpr(std::is_same<decltype(i->reformat( Vector<SizeT>(), Vector<SizeT>() )),Index>::value){
|
||||
auto beg = begin();
|
||||
auto aformat = beg.deepFormat();
|
||||
auto amax = beg.deepMax();
|
||||
auto fi = i->reformat( aformat, amax );
|
||||
return oproot(*this, moveToPtr( fi ) );
|
||||
}
|
||||
else {
|
||||
this->checkFormatCompatibility(*i);
|
||||
return oproot(*this, i);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// check if format is compatible
|
||||
this->checkFormatCompatibility(*i);
|
||||
|
|
|
@ -107,6 +107,9 @@ namespace CNORXZ
|
|||
/** @copydoc IndexInterface::deepFormat() */
|
||||
SizeT deepFormat() const;
|
||||
|
||||
/** @copydoc IndexInterface::deepMax() */
|
||||
SizeT deepMax() const;
|
||||
|
||||
/** @copydoc IndexInterface::reformat() */
|
||||
CIndex reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) const;
|
||||
|
||||
|
|
|
@ -64,6 +64,7 @@ namespace CNORXZ
|
|||
DIndex& at(const DType& meta);
|
||||
RangePtr prange(const DIndex& end) const;
|
||||
Vector<SizeT> deepFormat() const;
|
||||
Vector<SizeT> deepMax() const;
|
||||
|
||||
/** @copydoc IndexInterface::reformat() */
|
||||
DIndex reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) const;
|
||||
|
|
|
@ -173,9 +173,13 @@ namespace CNORXZ
|
|||
/** recursive index format */
|
||||
decltype(auto) deepFormat() const { return THIS().deepFormat(); }
|
||||
|
||||
/** reformat index, return new index instance
|
||||
/** max of all single-indices (recursive) */
|
||||
decltype(auto) deepMax() const { return THIS().deepMax(); }
|
||||
|
||||
/** reformat index, create new index instance
|
||||
@param f new format
|
||||
@param s new sub-index sizes
|
||||
@return new reformatted index instance
|
||||
*/
|
||||
decltype(auto) reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) const { return THIS().reformat(f,s); }
|
||||
|
||||
|
|
|
@ -462,7 +462,7 @@ namespace CNORXZ
|
|||
return false;
|
||||
}
|
||||
const bool ret2 = iter<0,NI-1>
|
||||
( [&](auto j) { return mFormat[CSizeT<j>{}].val() == mIPack[CSizeT<j+1>{}].lmax().val() * mFormat[CSizeT<j+1>{}].val(); },
|
||||
( [&](auto j) { return mFormat[CSizeT<j>{}].val() == mIPack[CSizeT<j+1>{}]->lmax().val() * mFormat[CSizeT<j+1>{}].val(); },
|
||||
[](const auto&... x) { return (x and ...); });
|
||||
if(ret2 and mFormat[CSizeT<NI-1>{}].val() == 1){
|
||||
return true;
|
||||
|
@ -512,7 +512,7 @@ namespace CNORXZ
|
|||
}
|
||||
|
||||
template <class FormatT, class... Indices>
|
||||
RangePtr GMIndex<FormatT,Indices...>::prange(const MIndex<Indices...>& last) const
|
||||
RangePtr GMIndex<FormatT,Indices...>::prange(const GMIndex<FormatT,Indices...>& last) const
|
||||
{
|
||||
return iter<0,NI>
|
||||
( [&](auto i) {
|
||||
|
@ -531,6 +531,13 @@ namespace CNORXZ
|
|||
[&](const auto&... e) { return concat(e...); } );
|
||||
}
|
||||
|
||||
template <class FormatT, class... Indices>
|
||||
auto GMIndex<FormatT,Indices...>::deepMax() const
|
||||
{
|
||||
return iter<0,NI>( [&](auto i) { return mIPack[i]->deepMax(); },
|
||||
[&](const auto&... e) { return concat(e...); } );
|
||||
}
|
||||
|
||||
template <class FormatT, class... Indices>
|
||||
decltype(auto)
|
||||
GMIndex<FormatT,Indices...>::reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) const
|
||||
|
@ -563,7 +570,7 @@ namespace CNORXZ
|
|||
{ CXZ_ASSERT(x % nformat[i].val() == 0, "incompatible"); x /= nformat[i].val(); } );
|
||||
std::copy(s.begin()+j0,s.begin()+j,ns.begin());
|
||||
return moveToPtr( mIPack[i]->reformat(nf,ns) );
|
||||
}, [](auto&... e) { return std::make_tuple( e... ); } );
|
||||
}, [](const auto&... e) { return std::make_tuple( e... ); } );
|
||||
GMIndex<MFormat<NI>,Indices...> oi { MFormat<NI>(nformat),SPack<Indices...>(npack) };
|
||||
oi = lex();
|
||||
return oi;
|
||||
|
|
|
@ -89,8 +89,9 @@ namespace CNORXZ
|
|||
const SPack<Indices...>& pack() const;
|
||||
const auto& format() const;
|
||||
const auto& lexFormat() const;
|
||||
RangePtr prange(const MIndex<Indices...>& last) const;
|
||||
RangePtr prange(const GMIndex<FormatT,Indices...>& last) const;
|
||||
auto deepFormat() const;
|
||||
auto deepMax() const;
|
||||
|
||||
/** @copydoc IndexInterface::reformat() */
|
||||
decltype(auto) reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) const;
|
||||
|
@ -248,6 +249,7 @@ namespace CNORXZ
|
|||
{
|
||||
static constexpr bool value = (index_expression_exists<Indices>::value and ...);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -167,6 +167,12 @@ namespace CNORXZ
|
|||
return mOrig->deepFormat();
|
||||
}
|
||||
|
||||
template <class IndexT>
|
||||
decltype(auto) PIndex<IndexT>::deepMax() const
|
||||
{
|
||||
return mOrig->deepMax();
|
||||
}
|
||||
|
||||
template <class IndexT>
|
||||
PIndex<IndexT> PIndex<IndexT>::reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) const
|
||||
{
|
||||
|
|
|
@ -55,6 +55,7 @@ namespace CNORXZ
|
|||
UPos stepSize(const IndexId<I>& id) const;
|
||||
RangePtr prange(const PIndex<IndexT>& last) const;
|
||||
decltype(auto) deepFormat() const;
|
||||
decltype(auto) deepMax() const;
|
||||
|
||||
/** @copydoc IndexInterface::reformat() */
|
||||
PIndex reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) const;
|
||||
|
|
|
@ -177,6 +177,12 @@ namespace CNORXZ
|
|||
return 1;
|
||||
}
|
||||
|
||||
template <typename MetaT, SizeT S>
|
||||
SizeT SIndex<MetaT,S>::deepMax() const
|
||||
{
|
||||
return lmax().val();
|
||||
}
|
||||
|
||||
template <typename MetaT, SizeT S>
|
||||
SIndex<MetaT,S> SIndex<MetaT,S>::reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) const
|
||||
{
|
||||
|
|
|
@ -61,6 +61,7 @@ namespace CNORXZ
|
|||
|
||||
RangePtr prange(const SIndex<MetaType,S>& last) const;
|
||||
SizeT deepFormat() const;
|
||||
SizeT deepMax() const;
|
||||
|
||||
/** @copydoc IndexInterface::reformat() */
|
||||
SIndex reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) const;
|
||||
|
|
|
@ -163,14 +163,25 @@ namespace CNORXZ
|
|||
return 1;
|
||||
}
|
||||
|
||||
template <typename MetaT>
|
||||
SizeT UIndex<MetaT>::deepMax() const
|
||||
{
|
||||
return lmax().val();
|
||||
}
|
||||
|
||||
template <typename MetaT>
|
||||
UIndex<MetaT> UIndex<MetaT>::reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) const
|
||||
{
|
||||
// can also get multi dim stuff, but:
|
||||
// * overall extension must match
|
||||
// * f must be trivial
|
||||
/*
|
||||
CXZ_ASSERT(f.size() == 1, "expected format of dimension 1, got " << toString(f));
|
||||
CXZ_ASSERT(s.size() == 1, "expected sizes of dimension 1, got " << toString(s));
|
||||
CXZ_ASSERT(f[0] == 1, "trivial format ([1]), got " << toString(f));
|
||||
CXZ_ASSERT(s[0] == lmax().val(), "expected size to be equal to index size (" <<
|
||||
lmax().val() << "), got " << s[0]);
|
||||
*/
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
|
@ -67,6 +67,8 @@ namespace CNORXZ
|
|||
|
||||
SizeT deepFormat() const;
|
||||
|
||||
SizeT deepMax() const;
|
||||
|
||||
/** @copydoc IndexInterface::reformat() */
|
||||
UIndex reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) const;
|
||||
|
||||
|
|
|
@ -158,6 +158,12 @@ namespace CNORXZ
|
|||
return toVec( mI->deepFormat() );
|
||||
}
|
||||
|
||||
template <class Index, typename Meta>
|
||||
Vector<SizeT> XIndex<Index,Meta>::deepMax() const
|
||||
{
|
||||
return toVec( mI->deepMax() );
|
||||
}
|
||||
|
||||
template <class Index, typename Meta>
|
||||
XIndexPtr XIndex<Index,Meta>::reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) const
|
||||
{
|
||||
|
|
|
@ -52,6 +52,7 @@ namespace CNORXZ
|
|||
virtual UPos stepSize(const IndexId<0>& id) const = 0;
|
||||
virtual RangePtr prange(const XIndexPtr& last) const = 0;
|
||||
virtual Vector<SizeT> deepFormat() const = 0;
|
||||
virtual Vector<SizeT> deepMax() const = 0;
|
||||
virtual XIndexPtr reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) const = 0;
|
||||
|
||||
virtual String stringMeta() const = 0;
|
||||
|
@ -105,6 +106,7 @@ namespace CNORXZ
|
|||
virtual UPos stepSize(const IndexId<0>& id) const override final;
|
||||
virtual RangePtr prange(const XIndexPtr& last) const override final;
|
||||
virtual Vector<SizeT> deepFormat() const override final;
|
||||
virtual Vector<SizeT> deepMax() const override final;
|
||||
virtual XIndexPtr reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) const override final;
|
||||
|
||||
virtual String stringMeta() const override final;
|
||||
|
|
|
@ -76,6 +76,7 @@ namespace CNORXZ
|
|||
const DPack& pack() const;
|
||||
RangePtr prange(const YIndex& last) const;
|
||||
Vector<SizeT> deepFormat() const;
|
||||
Vector<SizeT> deepMax() const;
|
||||
const YFormat& format() const;
|
||||
const YFormat& lexFormat() const;
|
||||
YIndex& setFormat(const YFormat& bs);
|
||||
|
|
|
@ -139,6 +139,11 @@ namespace CNORXZ
|
|||
return 1;
|
||||
}
|
||||
|
||||
SizeT CIndex::deepMax() const
|
||||
{
|
||||
return lmax().val();
|
||||
}
|
||||
|
||||
CIndex CIndex::reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) const
|
||||
{
|
||||
CXZ_ASSERT(f.size() == 1, "expected format of dimension 1, got " << toString(f));
|
||||
|
|
|
@ -177,6 +177,11 @@ namespace CNORXZ
|
|||
return mI->deepFormat();
|
||||
}
|
||||
|
||||
Vector<SizeT> DIndex::deepMax() const
|
||||
{
|
||||
return mI->deepMax();
|
||||
}
|
||||
|
||||
DIndex DIndex::reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) const
|
||||
{
|
||||
return DIndex(mI->reformat(f,s));
|
||||
|
|
|
@ -396,6 +396,23 @@ namespace CNORXZ
|
|||
return o;
|
||||
}
|
||||
|
||||
Vector<SizeT> YIndex::deepMax() const
|
||||
{
|
||||
Vector<Vector<SizeT>> dmv(mIs.size());
|
||||
SizeT osize = 0;
|
||||
for(SizeT j = 0; j != dmv.size(); ++j){
|
||||
dmv[j] = mIs[j]->deepMax();
|
||||
osize += dmv[j].size();
|
||||
}
|
||||
Vector<SizeT> o(osize);
|
||||
SizeT off = 0;
|
||||
for(SizeT j = 0; j != dmv.size(); ++j){
|
||||
std::copy(dmv[j].begin(), dmv[j].end(), o.begin()+off);
|
||||
off += dmv[j].size();
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
YIndex YIndex::reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) const
|
||||
{
|
||||
CXZ_ASSERT(f.size() == s.size(), "input error: f.size() != s.size()");
|
||||
|
|
Loading…
Reference in a new issue