reformat -> formatTo/formatFrom

This commit is contained in:
Christian Zimmermann 2023-06-25 23:35:09 +02:00
parent f088ba156b
commit f1b1298c69
12 changed files with 80 additions and 17 deletions

View file

@ -221,23 +221,26 @@ namespace CNORXZ
template <class Index> template <class Index>
OpRoot<T,Index> ArrayBase<T>::operator()(const Sptr<Index>& i) OpRoot<T,Index> ArrayBase<T>::operator()(const Sptr<Index>& i)
{ {
CXZ_WARNING("FORMAT / BLOCKSIZES!!!"); //CXZ_WARNING("FORMAT / BLOCKSIZES!!!");
return oproot(*this, i); auto j = moveToPtr( begin()->reformat(i) ); // moveToPtr: keep original instance of sub indices
return oproot(*this, j);
} }
template <typename T> template <typename T>
template <class... Indices> template <class... Indices>
inline decltype(auto) ArrayBase<T>::operator()(const SPack<Indices...>& pack) inline decltype(auto) ArrayBase<T>::operator()(const SPack<Indices...>& pack)
{ {
CXZ_WARNING("FORMAT / BLOCKSIZES!!!"); //CXZ_WARNING("FORMAT / BLOCKSIZES!!!");
return oproot(*this, mindexPtr(pack)); auto j = moveToPtr( begin()->reformat(mindexPtr(pack)) );
return oproot(*this, j);
} }
template <typename T> template <typename T>
inline decltype(auto) ArrayBase<T>::operator()(const DPack& pack) inline decltype(auto) ArrayBase<T>::operator()(const DPack& pack)
{ {
CXZ_WARNING("FORMAT / BLOCKSIZES!!!"); //CXZ_WARNING("FORMAT / BLOCKSIZES!!!");
return oproot(*this, yindexPtr(pack)); auto j = moveToPtr( begin()->reformat(yindexPtr(pack)) );
return oproot(*this, j);
} }
/***************************** /*****************************

View file

@ -19,9 +19,9 @@ namespace CNORXZ
} }
template <class Index> template <class Index>
decltype(auto) CIndex::reformat(const Sptr<Index>& ind) const decltype(auto) CIndex::formatFrom(const Index& ind) const
{ {
return ind; return *this;
} }
template <class Index> template <class Index>

View file

@ -48,7 +48,7 @@ namespace CNORXZ
COpRoot<SizeT,CIndex> xpr(const Sptr<CIndex>& _this) const; COpRoot<SizeT,CIndex> xpr(const Sptr<CIndex>& _this) const;
template <class Index> template <class Index>
decltype(auto) reformat(const Sptr<Index>& ind) const; decltype(auto) formatFrom(const Index& ind) const;
template <class Index> template <class Index>
decltype(auto) slice(const Sptr<Index>& ind) const; decltype(auto) slice(const Sptr<Index>& ind) const;

View file

@ -55,8 +55,13 @@ namespace CNORXZ
I& at(const MetaType& meta) { return THIS().at(meta); } I& at(const MetaType& meta) { return THIS().at(meta); }
decltype(auto) xpr(const Sptr<I>& _this) const { return THIS().xpr(_this); } decltype(auto) xpr(const Sptr<I>& _this) const { return THIS().xpr(_this); }
//template <class Index> template <class Index>
//decltype(auto) reformat(const Sptr<Index>& ind) const { return THIS().format(ind); } decltype(auto) formatTo(const Sptr<Index>& ind) const { return ind->formatFrom(THIS()); }
template <class Index>
decltype(auto) formatFrom(const Index& ind) const // yes this is const,
// changes only MIndex/YIndex format, in this case we can just copy the pointers to the sub-index instances
{ return THIS().formatFrom(ind); }
//template <class Index> //template <class Index>
//decltype(auto) slice(const Sptr<Index>& ind) const { return THIS().slice(ind); } //decltype(auto) slice(const Sptr<Index>& ind) const { return THIS().slice(ind); }
@ -106,6 +111,10 @@ namespace CNORXZ
struct has_static_sub struct has_static_sub
{ static constexpr bool value = false; }; { static constexpr bool value = false; };
template <class I>
struct index_is_multi
{ static constexpr bool value = false; };
template <class I, typename MetaType> template <class I, typename MetaType>
IndexPtr<I,MetaType>& operator++(const IndexPtr<I,MetaType>& i); IndexPtr<I,MetaType>& operator++(const IndexPtr<I,MetaType>& i);
@ -119,6 +128,8 @@ namespace CNORXZ
template <class I, typename MetaType> template <class I, typename MetaType>
IndexPtr<I,MetaType> operator-(const IndexPtr<I,MetaType>& i, Int n); IndexPtr<I,MetaType> operator-(const IndexPtr<I,MetaType>& i, Int n);
template <class I>
Sptr<I> moveToPtr(I&& i) { return std::make_shared<I>(std::forward(i)); }
} }
#endif #endif

View file

@ -0,0 +1,18 @@
#ifndef __cxz_index_utils_h__
#define __cxz_index_utils_h__
#include "base/base.h"
#include "index_base.h"
namespace CNORXZ
{
// automatically set static format if SIndices are used!
template <class... Indices>
constexpr decltype(auto) autoiPtr(const SPack<Indices...>& pack);
inline SPtr<YIndex> autoiPtr(const DPack& pack);
}
#endif

View file

@ -383,6 +383,22 @@ namespace CNORXZ
[](const auto&... ss) { return ( ss + ... ); }); [](const auto&... ss) { return ( ss + ... ); });
} }
template <class FormatT, class... Indices>
template <class Index>
decltype(auto) GMIndex<FormatT,Indices...>::formatFrom(const Index& ind) const
{
if constexpr(index_is_multi<Index>::value){
// controll compatibility, coherent blocks etc...
// two possibilities: single index (CIndex, UIndex, DIndex)
// or multi index (MIndex,YIndex)
}
else {
// no input format, keep the original format
return *this
}
}
template <class FormatT, class... Indices> template <class FormatT, class... Indices>
String GMIndex<FormatT,Indices...>::stringMeta() const String GMIndex<FormatT,Indices...>::stringMeta() const
{ {

View file

@ -63,6 +63,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 Index>
decltype(auto) formatFrom(const Index& ind) const;
String stringMeta() const; String stringMeta() const;
MetaType meta() const; MetaType meta() const;
GMIndex& at(const MetaType& metaPos); GMIndex& at(const MetaType& metaPos);
@ -137,6 +140,10 @@ namespace CNORXZ
struct has_static_sub<MIndex<Indices...>> struct has_static_sub<MIndex<Indices...>>
{ static constexpr bool value = true; }; { static constexpr bool value = true; };
template <class... Indices>
struct index_is_multi<MIndex<Indices...>>
{ static constexpr bool value = true; };
template <class... Indices> template <class... Indices>
constexpr decltype(auto) mindex(const Sptr<Indices>&... is); constexpr decltype(auto) mindex(const Sptr<Indices>&... is);

View file

@ -143,9 +143,9 @@ namespace CNORXZ
template <typename MetaT, SizeT S> template <typename MetaT, SizeT S>
template <class Index> template <class Index>
decltype(auto) SIndex<MetaT,S>::reformat(const Sptr<Index>& ind) const decltype(auto) SIndex<MetaT,S>::formatFrom(const Index& ind) const
{ {
return ind; return *this;
} }
template <typename MetaT, SizeT S> template <typename MetaT, SizeT S>

View file

@ -49,7 +49,7 @@ namespace CNORXZ
decltype(auto) xpr(const Sptr<SIndex<MetaType,S>>& _this) const; decltype(auto) xpr(const Sptr<SIndex<MetaType,S>>& _this) const;
template <class Index> template <class Index>
decltype(auto) reformat(const Sptr<Index>& ind) const; decltype(auto) formatFrom(const Index& ind) const;
template <class Index> template <class Index>
decltype(auto) slice(const Sptr<Index>& ind) const; decltype(auto) slice(const Sptr<Index>& ind) const;

View file

@ -152,9 +152,9 @@ namespace CNORXZ
template <typename MetaType> template <typename MetaType>
template <class Index> template <class Index>
decltype(auto) UIndex<MetaType>::reformat(const Sptr<Index>& ind) const decltype(auto) UIndex<MetaType>::formatFrom(const Index& ind) const
{ {
return ind; return *this;
} }
template <typename MetaType> template <typename MetaType>

View file

@ -56,7 +56,7 @@ namespace CNORXZ
decltype(auto) xpr(const Sptr<UIndex<MetaType>>& _this) const; decltype(auto) xpr(const Sptr<UIndex<MetaType>>& _this) const;
template <class Index> template <class Index>
decltype(auto) reformat(const Sptr<Index>& ind) const; decltype(auto) formatFrom(const Index& ind) const;
template <class Index> template <class Index>
decltype(auto) slice(const Sptr<Index>& ind) const; decltype(auto) slice(const Sptr<Index>& ind) const;

View file

@ -51,6 +51,9 @@ namespace CNORXZ
Sptr<YRange> range() const; Sptr<YRange> range() const;
UPos stepSize(const IndexId<0> id) const; UPos stepSize(const IndexId<0> id) const;
template <class Index>
YIndex formatFrom(const Index& ind) const;
String stringMeta() const; String stringMeta() const;
Vector<DType> meta() const; Vector<DType> meta() const;
YIndex& at(const Vector<DType>& meta); YIndex& at(const Vector<DType>& meta);
@ -89,6 +92,10 @@ namespace CNORXZ
UPos mLMax = 0; UPos mLMax = 0;
}; };
template <>
struct index_is_multi<YIndex>
{ static constexpr bool value = true; };
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 DPack& is);
@ -150,6 +157,7 @@ namespace CNORXZ
{ {
static Sptr<YRange> func(const RangePtr& r); static Sptr<YRange> func(const RangePtr& r);
}; };
} }
#endif #endif