change operator* for index shared ptrs -> creates index packs instead of m/yindices

This commit is contained in:
Christian Zimmermann 2023-01-11 19:02:34 +01:00
parent 6bd7140ae3
commit e8c8e519dc
8 changed files with 86 additions and 62 deletions

View file

@ -104,6 +104,21 @@ namespace CNORXZ
return coproot(*this, i); return coproot(*this, i);
} }
template <typename T>
template <class... Indices>
inline decltype(auto) CArrayBase<T>::operator()(const SPack<Indices...>& pack) const
{
CXZ_WARNING("FORMAT / BLOCKSIZES!!!");
return coproot(*this, mindexPtr(pack));
}
template <typename T>
inline decltype(auto) CArrayBase<T>::operator()(const DPack& pack) const
{
CXZ_WARNING("FORMAT / BLOCKSIZES!!!");
return coproot(*this, yindexPtr(pack));
}
/****************************** /******************************
* CArrayBase (protected) * * CArrayBase (protected) *
******************************/ ******************************/
@ -210,6 +225,21 @@ namespace CNORXZ
return oproot(*this, i); return oproot(*this, i);
} }
template <typename T>
template <class... Indices>
inline decltype(auto) ArrayBase<T>::operator()(const SPack<Indices...>& pack)
{
CXZ_WARNING("FORMAT / BLOCKSIZES!!!");
return oproot(*this, mindexPtr(pack));
}
template <typename T>
inline decltype(auto) ArrayBase<T>::operator()(const DPack& pack)
{
CXZ_WARNING("FORMAT / BLOCKSIZES!!!");
return oproot(*this, yindexPtr(pack));
}
/***************************** /*****************************
* ArrayBase (protected) * * ArrayBase (protected) *
*****************************/ *****************************/

View file

@ -42,6 +42,14 @@ namespace CNORXZ
template <typename I, typename M> template <typename I, typename M>
Sptr<CArrayBase<T>> sl(const IndexInterface<I,M>& i) const; Sptr<CArrayBase<T>> sl(const IndexInterface<I,M>& i) const;
template <class Index>
COpRoot<T,Index> operator()(const Sptr<Index>& i) const;
template <class... Indices>
inline decltype(auto) operator()(const SPack<Indices...>& pack) const;
inline decltype(auto) operator()(const DPack& pack) const;
virtual const T* data() const = 0; virtual const T* data() const = 0;
virtual SizeT size() const; virtual SizeT size() const;
virtual RangePtr range() const; virtual RangePtr range() const;
@ -53,9 +61,6 @@ namespace CNORXZ
virtual bool isView() const = 0; virtual bool isView() const = 0;
template <class Index>
COpRoot<T,Index> operator()(const Sptr<Index>& i) const;
protected: protected:
RangePtr mRange; RangePtr mRange;
@ -101,6 +106,14 @@ namespace CNORXZ
T& operator[](const DPack& pack); T& operator[](const DPack& pack);
T& at(const DPack& pack); T& at(const DPack& pack);
template <class Index>
OpRoot<T,Index> operator()(const Sptr<Index>& i);
template <class... Indices>
inline decltype(auto) operator()(const SPack<Indices...>& pack);
inline decltype(auto) operator()(const DPack& pack);
template <typename I, typename M> template <typename I, typename M>
Sptr<ArrayBase<T>> sl(const IndexInterface<I,M>& i); Sptr<ArrayBase<T>> sl(const IndexInterface<I,M>& i);
@ -109,9 +122,6 @@ namespace CNORXZ
virtual iterator begin(); virtual iterator begin();
virtual iterator end(); virtual iterator end();
template <class Index>
OpRoot<T,Index> operator()(const Sptr<Index>& i);
protected: protected:
template <class Acc> template <class Acc>

View file

