index reformat: apply format change to same instance (no copy)
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
This commit is contained in:
parent
62b75c01a0
commit
bf83c26a12
19 changed files with 75 additions and 82 deletions
|
@ -111,7 +111,7 @@ namespace CNORXZ
|
|||
SizeT deepMax() const;
|
||||
|
||||
/** @copydoc IndexInterface::reformat() */
|
||||
CIndex reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) const;
|
||||
CIndex& reformat(const Vector<SizeT>& f, const Vector<SizeT>& s);
|
||||
|
||||
/** @copydoc IndexInterface::ifor() */
|
||||
template <class Xpr, class F = NoF>
|
||||
|
|
|
@ -67,7 +67,7 @@ namespace CNORXZ
|
|||
Vector<SizeT> deepMax() const;
|
||||
|
||||
/** @copydoc IndexInterface::reformat() */
|
||||
DIndex reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) const;
|
||||
DIndex& reformat(const Vector<SizeT>& f, const Vector<SizeT>& s);
|
||||
|
||||
template <class Xpr, class F>
|
||||
decltype(auto) ifor(const Xpr& xpr, F&& f) const;
|
||||
|
|
|
@ -157,17 +157,6 @@ namespace CNORXZ
|
|||
return i->xpr(i);
|
||||
}
|
||||
|
||||
template <class I>
|
||||
decltype(auto) reformat(const Sptr<I>& i, const Vector<SizeT>& f, const Vector<SizeT>& s)
|
||||
{
|
||||
if constexpr(has_sub<I>::value){
|
||||
return moveToPtr( i->reformat(f,s) );
|
||||
}
|
||||
else {
|
||||
i->reformat(f,s); // checks
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -179,9 +179,8 @@ namespace CNORXZ
|
|||
/** 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); }
|
||||
I& reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) { return THIS().reformat(f,s); }
|
||||
|
||||
/** create a for-loop expression
|
||||
|
||||
|
@ -234,9 +233,6 @@ namespace CNORXZ
|
|||
template <class I>
|
||||
decltype(auto) xpr(const Sptr<I>& i);
|
||||
|
||||
// do not copy single-indices:
|
||||
template <class I>
|
||||
decltype(auto) reformat(const Sptr<I>& i, const Vector<SizeT>& f, const Vector<SizeT>& s);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -24,6 +24,8 @@ namespace CNORXZ
|
|||
class MFormat
|
||||
{
|
||||
public:
|
||||
typedef Arr<UPos,N> InputType;
|
||||
|
||||
SP_DEFAULT_MEMBERS(constexpr,MFormat);
|
||||
explicit constexpr MFormat(const Arr<UPos,N>& b);
|
||||
|
||||
|
@ -50,6 +52,8 @@ namespace CNORXZ
|
|||
class GMFormat
|
||||
{
|
||||
public:
|
||||
typedef Tuple<PosT...> InputType;
|
||||
|
||||
SP_DEFAULT_MEMBERS(constexpr,GMFormat);
|
||||
explicit constexpr GMFormat(const Tuple<PosT...>& b);
|
||||
explicit constexpr GMFormat(Tuple<PosT...>&& b);
|
||||
|
@ -78,6 +82,8 @@ namespace CNORXZ
|
|||
class YFormat
|
||||
{
|
||||
public:
|
||||
typedef Vector<UPos> InputType;
|
||||
|
||||
DEFAULT_MEMBERS(YFormat);
|
||||
explicit YFormat(const Vector<UPos>& b);
|
||||
|
||||
|
|
|
@ -539,41 +539,45 @@ namespace CNORXZ
|
|||
}
|
||||
|
||||
template <class FormatT, class... Indices>
|
||||
decltype(auto)
|
||||
GMIndex<FormatT,Indices...>::reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) const
|
||||
GMIndex<FormatT,Indices...>&
|
||||
GMIndex<FormatT,Indices...>::reformat(const Vector<SizeT>& f, const Vector<SizeT>& s)
|
||||
{
|
||||
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];
|
||||
return mIPack[i];
|
||||
}
|
||||
// CHECK!!!
|
||||
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 CNORXZ::reformat(mIPack[i],nf,ns);
|
||||
}, [](const auto&... e) { return std::make_tuple( e... ); } );
|
||||
GMIndex<MFormat<NI>,Indices...> oi { MFormat<NI>(nformat),SPack<Indices...>(npack) };
|
||||
oi = lex();
|
||||
return oi;
|
||||
if constexpr(std::is_same<FormatT,None>::value){
|
||||
CXZ_ASSERT(CNORXZ::formatIsTrivial(f,s),
|
||||
"cannot reformat MIndex with format type = None");
|
||||
return *this;
|
||||
}
|
||||
else {
|
||||
CXZ_ASSERT(f.size() == s.size(), "input error: f.size() != s.size()");
|
||||
// f: input format
|
||||
// s: input sizes
|
||||
SizeT j = 0;
|
||||
SizeT j0 = 0;
|
||||
typename FormatT::InputType nformat;
|
||||
auto npack = iter<0,NI>( [&](auto i) {
|
||||
SizeT si = 1;
|
||||
if(mIPack[i]->lmax().val() != 1){
|
||||
// CHECK!!!
|
||||
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());
|
||||
std::get<i>(nformat) = *std::min_element(nf.begin(), nf.end());
|
||||
std::for_each(nf.begin(), nf.end(), [&](SizeT& x)
|
||||
{ CXZ_ASSERT(x % std::get<i>(nformat).val() == 0, "incompatible");
|
||||
x /= std::get<i>(nformat).val(); } );
|
||||
std::copy(s.begin()+j0,s.begin()+j,ns.begin());
|
||||
mIPack[i]->reformat(nf,ns);
|
||||
}
|
||||
}, NoF {});
|
||||
mFormat = FormatT(nformat);
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
|
||||
template <class FormatT, class... Indices>
|
||||
|
|
|
@ -94,7 +94,7 @@ namespace CNORXZ
|
|||
auto deepMax() const;
|
||||
|
||||
/** @copydoc IndexInterface::reformat() */
|
||||
decltype(auto) reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) const;
|
||||
GMIndex& reformat(const Vector<SizeT>& f, const Vector<SizeT>& s);
|
||||
|
||||
GMIndex& setFormat(const FormatT& bs);
|
||||
|
||||
|
|
|
@ -174,13 +174,12 @@ namespace CNORXZ
|
|||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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]);
|
||||
CXZ_ASSERT(f[0]*s[0] == lmax().val(), "got wrong extension: " << f[0]*s[0]
|
||||
<< " vs " << lmax().val());
|
||||
CXZ_ASSERT(CNORXZ::formatIsTrivial(f,s), "format is not trivial: f = " << toString(f)
|
||||
<< ", s = " << toString(s));
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ namespace CNORXZ
|
|||
decltype(auto) deepMax() const;
|
||||
|
||||
/** @copydoc IndexInterface::reformat() */
|
||||
PIndex reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) const;
|
||||
PIndex& reformat(const Vector<SizeT>& f, const Vector<SizeT>& s);
|
||||
|
||||
String stringMeta() const;
|
||||
decltype(auto) meta() const;
|
||||
|
|
|
@ -184,7 +184,7 @@ namespace CNORXZ
|
|||
}
|
||||
|
||||
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)
|
||||
{
|
||||
CXZ_ASSERT(f[0]*s[0] == lmax().val(), "got wrong extension: " << f[0]*s[0]
|
||||
<< " vs " << lmax().val());
|
||||
|
|
|
@ -64,7 +64,7 @@ namespace CNORXZ
|
|||
SizeT deepMax() const;
|
||||
|
||||
/** @copydoc IndexInterface::reformat() */
|
||||
SIndex reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) const;
|
||||
SIndex& reformat(const Vector<SizeT>& f, const Vector<SizeT>& s);
|
||||
|
||||
template <class Xpr, class F>
|
||||
decltype(auto) ifor(const Xpr& xpr, F&& f) const;
|
||||
|
|
|
@ -170,7 +170,7 @@ namespace CNORXZ
|
|||
}
|
||||
|
||||
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)
|
||||
{
|
||||
CXZ_ASSERT(f[0]*s[0] == lmax().val(), "got wrong extension: " << f[0]*s[0]
|
||||
<< " vs " << lmax().val());
|
||||
|
|
|
@ -70,7 +70,7 @@ namespace CNORXZ
|
|||
SizeT deepMax() const;
|
||||
|
||||
/** @copydoc IndexInterface::reformat() */
|
||||
UIndex reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) const;
|
||||
UIndex& reformat(const Vector<SizeT>& f, const Vector<SizeT>& s);
|
||||
|
||||
template <class Xpr, class F>
|
||||
decltype(auto) ifor(const Xpr& xpr, F&& f) const;
|
||||
|
|
|
@ -165,9 +165,10 @@ namespace CNORXZ
|
|||
}
|
||||
|
||||
template <class Index, typename Meta>
|
||||
XIndexPtr XIndex<Index,Meta>::reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) const
|
||||
XIndex<Index,Meta>& XIndex<Index,Meta>::reformat(const Vector<SizeT>& f, const Vector<SizeT>& s)
|
||||
{
|
||||
return xindexPtr( moveToPtr( mI->reformat(f,s) ) );
|
||||
mI->reformat(f,s);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class Index, typename Meta>
|
||||
|
|
|
@ -53,7 +53,7 @@ namespace CNORXZ
|
|||
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 XIndexBase& reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) = 0;
|
||||
|
||||
virtual String stringMeta() const = 0;
|
||||
virtual DType meta() const = 0;
|
||||
|
@ -107,7 +107,7 @@ namespace CNORXZ
|
|||
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 XIndex& reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) override final;
|
||||
|
||||
virtual String stringMeta() const override final;
|
||||
virtual DType meta() const override final;
|
||||
|
|
|
@ -80,7 +80,7 @@ namespace CNORXZ
|
|||
const YFormat& format() const;
|
||||
const YFormat& lexFormat() const;
|
||||
YIndex& setFormat(const YFormat& bs);
|
||||
YIndex reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) const;
|
||||
YIndex& reformat(const Vector<SizeT>& f, const Vector<SizeT>& s);
|
||||
|
||||
/** @copydoc IndexInterface::formatIsTrivial() */
|
||||
bool formatIsTrivial() const;
|
||||
|
|
|
@ -144,7 +144,7 @@ namespace CNORXZ
|
|||
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)
|
||||
{
|
||||
CXZ_ASSERT(f[0]*s[0] == lmax().val(), "got wrong extension: " << f[0]*s[0]
|
||||
<< " vs " << lmax().val());
|
||||
|
|
|
@ -182,9 +182,10 @@ namespace CNORXZ
|
|||
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)
|
||||
{
|
||||
return DIndex(mI->reformat(f,s));
|
||||
mI->reformat(f,s);
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool DIndex::formatIsTrivial() const
|
||||
|
|
|
@ -413,27 +413,25 @@ namespace CNORXZ
|
|||
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)
|
||||
{
|
||||
CXZ_ASSERT(f.size() == s.size(), "input error: f.size() != s.size()");
|
||||
// f: input format
|
||||
// s: input sizes
|
||||
SizeT j = 0;
|
||||
SizeT j0 = 0;
|
||||
Vector<UPos> nformat(dim());
|
||||
Vector<XIndexPtr> npack(dim());
|
||||
Vector<UPos> nformat;
|
||||
for(SizeT i = 0; i != dim(); ++i){
|
||||
SizeT si = 1;
|
||||
if(mIs[i]->lmax().val() == 1){
|
||||
npack[i] = mIs[i];
|
||||
continue;
|
||||
}
|
||||
for(; si < mIs[i]->lmax().val(); ++j){
|
||||
si *= s[i];
|
||||
CXZ_ASSERT(j < f.size(), "incompatible index formats");
|
||||
}
|
||||
CXZ_ASSERT(si == mIs[i]->lmax().val(),
|
||||
"incompatible index formats: " << toString(s) << " vs " //!!!
|
||||
);
|
||||
"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());
|
||||
|
@ -441,11 +439,10 @@ namespace CNORXZ
|
|||
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());
|
||||
npack[i] = mIs[i]->reformat(nf,ns);
|
||||
mIs[i]->reformat(nf,ns);
|
||||
}
|
||||
YIndex oi ( YFormat(nformat), npack );
|
||||
oi = lex();
|
||||
return oi;
|
||||
mFormat = YFormat(nformat);
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool YIndex::formatIsTrivial() const
|
||||
|
|
Loading…
Reference in a new issue