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