WIP: todos in array operator(), operator[]
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

This commit is contained in:
Christian Zimmermann 2023-12-11 01:11:49 +01:00
parent a7c1aad6fc
commit fb8a44e88b
3 changed files with 77 additions and 37 deletions

View file

@ -31,13 +31,13 @@ namespace CNORXZ
template <typename I, typename M> template <typename I, typename M>
const T& CArrayBase<T>::operator[](const IndexInterface<I,M>& i) const const T& CArrayBase<T>::operator[](const IndexInterface<I,M>& i) const
{ {
/* if(formatIsTrivial()){
TODO: check if container format is trivial: return data()[i.lex()];
if yes, just return data[i.lex()], in case of at() check extensions }
if not, do what is done now else {
*/ auto ai = itLex(i);
auto ai = itLex(i); return *ai;
return *ai; }
} }
template <typename T> template <typename T>
@ -52,8 +52,13 @@ namespace CNORXZ
template <class... Indices> template <class... Indices>
const T& CArrayBase<T>::operator[](const SPack<Indices...>& pack) const const T& CArrayBase<T>::operator[](const SPack<Indices...>& pack) const
{ {
auto ai = itLex(pack); if(formatIsTrivial()){
return *ai; return data()[pack.lex()];
}
else {
auto ai = itLex(pack);
return *ai;
}
} }
template <typename T> template <typename T>
@ -116,32 +121,39 @@ namespace CNORXZ
template <class Index> template <class Index>
COpRoot<T,Index> CArrayBase<T>::operator()(const Sptr<Index>& i) const COpRoot<T,Index> CArrayBase<T>::operator()(const Sptr<Index>& i) const
{ {
/* if(formatIsTrivial()){
TODO: check if container format is trivial // assert that index format is trivial and has correct extensions
if yes, assert that index format is trivial and has correct extensions CXZ_ASSERT(i->formatIsTrivial(),
if not, check if index format is trivial "got non-trivial index for container with trivial format");
- if yes: try to apply container format this->checkFormatCompatibility(*i);
- if not: check if format is compatible return coproot(*this, i);
*/ }
this->checkFormatCompatibility(*i); else {
return coproot(*this, i); if(i->formatIsTrivial()){
// try to apply container format
auto aformat = begin().deepFormat();
CXZ_ERROR("IMPLEMENT " << toString(aformat));
return coproot(*this, i);
}
else {
// check if format is compatible
this->checkFormatCompatibility(*i);
return coproot(*this, i);
}
}
} }
template <typename T> template <typename T>
template <class... Indices> template <class... Indices>
inline decltype(auto) CArrayBase<T>::operator()(const SPack<Indices...>& pack) const inline decltype(auto) CArrayBase<T>::operator()(const SPack<Indices...>& pack) const
{ {
auto i = mindexPtr(pack); return operator()(mindexPtr(pack));
this->checkFormatCompatibility(*i);
return coproot(*this, i);
} }
template <typename T> template <typename T>
inline decltype(auto) CArrayBase<T>::operator()(const DPack& pack) const inline decltype(auto) CArrayBase<T>::operator()(const DPack& pack) const
{ {
auto i = yindexPtr(pack); return operator()(yindexPtr(pack));
this->checkFormatCompatibility(*i);
return coproot(*this, i);
} }
/*=================================================================+ /*=================================================================+
@ -210,8 +222,13 @@ namespace CNORXZ
template <typename I, typename M> template <typename I, typename M>
T& ArrayBase<T>::operator[](const IndexInterface<I,M>& i) T& ArrayBase<T>::operator[](const IndexInterface<I,M>& i)
{ {
auto ai = itLex(i); if(this->formatIsTrivial()){
return *ai; return data()[i.lex()];
}
else {
auto ai = itLex(i);
return *ai;
}
} }
template <typename T> template <typename T>
@ -226,8 +243,13 @@ namespace CNORXZ
template <class... Indices> template <class... Indices>
T& ArrayBase<T>::operator[](const SPack<Indices...>& pack) T& ArrayBase<T>::operator[](const SPack<Indices...>& pack)
{ {
auto ai = itLex(pack); if(this->formatIsTrivial()){
return *ai; return data()[pack.lex()];
}
else {
auto ai = itLex(pack);
return *ai;
}
} }
template <typename T> template <typename T>
@ -278,25 +300,39 @@ 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)
{ {
this->checkFormatCompatibility(*i); if(this->formatIsTrivial()){
return oproot(*this, i); // assert that index format is trivial and has correct extensions
CXZ_ASSERT(i->formatIsTrivial(),
"got non-trivial index for container with trivial format");
this->checkFormatCompatibility(*i);
return oproot(*this, i);
}
else {
if(i->formatIsTrivial()){
// try to apply container format
auto aformat = begin().deepFormat();
CXZ_ERROR("IMPLEMENT " << toString(aformat));
return oproot(*this, i);
}
else {
// check if format is compatible
this->checkFormatCompatibility(*i);
return oproot(*this, i);
}
}
} }
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)
{ {
auto i = mindexPtr(pack); return operator()(mindexPtr(pack));
this->checkFormatCompatibility(*i);
return oproot(*this, i);
} }
template <typename T> template <typename T>
inline decltype(auto) ArrayBase<T>::operator()(const DPack& pack) inline decltype(auto) ArrayBase<T>::operator()(const DPack& pack)
{ {
auto i = yindexPtr(pack); return operator()(yindexPtr(pack));
this->checkFormatCompatibility(*i);
return oproot(*this, i);
} }
/*================================================================+ /*================================================================+

View file

@ -174,7 +174,7 @@ namespace CNORXZ
void checkFormatCompatibility(const Acc& acc) const; void checkFormatCompatibility(const Acc& acc) const;
/** check if format is trivial /** check if format is trivial
@return true is container is data owning array, else return @return true if container is data owning array, else return
result of the corresponding container index result of the corresponding container index
*/ */
virtual bool formatIsTrivial() const = 0; virtual bool formatIsTrivial() const = 0;

View file

@ -18,6 +18,10 @@
namespace CNORXZ namespace CNORXZ
{ {
/** ***
Generic multi-dimensional array class
This class owns the data that can be accessed through it
**/
template <typename T> template <typename T>
class MArray : public ArrayBase<T> class MArray : public ArrayBase<T>
{ {