WIP: reformat
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

This commit is contained in:
Christian Zimmermann 2023-12-19 02:08:15 +01:00
parent 642381ecc0
commit 00eb2d2fb1
18 changed files with 129 additions and 9 deletions

View file

@ -107,6 +107,9 @@ namespace CNORXZ
/** @copydoc IndexInterface::deepFormat() */ /** @copydoc IndexInterface::deepFormat() */
SizeT deepFormat() const; SizeT deepFormat() const;
/** @copydoc IndexInterface::reformat() */
CIndex reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) const;
/** @copydoc IndexInterface::ifor() */ /** @copydoc IndexInterface::ifor() */
template <class Xpr, class F = NoF> template <class Xpr, class F = NoF>
decltype(auto) ifor(const Xpr& xpr, F&& f) const; decltype(auto) ifor(const Xpr& xpr, F&& f) const;

View file

@ -64,6 +64,9 @@ 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;
/** @copydoc IndexInterface::reformat() */
DIndex reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) const;
template <class Xpr, class F> template <class Xpr, class F>
decltype(auto) ifor(const Xpr& xpr, F&& f) const; decltype(auto) ifor(const Xpr& xpr, F&& f) const;

View file

@ -146,7 +146,7 @@ namespace CNORXZ
template <class I> template <class I>
Sptr<I> moveToPtr(I&& i) Sptr<I> moveToPtr(I&& i)
{ {
return std::make_shared<I>(std::forward(i)); return std::make_shared<I>(std::forward<I>(i));
} }
template <class I> template <class I>

View file

@ -173,6 +173,12 @@ 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
@param f new format
@param s new sub-index sizes
*/
decltype(auto) reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) const { return THIS().reformat(f,s); }
/** create a for-loop expression /** create a for-loop expression
@tparam Xpr loop internal expression @tparam Xpr loop internal expression

View file

@ -531,6 +531,44 @@ namespace CNORXZ
[&](const auto&... e) { return concat(e...); } ); [&](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
{
CXZ_ASSERT(f.size() == s.size(), "input error: f.size() != s.size()");
// f: input format
// s: input sizes
SizeT j = 0;
SizeT j0 = 0;
Arr<UPos,NI> nformat;
auto npack = iter<0,NI>( [&](auto i) {
SizeT si = 1;
//if(mIPack[i]->lmax().val() == 1){
//std::get<i>(npack) = mIPack[i];
//}
// CHECK!!!
// TODO: DO NOT COPY SINGLE INDEX INSTANCES!!!
for(; si < mIPack[i]->lmax().val(); ++j){
si *= s[i];
CXZ_ASSERT(j < f.size(), "incompatible index formats");
}
CXZ_ASSERT(si == mIPack[i]->lmax().val(),
"incompatible index formats: " << toString(s) << " vs " //!!!
);
Vector<SizeT> nf(j-j0);
Vector<SizeT> ns(j-j0);
std::copy(f.begin()+j0,f.begin()+j,nf.begin());
nformat[i] = *std::min_element(nf.begin(), nf.end());
std::for_each(nf.begin(), nf.end(), [&](SizeT& x)
{ 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... ); } );
GMIndex<MFormat<NI>,Indices...> oi { MFormat<NI>(nformat),SPack<Indices...>(npack) };
oi = lex();
return oi;
}
template <class FormatT, class... Indices> template <class FormatT, class... Indices>
GMIndex<FormatT,Indices...>& GMIndex<FormatT,Indices...>::setFormat(const FormatT& bs) GMIndex<FormatT,Indices...>& GMIndex<FormatT,Indices...>::setFormat(const FormatT& bs)
{ {

View file

@ -91,6 +91,10 @@ namespace CNORXZ
const auto& lexFormat() const; const auto& lexFormat() const;
RangePtr prange(const MIndex<Indices...>& last) const; RangePtr prange(const MIndex<Indices...>& last) const;
auto deepFormat() const; auto deepFormat() const;
/** @copydoc IndexInterface::reformat() */
decltype(auto) reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) const;
GMIndex& setFormat(const FormatT& bs); GMIndex& setFormat(const FormatT& bs);
/** @copydoc IndexInterface::formatIsTrivial() */ /** @copydoc IndexInterface::formatIsTrivial() */

View file

@ -167,6 +167,17 @@ namespace CNORXZ
return mOrig->deepFormat(); return mOrig->deepFormat();
} }
template <class IndexT>
PIndex<IndexT> PIndex<IndexT>::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(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;
}
template <class IndexT> template <class IndexT>
String PIndex<IndexT>::stringMeta() const String PIndex<IndexT>::stringMeta() const
{ {

View file

@ -56,6 +56,9 @@ namespace CNORXZ
RangePtr prange(const PIndex<IndexT>& last) const; RangePtr prange(const PIndex<IndexT>& last) const;
decltype(auto) deepFormat() const; decltype(auto) deepFormat() const;
/** @copydoc IndexInterface::reformat() */
PIndex reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) const;
String stringMeta() const; String stringMeta() const;
decltype(auto) meta() const; decltype(auto) meta() const;
PIndex& at(const MetaType& metaPos); PIndex& at(const MetaType& metaPos);

View file

@ -177,6 +177,17 @@ namespace CNORXZ
return 1; return 1;
} }
template <typename MetaT, SizeT S>
SIndex<MetaT,S> SIndex<MetaT,S>::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(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;
}
template <typename MetaT, SizeT S> template <typename MetaT, SizeT S>
template <class Xpr, class F> template <class Xpr, class F>
decltype(auto) SIndex<MetaT,S>::ifor(const Xpr& xpr, F&& f) const decltype(auto) SIndex<MetaT,S>::ifor(const Xpr& xpr, F&& f) const