@ -72,6 +72,22 @@ namespace CNORXZ
return a.rmul(std::make_shared<I2>(b.THIS())); return a.rmul(std::make_shared<I2>(b.THIS()));
} }
template <class Index, class... Indices>
inline decltype(auto) operator*(const Sptr<Index>& a,
const SPack<Indices...>& b)
{
static_assert(is_index<Index>::value, "got non-index type");
return b.lmul(a);
}
template <class Index, class... Indices>
inline decltype(auto) operator*(const SPack<Indices...>& a,
const Sptr<Index>& b)
{
static_assert(is_index<Index>::value, "got non-index type");
return a.rmul(b);
}
template <class... Indices1, class... Indices2> template <class... Indices1, class... Indices2>
inline decltype(auto) operator*(const SPack<Indices1...>& a, const SPack<Indices2...>& b) inline decltype(auto) operator*(const SPack<Indices1...>& a, const SPack<Indices2...>& b)
{ {
@ -102,48 +118,13 @@ namespace CNORXZ
template <class I1, class I2> template <class I1, class I2>
decltype(auto) iptrMul(const Sptr<I1>& a, const Sptr<I2>& b) decltype(auto) iptrMul(const Sptr<I1>& a, const Sptr<I2>& b)
{ {
if constexpr(std::is_same<I1,DIndex>::value){ static_assert(is_index<I1>::value and is_index<I2>::value, "got non-index type");
if constexpr(std::is_same<I2,DIndex>::value){ if constexpr(std::is_same<I1,YIndex>::value or std::is_same<I2,YIndex>::value or
return std::make_shared<YIndex>({ a->xptr(), b->xptr() }); std::is_same<I1,DIndex>::value or std::is_same<I2,DIndex>::value) {
} return dpackp(a, b);
else if constexpr(std::is_same<I2,YIndex>::value){
auto p = b->pack();
p.insert(0, a->xptr());
return std::make_shared<YIndex>(p);
}
}
else if constexpr(std::is_same<I1,YIndex>::value){
if constexpr(std::is_same<I2,DIndex>::value){
auto p = a->pack();
p.push_back(b->xptr());
return std::make_shared<YIndex>(p);
}
else if constexpr(std::is_same<I2,YIndex>::value){
auto p = a->pack();
p.insert(p.end(), b->pack().begin(), b->pack().end());
return std::make_shared<YIndex>(p);
}
} }
else { else {
constexpr SizeT I1D = index_dim<I1>::value; return spackp(a, b);
constexpr SizeT I2D = index_dim<I2>::value;
if constexpr(I1D == 1){
if constexpr(index_dim<I2>::value == 1){
return std::make_shared<MIndex<I1,I2>>(a, b);
}
else {
return MIndexSptrMul::evalXM(a, b, std::make_index_sequence<I1D>{});
}
}
else {
if constexpr(index_dim<I2>::value == 1){
return MIndexSptrMul::evalMX(a, b, std::make_index_sequence<I2D>{});
}
else {
return MIndexSptrMul::evalMM(a, b, std::make_index_sequence<I1D>{},
std::make_index_sequence<I2D>{});
}
}
} }
} }

View file

@ -472,12 +472,6 @@ namespace CNORXZ
( bs1, e... ); } ); ( bs1, e... ); } );
} }
template <class BT1, class... Is1, class BT2, class... Is2>
decltype(auto) operator*(const Sptr<GMIndex<BT1,Is1...>>& a, const Sptr<GMIndex<BT2,Is2...>>& b)
{
return iptrMul(a, b);
}
template <class... Indices> template <class... Indices>
constexpr decltype(auto) mindex(const Sptr<Indices>&... is) constexpr decltype(auto) mindex(const Sptr<Indices>&... is)
{ {
@ -490,6 +484,12 @@ namespace CNORXZ
return MIndex<Indices...>(pack); return MIndex<Indices...>(pack);
} }
template <class... Indices>
constexpr decltype(auto) mindexPtr(const SPack<Indices...>& pack)
{
return std::make_shared<MIndex<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 Sptr<Indices>&... is)
{ {

View file

@ -105,7 +105,6 @@ namespace CNORXZ
typedef RemoveRef<decltype(mkLexFormat(mIPack,Isqr<0,NI-1>{}))> LexFormatT; typedef RemoveRef<decltype(mkLexFormat(mIPack,Isqr<0,NI-1>{}))> LexFormatT;
LexFormatT mLexFormat; LexFormatT mLexFormat;
FormatT mFormat; FormatT mFormat;
//BlockType mFormat; // -> FormatT
SizeT mLex; SizeT mLex;
typedef RemoveRef<decltype(mkLMax(mIPack))> LMaxT; typedef RemoveRef<decltype(mkLMax(mIPack))> LMaxT;
LMaxT mLMax; LMaxT mLMax;
@ -116,11 +115,6 @@ namespace CNORXZ
template <class BT1, class BT2, class... Indices> template <class BT1, class BT2, class... Indices>
decltype(auto) replaceFormat(const BT1& bs1, const Sptr<GMIndex<BT2,Indices...>>& gmi); decltype(auto) replaceFormat(const BT1& bs1, const Sptr<GMIndex<BT2,Indices...>>& gmi);
template <class BT1, class... Is1, class BT2, class... Is2>
decltype(auto) operator*(const Sptr<GMIndex<BT1,Is1...>>& a, const Sptr<GMIndex<BT2,Is2...>>& b);
//template <class... Indices>
//using MIndex = GMIndex<None,Indices...>;
template <class... Indices> template <class... Indices>
struct index_has_const_size<MIndex<Indices...>> struct index_has_const_size<MIndex<Indices...>>
{ static constexpr bool value = (index_has_const_size<Indices>::value and ...); }; { static constexpr bool value = (index_has_const_size<Indices>::value and ...); };
@ -147,6 +141,9 @@ namespace CNORXZ
template <class... Indices> template <class... Indices>
constexpr decltype(auto) mindex(const SPack<Indices...>& pack); constexpr decltype(auto) mindex(const SPack<Indices...>& pack);
template <class... Indices>
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 Sptr<Indices>&... is);

View file

@ -89,6 +89,7 @@ namespace CNORXZ
YIndex yindex(const DPack& pack); YIndex yindex(const DPack& pack);
YIndex yindex(const Vector<XIndexPtr>& is); YIndex yindex(const Vector<XIndexPtr>& is);
Sptr<YIndex> yindexPtr(const DPack& is);
Sptr<YIndex> yindexPtr(const Vector<XIndexPtr>& is); Sptr<YIndex> yindexPtr(const Vector<XIndexPtr>& is);
Sptr<YIndex> yindexPtr(const Vector<SizeT>& bs, const Vector<XIndexPtr>& is); Sptr<YIndex> yindexPtr(const Vector<SizeT>& bs, const Vector<XIndexPtr>& is);

View file

@ -392,6 +392,11 @@ namespace CNORXZ
return YIndex(is); return YIndex(is);
} }
Sptr<YIndex> yindexPtr(const DPack& pack)
{
return std::make_shared<YIndex>(pack.all());
}
Sptr<YIndex> yindexPtr(const Vector<XIndexPtr>& is) Sptr<YIndex> yindexPtr(const Vector<XIndexPtr>& is)
{ {
return std::make_shared<YIndex>(is); return std::make_shared<YIndex>(is);

View file

@ -63,8 +63,8 @@ namespace
mCIa2 = std::make_shared<CIndex>(cra); mCIa2 = std::make_shared<CIndex>(cra);
mCIb1 = std::make_shared<CIndex>(crb); mCIb1 = std::make_shared<CIndex>(crb);
mCIb2 = std::make_shared<CIndex>(crb); mCIb2 = std::make_shared<CIndex>(crb);
mCCa1a2 = mCIa1*mCIa2; mCCa1a2 = mindexPtr(mCIa1*mCIa2);
mCCa2a1 = mCIa2*mCIa1; mCCa2a1 = mindexPtr(mCIa2*mCIa1);
mOCa1a2.init(mCCa1a2); mOCa1a2.init(mCCa1a2);
mORa2a1.init(mData12.data(), mCCa2a1); mORa2a1.init(mData12.data(), mCCa2a1);
} }