This commit is contained in:
parent
642381ecc0
commit
00eb2d2fb1
18 changed files with 129 additions and 9 deletions
|
@ -107,6 +107,9 @@ namespace CNORXZ
|
|||
/** @copydoc IndexInterface::deepFormat() */
|
||||
SizeT deepFormat() const;
|
||||
|
||||
/** @copydoc IndexInterface::reformat() */
|
||||
CIndex reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) const;
|
||||
|
||||
/** @copydoc IndexInterface::ifor() */
|
||||
template <class Xpr, class F = NoF>
|
||||
decltype(auto) ifor(const Xpr& xpr, F&& f) const;
|
||||
|
|
|
@ -64,6 +64,9 @@ namespace CNORXZ
|
|||
DIndex& at(const DType& meta);
|
||||
RangePtr prange(const DIndex& end) const;
|
||||
Vector<SizeT> deepFormat() const;
|
||||
|
||||
/** @copydoc IndexInterface::reformat() */
|
||||
DIndex reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) const;
|
||||
|
||||
template <class Xpr, class F>
|
||||
decltype(auto) ifor(const Xpr& xpr, F&& f) const;
|
||||
|
|
|
@ -146,7 +146,7 @@ namespace CNORXZ
|
|||
template <class 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>
|
||||
|
|
|
@ -173,6 +173,12 @@ namespace CNORXZ
|
|||
/** recursive index format */
|
||||
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
|
||||
|
||||
@tparam Xpr loop internal expression
|
||||
|
|
|
@ -531,6 +531,44 @@ namespace CNORXZ
|
|||
[&](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>
|
||||
GMIndex<FormatT,Indices...>& GMIndex<FormatT,Indices...>::setFormat(const FormatT& bs)
|
||||
{
|
||||
|
|
|
@ -91,6 +91,10 @@ namespace CNORXZ
|
|||
const auto& lexFormat() const;
|
||||
RangePtr prange(const MIndex<Indices...>& last) const;
|
||||
auto deepFormat() const;
|
||||
|
||||
/** @copydoc IndexInterface::reformat() */
|
||||
decltype(auto) reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) const;
|
||||
|
||||
GMIndex& setFormat(const FormatT& bs);
|
||||
|
||||
/** @copydoc IndexInterface::formatIsTrivial() */
|
||||
|
|
|
@ -167,6 +167,17 @@ namespace CNORXZ
|
|||
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>
|
||||
String PIndex<IndexT>::stringMeta() const
|
||||
{
|
||||
|
|
|
@ -56,6 +56,9 @@ namespace CNORXZ
|
|||
RangePtr prange(const PIndex<IndexT>& last) const;
|
||||
decltype(auto) deepFormat() const;
|
||||
|
||||
/** @copydoc IndexInterface::reformat() */
|
||||
PIndex reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) const;
|
||||
|
||||
String stringMeta() const;
|
||||
decltype(auto) meta() const;
|
||||
PIndex& at(const MetaType& metaPos);
|
||||
|
|
|
@ -177,6 +177,17 @@ namespace CNORXZ
|
|||
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 <class Xpr, class F>
|
||||
decltype(auto) SIndex<MetaT,S>::ifor(const Xpr& xpr, F&& f) const
|
||||
|
|
|
@ -62,6 +62,9 @@ namespace CNORXZ
|
|||
RangePtr prange(const SIndex<MetaType,S>& last) const;
|
||||
SizeT deepFormat() const;
|
||||
|
||||
/** @copydoc IndexInterface::reformat() */
|
||||
SIndex reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) const;
|
||||
|
||||
template <class Xpr, class F>
|
||||
decltype(auto) ifor(const Xpr& xpr, F&& f) const;
|
||||
|
||||
|
|
|
@ -163,6 +163,17 @@ namespace CNORXZ
|
|||
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>
|
||||
size_t UIndex<MetaT>::dim() const // = 1
|
||||
{
|
||||
|
|
|
@ -67,6 +67,9 @@ namespace CNORXZ
|
|||
|
||||
SizeT deepFormat() const;
|
||||
|
||||
/** @copydoc IndexInterface::reformat() */
|
||||
UIndex reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) const;
|
||||
|
||||
template <class Xpr, class F>
|
||||
decltype(auto) ifor(const Xpr& xpr, F&& f) const;
|
||||
|
||||
|
|
|
@ -158,6 +158,12 @@ namespace CNORXZ
|
|||
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>
|
||||
String XIndex<Index,Meta>::stringMeta() 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 XIndexPtr reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) const = 0;
|
||||
|
||||
virtual String stringMeta() const = 0;
|
||||
virtual DType meta() const = 0;
|
||||
|
@ -104,6 +105,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 XIndexPtr reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) const override final;
|
||||
|
||||
virtual String stringMeta() const override final;
|
||||
virtual DType meta() const override final;
|
||||
|
|
|
@ -76,10 +76,10 @@ namespace CNORXZ
|
|||
const DPack& pack() const;
|
||||
RangePtr prange(const YIndex& last) const;
|
||||
Vector<SizeT> deepFormat() const;
|
||||
YIndex& setFormat(const Vector<SizeT>& f, const Vector<SizeT>& s);
|
||||
const YFormat& format() const;
|
||||
const YFormat& lexFormat() const;
|
||||
YIndex& setFormat(const YFormat& bs);
|
||||
YIndex reformat(const Vector<SizeT>& f, const Vector<SizeT>& s) const;
|
||||
|
||||
/** @copydoc IndexInterface::formatIsTrivial() */
|
||||
bool formatIsTrivial() const;
|
||||
|
|
|
@ -139,6 +139,16 @@ namespace CNORXZ
|
|||
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
|
||||
{
|
||||
return true;
|
||||
|
|
|
@ -177,6 +177,11 @@ namespace CNORXZ
|
|||
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
|
||||
{
|
||||
return true;
|
||||
|
|
|
@ -396,7 +396,7 @@ namespace CNORXZ
|
|||
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()");
|
||||
// f: input format
|
||||
|
@ -404,10 +404,11 @@ namespace CNORXZ
|
|||
SizeT j = 0;
|
||||
SizeT j0 = 0;
|
||||
Vector<UPos> nformat(dim());
|
||||
Vector<XIndexPtr> npack(dim());
|
||||
for(SizeT i = 0; i != dim(); ++i){
|
||||
SizeT si = 1;
|
||||
if(mIs[i]->lmax().val() == 1){
|
||||
continue;
|
||||
npack[i] = mIs[i];
|
||||
}
|
||||
for(; si < mIs[i]->lmax().val(); ++j){
|
||||
si *= s[i];
|
||||
|
@ -421,13 +422,13 @@ namespace CNORXZ
|
|||
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 % 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());
|
||||
CXZ_ERROR("implement for all indices!!!");
|
||||
//mIs[i]->setFormat(nf,ns);
|
||||
npack[i] = mIs[i]->reformat(nf,ns);
|
||||
}
|
||||
mFormat = nformat;
|
||||
return *this;
|
||||
YIndex oi ( YFormat(nformat), npack );
|
||||
oi = lex();
|
||||
return oi;
|
||||
}
|
||||
|
||||
bool YIndex::formatIsTrivial() const
|
||||
|
|
Loading…
Reference in a new issue