View file

@ -62,6 +62,9 @@ namespace CNORXZ
RangePtr prange(const SIndex<MetaType,S>& last) const; RangePtr prange(const SIndex<MetaType,S>& last) const;
SizeT deepFormat() const; SizeT deepFormat() const;
/** @copydoc IndexInterface::reformat() */
SIndex reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) const;
template <class Xpr, class F> template <class Xpr, class F>
decltype(auto) ifor(const Xpr& xpr, F&& f) const; decltype(auto) ifor(const Xpr& xpr, F&& f) const;

View file

@ -163,6 +163,17 @@ namespace CNORXZ
return 1; return 1;
} }
template <typename MetaT>
UIndex<MetaT> UIndex<MetaT>::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(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;
}
template <typename MetaT> template <typename MetaT>
size_t UIndex<MetaT>::dim() const // = 1 size_t UIndex<MetaT>::dim() const // = 1
{ {

View file

@ -67,6 +67,9 @@ namespace CNORXZ
SizeT deepFormat() const; SizeT deepFormat() const;
/** @copydoc IndexInterface::reformat() */
UIndex reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) const;
template <class Xpr, class F> template <class Xpr, class F>
decltype(auto) ifor(const Xpr& xpr, F&& f) const; decltype(auto) ifor(const Xpr& xpr, F&& f) const;

View file

@ -158,6 +158,12 @@ namespace CNORXZ
return toVec( mI->deepFormat() ); return toVec( mI->deepFormat() );
} }
template <class Index, typename Meta>
XIndexPtr XIndex<Index,Meta>::reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) const
{
return xindexPtr( moveToPtr( mI->reformat(f,s) ) );
}
template <class Index, typename Meta> template <class Index, typename Meta>
String XIndex<Index,Meta>::stringMeta() const String XIndex<Index,Meta>::stringMeta() const
{ {

View file

@ -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 XIndexPtr reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) const = 0;
virtual String stringMeta() const = 0; virtual String stringMeta() const = 0;
virtual DType meta() const = 0; virtual DType meta() const = 0;
@ -104,6 +105,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 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;
virtual DType meta() const override final; virtual DType meta() const override final;

View file

@ -76,10 +76,10 @@ 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;
YIndex& setFormat(const Vector<SizeT>& f, const Vector<SizeT>& s);
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);
YIndex reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) const;
/** @copydoc IndexInterface::formatIsTrivial() */ /** @copydoc IndexInterface::formatIsTrivial() */
bool formatIsTrivial() const; bool formatIsTrivial() const;

View file

@ -139,6 +139,16 @@ namespace CNORXZ
return 1; return 1;
} }
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(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;
}
bool CIndex::formatIsTrivial() const bool CIndex::formatIsTrivial() const
{ {
return true; return true;

View file

@ -177,6 +177,11 @@ namespace CNORXZ
return mI->deepFormat(); return mI->deepFormat();
} }
DIndex DIndex::reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) const
{
return DIndex(mI->reformat(f,s));
}
bool DIndex::formatIsTrivial() const bool DIndex::formatIsTrivial() const
{ {
return true; return true;

View file

@ -396,7 +396,7 @@ namespace CNORXZ
return o; return o;
} }
YIndex& YIndex::setFormat(const Vector<SizeT>& f, const Vector<SizeT>& s) YIndex YIndex::reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) const
{ {
CXZ_ASSERT(f.size() == s.size(), "input error: f.size() != s.size()"); CXZ_ASSERT(f.size() == s.size(), "input error: f.size() != s.size()");
// f: input format // f: input format
@ -404,10 +404,11 @@ namespace CNORXZ
SizeT j = 0; SizeT j = 0;
SizeT j0 = 0; SizeT j0 = 0;
Vector<UPos> nformat(dim()); Vector<UPos> nformat(dim());
Vector<XIndexPtr> npack(dim());
for(SizeT i = 0; i != dim(); ++i){ for(SizeT i = 0; i != dim(); ++i){
SizeT si = 1; SizeT si = 1;
if(mIs[i]->lmax().val() == 1){ if(mIs[i]->lmax().val() == 1){
continue; npack[i] = mIs[i];
} }
for(; si < mIs[i]->lmax().val(); ++j){ for(; si < mIs[i]->lmax().val(); ++j){
si *= s[i]; si *= s[i];
@ -421,13 +422,13 @@ namespace CNORXZ
std::copy(f.begin()+j0,f.begin()+j,nf.begin()); std::copy(f.begin()+j0,f.begin()+j,nf.begin());
nformat[i] = *std::min_element(nf.begin(), nf.end()); nformat[i] = *std::min_element(nf.begin(), nf.end());
std::for_each(nf.begin(), nf.end(), [&](SizeT& x) std::for_each(nf.begin(), nf.end(), [&](SizeT& x)
{ CXZ_ASSERT(x % mFormat[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());
CXZ_ERROR("implement for all indices!!!"); npack[i] = mIs[i]->reformat(nf,ns);
//mIs[i]->setFormat(nf,ns);
} }
mFormat = nformat; YIndex oi ( YFormat(nformat), npack );
return *this; oi = lex();
return oi;
} }
bool YIndex::formatIsTrivial() const bool YIndex::formatIsTrivial() const