various fixes regarding usage of Consecutive

This commit is contained in:
Christian Zimmermann 2023-06-17 21:51:37 +02:00
parent bd6f15156b
commit 17b8b79ade
13 changed files with 118 additions and 47 deletions

View file

@ -21,7 +21,7 @@ namespace CNORXZ
constexpr SizeT N = epos_size<EPosT>::value; constexpr SizeT N = epos_size<EPosT>::value;
static_assert(is_epos_type<EPosT>::value, "got non-epos-type"); static_assert(is_epos_type<EPosT>::value, "got non-epos-type");
if constexpr(pos_type_is_consecutive<EPosT>::value){ if constexpr(pos_type_is_consecutive<EPosT>::value){
return *reinterpret_cast<const Consecutive<T,N>*>(d); return *reinterpret_cast<const Consecutive<T,N>*>(d+pos.scal().val());
} }
else { else {
return vregi(d, pos, std::make_index_sequence<N>{}); return vregi(d, pos, std::make_index_sequence<N>{});
@ -35,7 +35,7 @@ namespace CNORXZ
static_assert(is_epos_type<EPosT>::value, "got non-epos-type"); static_assert(is_epos_type<EPosT>::value, "got non-epos-type");
static_assert(pos_type_is_consecutive<EPosT>::value, "no write access for non-consecutive"); static_assert(pos_type_is_consecutive<EPosT>::value, "no write access for non-consecutive");
if constexpr(pos_type_is_consecutive<EPosT>::value){ if constexpr(pos_type_is_consecutive<EPosT>::value){
return *reinterpret_cast<Consecutive<T,N>*>(d); return *reinterpret_cast<Consecutive<T,N>*>(d+pos.scal().val());
} }
else { else {
return vregi(d, pos, std::make_index_sequence<N>{}); return vregi(d, pos, std::make_index_sequence<N>{});

View file

@ -8,9 +8,14 @@
namespace CNORXZ namespace CNORXZ
{ {
template <SizeT I> template <SizeT I>
UPos CIndex::stepSize(const IndexId<I>& id) const decltype(auto) CIndex::stepSize(const IndexId<I>& id) const
{ {
return UPos(id == this->id() ? 1 : 0); if constexpr(I != 0){
return SPos<0>();
}
else {
return UPos(id == this->id() ? 1 : 0);
}
} }
template <class Index> template <class Index>

View file

@ -40,7 +40,7 @@ namespace CNORXZ
Sptr<RangeType> range() const; Sptr<RangeType> range() const;
template <SizeT I> template <SizeT I>
UPos stepSize(const IndexId<I>& id) const; decltype(auto) stepSize(const IndexId<I>& id) const;
String stringMeta() const; String stringMeta() const;
SizeT meta() const; SizeT meta() const;

View file

@ -22,7 +22,7 @@ namespace CNORXZ
template <SizeT I> template <SizeT I>
decltype(auto) LIndex<Index,L>::stepSize(const IndexId<I>& id) const decltype(auto) LIndex<Index,L>::stepSize(const IndexId<I>& id) const
{ {
if constexpr(L == 0 or I == 0){ if constexpr(L == 0 and I == 0){
return UPos(mI->id() == id ? 1 : 0); return UPos(mI->id() == id ? 1 : 0);
} }
else { else {
@ -35,6 +35,13 @@ namespace CNORXZ
} }
} }
template <class Index, SizeT L>
template <class Xpr, class F>
decltype(auto) LIndex<Index,L>::ifor(const Xpr& xpr, F&& f) const
{
return For<L,Xpr,F>(this->pmax().val(), this->id(), xpr, std::forward<F>(f));
}
template <class Index, SizeT L, class I1> template <class Index, SizeT L, class I1>
decltype(auto) operator*(const Sptr<LIndex<Index,L>>& a, const Sptr<I1>& b) decltype(auto) operator*(const Sptr<LIndex<Index,L>>& a, const Sptr<I1>& b)
{ {

View file

@ -25,6 +25,9 @@ namespace CNORXZ
template <SizeT I> template <SizeT I>
decltype(auto) stepSize(const IndexId<I>& id) const; decltype(auto) stepSize(const IndexId<I>& id) const;
template <class Xpr, class F>
decltype(auto) ifor(const Xpr& xpr, F&& f) const;
private: private:
Sptr<Index> mI; Sptr<Index> mI;
}; };

View file

@ -506,9 +506,9 @@ namespace CNORXZ
} }
template <class FormatT, class... Indices> template <class FormatT, class... Indices>
constexpr decltype(auto) gmindexPtr(const FormatT& bs, const Sptr<Indices>&... is) constexpr decltype(auto) gmindexPtr(const FormatT& bs, const SPack<Indices...>& pack)
{ {
return std::make_shared<GMIndex<FormatT,Indices...>>(bs, is...); return std::make_shared<GMIndex<FormatT,Indices...>>(bs, pack);
} }
template <class I1, class FormatT, class... Indices> template <class I1, class FormatT, class... Indices>

View file

@ -147,7 +147,7 @@ namespace CNORXZ
constexpr decltype(auto) mindexPtr(const SPack<Indices...>& pack); constexpr decltype(auto) mindexPtr(const SPack<Indices...>& pack);
template <class FormatT, class... Indices> template <class FormatT, class... Indices>
constexpr decltype(auto) gmindexPtr(const FormatT& bs, const Sptr<Indices>&... is); constexpr decltype(auto) gmindexPtr(const FormatT& bs, const SPack<Indices...>& pack);
template <class I1, class FormatT, class... Indices> template <class I1, class FormatT, class... Indices>
decltype(auto) operator*(const Sptr<GMIndex<FormatT,Indices...>>& a, const Sptr<I1>& b); decltype(auto) operator*(const Sptr<GMIndex<FormatT,Indices...>>& a, const Sptr<I1>& b);

View file

@ -140,9 +140,14 @@ namespace CNORXZ
template <typename MetaType> template <typename MetaType>
template <SizeT I> template <SizeT I>
UPos UIndex<MetaType>::stepSize(const IndexId<I>& id) const decltype(auto) UIndex<MetaType>::stepSize(const IndexId<I>& id) const
{ {
return UPos(id == this->id() ? 1 : 0); if constexpr(I != 0){
return SPos<0>();
}
else {
return UPos(id == this->id() ? 1 : 0);
}
} }
template <typename MetaType> template <typename MetaType>

View file

@ -48,7 +48,7 @@ namespace CNORXZ
Sptr<RangeType> range() const; Sptr<RangeType> range() const;
template <SizeT I> template <SizeT I>
UPos stepSize(const IndexId<I>& id) const; decltype(auto) stepSize(const IndexId<I>& id) const;
String stringMeta() const; String stringMeta() const;
const MetaT& meta() const; const MetaT& meta() const;

View file

@ -22,7 +22,7 @@ namespace CNORXZ
template <SizeT J> template <SizeT J>
constexpr decltype(auto) IndexId<I>::operator==(const IndexId<J>& a) const constexpr decltype(auto) IndexId<I>::operator==(const IndexId<J>& a) const
{ {
if constexpr(I != 0 and J != 0){ if constexpr(I != 0 or J != 0){
if constexpr(I == J){ if constexpr(I == J){
CXZ_ASSERT(mId == a.id(), CXZ_ASSERT(mId == a.id(),
"got different index ids for equal static index label"); "got different index ids for equal static index label");

View file

@ -31,6 +31,13 @@ namespace CNORXZ
return SPos<N+N1>(); return SPos<N+N1>();
} }
template <SizeT N>
template <SizeT N1>
constexpr auto SPos<N>::operator-(const SPos<N1>& a) const
{
return SPos<N-N1>();
}
template <SizeT N> template <SizeT N>
template <SizeT N1> template <SizeT N1>
constexpr auto SPos<N>::operator*(const SPos<N1>& a) const constexpr auto SPos<N>::operator*(const SPos<N1>& a) const
@ -54,13 +61,23 @@ namespace CNORXZ
template <SizeT N> template <SizeT N>
constexpr auto SPos<N>::operator*(const UPos& a) const constexpr auto SPos<N>::operator*(const UPos& a) const
{ {
return UPos(N*a.val()); if constexpr(N == 0){
return SPos<0>();
}
else {
return UPos(N*a.val());
}
} }
template <SizeT N> template <SizeT N>
constexpr auto SPos<N>::operator()(const UPos& a) const constexpr auto SPos<N>::operator()(const UPos& a) const
{ {
return UPos(N*a.val()); if constexpr(N == 0){
return SPos<0>();
}
else {
return UPos(N*a.val());
}
} }
template <SizeT N> template <SizeT N>
@ -603,7 +620,7 @@ namespace CNORXZ
return iter<0,sizeof...(OPosTs)> return iter<0,sizeof...(OPosTs)>
( [&](auto i) { return std::get<i>(mP); }, ( [&](auto i) { return std::get<i>(mP); },
[&](const auto&... e) { return EPos<decltype(BPosT::operator*(a)),OPosTs...> [&](const auto&... e) { return EPos<decltype(BPosT::operator*(a)),OPosTs...>
(BPosT::operator*(a),e...); } ); (BPosT::operator*(a),e*a...); } );
} }
template <class BPosT, class... OPosTs> template <class BPosT, class... OPosTs>
@ -613,7 +630,7 @@ namespace CNORXZ
return iter<0,sizeof...(OPosTs)> return iter<0,sizeof...(OPosTs)>
( [&](auto i) { return std::get<i>(mP); }, ( [&](auto i) { return std::get<i>(mP); },
[&](const auto&... e) { return EPos<decltype(BPosT::operator()(a)),OPosTs...> [&](const auto&... e) { return EPos<decltype(BPosT::operator()(a)),OPosTs...>
(BPosT::operator()(a),e...); } ); (BPosT::operator()(a),e*a...); } );
} }
@ -629,11 +646,17 @@ namespace CNORXZ
return inext(std::index_sequence_for<OPosTs...>{}); return inext(std::index_sequence_for<OPosTs...>{});
} }
template <class BPosT, class... OPosTs>
constexpr decltype(auto) EPos<BPosT,OPosTs...>::scal() const
{
return static_cast<const BPosT&>(*this);
}
template <class BPosT, class... OPosTs> template <class BPosT, class... OPosTs>
template <SizeT I> template <SizeT I>
constexpr decltype(auto) EPos<BPosT,OPosTs...>::get() const constexpr decltype(auto) EPos<BPosT,OPosTs...>::get() const
{ {
return std::get<I>(mP); return scal()+std::get<I>(mP);
} }
template <class BPosT, class... OPosTs> template <class BPosT, class... OPosTs>
@ -644,7 +667,7 @@ namespace CNORXZ
return std::index_sequence<std::get<Is>(mP).val()...>{}; return std::index_sequence<std::get<Is>(mP).val()...>{};
} }
else { else {
return Arr<SizeT,is.size()> { std::get<Is>(mP).val()... }; return Arr<SizeT,is.size()> { (BPosT::val()+std::get<Is>(mP).val())... };
} }
} }
@ -653,7 +676,7 @@ namespace CNORXZ
constexpr decltype(auto) EPos<BPosT,OPosTs...>::inext(std::index_sequence<Is...> is) const constexpr decltype(auto) EPos<BPosT,OPosTs...>::inext(std::index_sequence<Is...> is) const
{ {
typedef EPos<decltype(next()),decltype(std::get<Is>(mP).next())...> OEPosT; typedef EPos<decltype(next()),decltype(std::get<Is>(mP).next())...> OEPosT;
return OEPosT(next(), std::get<Is>(mP).next()...); return OEPosT(BPosT::next(), std::get<Is>(mP).next()...);
} }
/********************************* /*********************************

View file

@ -21,6 +21,8 @@ namespace CNORXZ
template <SizeT N1> template <SizeT N1>
constexpr auto operator+(const SPos<N1>& a) const; constexpr auto operator+(const SPos<N1>& a) const;
template <SizeT N1> template <SizeT N1>
constexpr auto operator-(const SPos<N1>& a) const;
template <SizeT N1>
constexpr auto operator*(const SPos<N1>& a) const; constexpr auto operator*(const SPos<N1>& a) const;
template <SizeT N1> template <SizeT N1>
constexpr auto operator()(const SPos<N1>& a) const; constexpr auto operator()(const SPos<N1>& a) const;
@ -288,6 +290,8 @@ namespace CNORXZ
constexpr decltype(auto) val() const; constexpr decltype(auto) val() const;
constexpr decltype(auto) next() const; constexpr decltype(auto) next() const;
constexpr decltype(auto) scal() const;
template <SizeT I> template <SizeT I>
constexpr decltype(auto) get() const; constexpr decltype(auto) get() const;
}; };
@ -424,6 +428,12 @@ namespace CNORXZ
static constexpr bool value = pos_types_consecutive<OPosTs...>::value; static constexpr bool value = pos_types_consecutive<OPosTs...>::value;
}; };
template <class BPosT, class NPosT>
struct pos_type_is_consecutive<MPos<BPosT,NPosT>>
{
static constexpr bool value = pos_type_is_consecutive<BPosT>::value;
};
} // end namespace CNORXZInternal } // end namespace CNORXZInternal

View file

@ -99,16 +99,17 @@ namespace
protected: protected:
typedef MIndex<CIndex,LIndex<CIndex,2>,EIndex<SizeT,4,1>> MCCI1; typedef MIndex<CIndex,LIndex<CIndex,2>,EIndex<SizeT,4,1>> MCCI1;
typedef GMIndex<GMFormat<UPos,UPos,SPos<1>>,CIndex,LIndex<CIndex,2>,EIndex<SizeT,4,1>> MCCI1x;
typedef MIndex<LIndex<CIndex,2>,EIndex<SizeT,4,1>,CIndex> MCCI2; typedef MIndex<LIndex<CIndex,2>,EIndex<SizeT,4,1>,CIndex> MCCI2;
OpCont_CR_CR_Test2() OpCont_CR_CR_Test2()
{ {
mSize1 = 12; mSize1 = 11;
mSize2 = 11; mSize2 = 12;
SizeT off = 20; SizeT off = 20;
mData1 = Numbers::get(off, mSize1); //mData1 = Numbers::get(off, mSize1);
mData2 = Numbers::get(off += mSize1 , mSize2); //mData2 = Numbers::get(off += mSize1 , mSize2);
mData11 = Numbers::get(off += mSize2, mSize1*mSize2); mData21 = Numbers::get(off += mSize2, mSize1*mSize2);
mData12 = Numbers::get(off += mSize1*mSize2, mSize1*mSize2); mData12 = Numbers::get(off += mSize1*mSize2, mSize1*mSize2);
auto cr1 = CRangeFactory(mSize1).create(); auto cr1 = CRangeFactory(mSize1).create();
auto cr2 = CRangeFactory(mSize2).create(); auto cr2 = CRangeFactory(mSize2).create();
@ -116,28 +117,31 @@ namespace
mCI1j = std::make_shared<CIndex>(cr1); mCI1j = std::make_shared<CIndex>(cr1);
mCI2i = std::make_shared<CIndex>(cr2); mCI2i = std::make_shared<CIndex>(cr2);
mCI2j = std::make_shared<CIndex>(cr2); mCI2j = std::make_shared<CIndex>(cr2);
mCC1i1j = mindexPtr(mCI1i*eplex<4,1,2>(mCI1j)); auto ipack1 = mCI1i*eplex<4,1,2>(mCI2j);
mCC1j1i = mindexPtr(eplex<4,1,2>(mCI1j)*mCI1i); auto iform1 = gmformat(UPos(mCI2j->lmax().val()),UPos(4),SPos<1>());
mOC1i1j.init(mCC1i1j); mCC1i2j = gmindexPtr( iform1, ipack1 );
mOR1j1i.init(mData11.data(), mCC1j1i); //mCC1i2j = mindexPtr(mCI1i*eplex<4,1,2>(mCI2j));
mOR1i1j.init(mData12.data(), mCC1i1j); mCC2j1i = mindexPtr(eplex<4,1,2>(mCI2j)*mCI1i);
mOC1i2j.init(mCC1i2j);
mOR2j1i.init(mData21.data(), mCC2j1i);
mOR1i2j.init(mData12.data(), mCC1i2j);
} }
SizeT mSize1; SizeT mSize1;
SizeT mSize2; SizeT mSize2;
Vector<Double> mData1;
Vector<Double> mData2;
Vector<Double> mData11;
Vector<Double> mData12; Vector<Double> mData12;
Vector<Double> mData21;
Vector<Double> mData11_1;
Vector<Double> mData11_2;
Sptr<CIndex> mCI1i; Sptr<CIndex> mCI1i;
Sptr<CIndex> mCI1j; Sptr<CIndex> mCI1j;
Sptr<CIndex> mCI2i; Sptr<CIndex> mCI2i;
Sptr<CIndex> mCI2j; Sptr<CIndex> mCI2j;
Sptr<MCCI1> mCC1i1j; Sptr<MCCI1x> mCC1i2j;
Sptr<MCCI2> mCC1j1i; Sptr<MCCI2> mCC2j1i;
OpCont<double,MCCI1> mOC1i1j; OpCont<double,MCCI1x> mOC1i2j;
COpRoot<double,MCCI2> mOR1j1i; COpRoot<double,MCCI2> mOR2j1i;
COpRoot<double,MCCI1> mOR1i1j; COpRoot<double,MCCI1x> mOR1i2j;
}; };
TEST_F(OpCont_CR_Test, Basics) TEST_F(OpCont_CR_Test, Basics)
@ -233,24 +237,38 @@ namespace
TEST_F(OpCont_CR_CR_Test2, Assignment) TEST_F(OpCont_CR_CR_Test2, Assignment)
{ {
mOC1i1j = mOR1j1i; EXPECT_EQ( mCC2j1i->stepSize( mCC1i2j->pack()[CSizeT<0>{}]->id() ).val(), 1u );
EXPECT_EQ( mCC2j1i->stepSize( mCC1i2j->pack()[CSizeT<1>{}]->id() ).val(), 44u );
EXPECT_EQ( mCC2j1i->stepSize( mCC1i2j->pack()[CSizeT<2>{}]->id() ).val(), 11u );
mOC1i2j = mOR2j1i;
for(SizeT i = 0; i != mCI1i->pmax().val(); ++i){ for(SizeT i = 0; i != mCI1i->pmax().val(); ++i){
for(SizeT j = 0; j != mCI1j->pmax().val(); ++j){ for(SizeT j = 0; j != mCI2j->pmax().val(); ++j){
const SizeT jS = mCI1j->pmax().val(); const SizeT jS = mCI2j->pmax().val();
const SizeT iS = mCI1i->pmax().val(); const SizeT iS = mCI1i->pmax().val();
EXPECT_EQ(mOC1i1j.data()[i*jS+j], mOR1j1i.data()[j*iS+i]); EXPECT_EQ(mOC1i2j.data()[i*jS+j], mOR2j1i.data()[j*iS+i]);
} }
} }
} }
TEST_F(OpCont_CR_CR_Test2, Multiply) TEST_F(OpCont_CR_CR_Test2, Multiply)
{ {
mOC1i1j = mOR1j1i * mOR1i1j; EXPECT_EQ( mCC2j1i->stepSize( mCC1i2j->pack()[CSizeT<0>{}]->id() ).val(), 1u );
EXPECT_EQ( mCC2j1i->stepSize( mCC1i2j->pack()[CSizeT<1>{}]->id() ).val(), 44u );
EXPECT_EQ( mCC2j1i->stepSize( mCC1i2j->pack()[CSizeT<2>{}]->id() ).val(), 11u );
EXPECT_EQ( mCC1i2j->stepSize( mCC1i2j->pack()[CSizeT<0>{}]->id() ).val(), 12u );
EXPECT_EQ( mCC1i2j->stepSize( mCC1i2j->pack()[CSizeT<1>{}]->id() ).val(), 4u );
EXPECT_EQ( mCC1i2j->stepSize( mCC1i2j->pack()[CSizeT<2>{}]->id() ).val(), 1u );
mOC1i2j = mOR2j1i * mOR1i2j;
for(SizeT i = 0; i != mCI1i->pmax().val(); ++i){ for(SizeT i = 0; i != mCI1i->pmax().val(); ++i){
for(SizeT j = 0; j != mCI1j->pmax().val(); ++j){ for(SizeT j = 0; j != mCI2j->pmax().val(); ++j){
const SizeT jS = mCI1j->pmax().val(); const SizeT jS = mCI2j->pmax().val();
const SizeT iS = mCI1i->pmax().val(); const SizeT iS = mCI1i->pmax().val();
EXPECT_EQ(mOC1i1j.data()[i*jS+j], mOR1j1i.data()[j*iS+i] * mOR1i1j.data()[i*jS+j]); EXPECT_EQ(mOC1i2j.data()[i*jS+j], mOR2j1i.data()[j*iS+i] * mOR1i2j.data()[i*jS+j]);
} }
} }
} }