This commit is contained in:
parent
bf83c26a12
commit
c72fbc329d
5 changed files with 66 additions and 8 deletions
|
@ -39,6 +39,13 @@ namespace CNORXZ
|
|||
return DXpr<R>( bufxpr([&](auto x){ return mI->ifor( DXpr<None>( assignxpr(x, xpr) ), NoF {} ); }) );
|
||||
}
|
||||
}
|
||||
|
||||
template <class I>
|
||||
I indexAs(const DIndex& i)
|
||||
{
|
||||
static_assert(is_index<I>::value, "expected index type");
|
||||
return std::dynamic_pointer_cast<XIndex<I,typename I::MetaType>>( i.xptr() )->get();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -73,7 +73,7 @@ namespace CNORXZ
|
|||
decltype(auto) ifor(const Xpr& xpr, F&& f) const;
|
||||
|
||||
const XIndexPtr& xptr() const;
|
||||
|
||||
|
||||
/** @copydoc IndexInterface::formatIsTrivial() */
|
||||
bool formatIsTrivial() const;
|
||||
|
||||
|
@ -84,6 +84,9 @@ namespace CNORXZ
|
|||
template <>
|
||||
struct has_sub<DIndex>
|
||||
{ static constexpr bool value = true; };
|
||||
|
||||
template <class I>
|
||||
I indexAs(const DIndex& i);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -30,8 +30,8 @@ namespace CNORXZ
|
|||
template <class FormatT>
|
||||
constexpr MFormat<N>::MFormat(const FormatT& f)
|
||||
{
|
||||
static_assert(f.size() == N, "try to assign format of wrong dimension");
|
||||
iter<0,N>( [&](auto i) { mB[i] = f[i]; }, NoF{} );
|
||||
CXZ_ASSERT(f.size() == N, "try to assign format of wrong dimension");
|
||||
iter<0,N>( [&](auto i) { mB[i] = f[i].val(); }, NoF{} );
|
||||
}
|
||||
|
||||
template <SizeT N>
|
||||
|
|
|
@ -187,6 +187,9 @@ namespace CNORXZ
|
|||
mLMax(mkLMax(mIPack)),
|
||||
mPMax(mkPMax(mIPack,mFormat))
|
||||
{
|
||||
if constexpr(not std::is_same<None,FormatT>::value){
|
||||
mFormat = mLexFormat;
|
||||
}
|
||||
mkPos();
|
||||
}
|
||||
|
||||
|
@ -213,6 +216,9 @@ namespace CNORXZ
|
|||
mLMax(mkLMax(mIPack)),
|
||||
mPMax(mkPMax(mIPack,mFormat))
|
||||
{
|
||||
if constexpr(not std::is_same<None,FormatT>::value){
|
||||
mFormat = mLexFormat;
|
||||
}
|
||||
mkPos();
|
||||
}
|
||||
|
||||
|
@ -240,6 +246,9 @@ namespace CNORXZ
|
|||
mLMax(mkLMax(mIPack)),
|
||||
mPMax(mkPMax(mIPack,mFormat))
|
||||
{
|
||||
if constexpr(not std::is_same<None,FormatT>::value){
|
||||
mFormat = mLexFormat;
|
||||
}
|
||||
*this = lexpos;
|
||||
}
|
||||
|
||||
|
@ -364,7 +373,7 @@ namespace CNORXZ
|
|||
template <class FormatT, class... Indices>
|
||||
constexpr decltype(auto) GMIndex<FormatT,Indices...>::lmax() const
|
||||
{
|
||||
return mPMax;
|
||||
return mLMax;
|
||||
}
|
||||
|
||||
template <class FormatT, class... Indices>
|
||||
|
@ -554,7 +563,13 @@ namespace CNORXZ
|
|||
SizeT j = 0;
|
||||
SizeT j0 = 0;
|
||||
typename FormatT::InputType nformat;
|
||||
auto npack = iter<0,NI>( [&](auto i) {
|
||||
auto mkFv = [&]() {
|
||||
Vector<SizeT> o(NI);
|
||||
SizeT i = 0;
|
||||
for(const auto& y:mFormat.all()) { o[i++] = y.val(); }
|
||||
return o;
|
||||
};
|
||||
iter<0,NI>( [&](auto i) {
|
||||
SizeT si = 1;
|
||||
if(mIPack[i]->lmax().val() != 1){
|
||||
// CHECK!!!
|
||||
|
@ -563,7 +578,9 @@ namespace CNORXZ
|
|||
CXZ_ASSERT(j < f.size(), "incompatible index formats");
|
||||
}
|
||||
CXZ_ASSERT(si == mIPack[i]->lmax().val(),
|
||||
"incompatible index formats: " << toString(s) << " vs " /*!!!*/);
|
||||
"incompatible index formats: " << toString(f) << " vs "
|
||||
<< toString(mkFv()) << " ( " << si << " != "
|
||||
<< mIPack[i]->lmax().val() << " ) ");
|
||||
Vector<SizeT> nf(j-j0);
|
||||
Vector<SizeT> ns(j-j0);
|
||||
std::copy(f.begin()+j0,f.begin()+j,nf.begin());
|
||||
|
|
|
@ -28,19 +28,24 @@ namespace
|
|||
auto mr105 = mrange(ur3x,ur7x,cr5x);
|
||||
auto cr11 = CRangeFactory(11).create();
|
||||
auto cr13 = CRangeFactory(13).create();
|
||||
auto cr17 = CRangeFactory(17).create();
|
||||
mRange = yrange({cr11,mr105,cr13,sr2});
|
||||
mRange2 = yrange({cr11,mr105,cr13,cr17,sr2});
|
||||
}
|
||||
|
||||
Vector<String> mMeta7;
|
||||
RangePtr mRange;
|
||||
RangePtr mRange2;
|
||||
};
|
||||
|
||||
TEST_F(Format_Test, RangeCheck)
|
||||
{
|
||||
EXPECT_EQ(mRange->size(), 2*105*11*13);
|
||||
EXPECT_EQ(mRange2->size(), 2*105*11*13*17);
|
||||
auto yi = mRange->begin();
|
||||
EXPECT_EQ(yi.lmax().val(), mRange->size());
|
||||
EXPECT_EQ(yi.pmax().val(), mRange->size());
|
||||
EXPECT_EQ(mRange->dim(), 4u);
|
||||
}
|
||||
|
||||
TEST_F(Format_Test, CFormat)
|
||||
|
@ -48,9 +53,35 @@ namespace
|
|||
CIndex ci(mRange);
|
||||
EXPECT_EQ(ci.lmax().val(), mRange->size());
|
||||
auto yi = mRange->begin();
|
||||
auto rfi = ci.reformat( yi.deepFormat(), yi.deepMax() );
|
||||
auto yi2 = mRange2->begin();
|
||||
ci.reformat( yi.deepFormat(), yi.deepMax() );
|
||||
VCHECK(toString(yi.deepFormat()));
|
||||
VCHECK(toString(yi.deepMax()));
|
||||
EXPECT_EQ(rfi.lmax().val(), mRange->size());
|
||||
VCHECK(toString(yi2.deepFormat()));
|
||||
VCHECK(toString(yi2.deepMax()));
|
||||
EXPECT_EQ(ci.lmax().val(), mRange->size());
|
||||
}
|
||||
|
||||
TEST_F(Format_Test, XFormat)
|
||||
{
|
||||
GMIndex<MFormat<4>,CIndex,CIndex,CIndex,CIndex> mi(mRange);
|
||||
MIndex<CIndex,CIndex,CIndex,CIndex,CIndex> mi2(mRange2);
|
||||
EXPECT_EQ(mi.lmax().val(), mRange->size());
|
||||
EXPECT_EQ(mi2.lmax().val(), mRange2->size());
|
||||
auto yi = indexAs<YIndex>( mRange->begin() );
|
||||
mi.reformat( yi.deepFormat(), yi.deepMax() );
|
||||
EXPECT_EQ(mi.lmax().val(), mRange->size());
|
||||
VCHECK(toString(mi.deepFormat()));
|
||||
VCHECK(toString(mi.deepMax()));
|
||||
VCHECK(toString(mi2.deepFormat()));
|
||||
VCHECK(toString(mi2.deepMax()));
|
||||
|
||||
|
||||
yi.setFormat( YFormat( Vector<SizeT>{ mi2.format()[CSizeT<0>{}].val(), mi2.format()[CSizeT<1>{}].val(), mi2.format()[CSizeT<2>{}].val(), mi2.format()[CSizeT<4>{}].val() } ) );
|
||||
VCHECK(toString(yi.deepFormat()));
|
||||
|
||||
mi.reformat( yi.deepFormat(), yi.deepMax() );
|
||||
VCHECK(toString(mi.deepFormat()));
|
||||
VCHECK(toString(mi.deepMax()));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue