WIP: deepFormat + check format compatibility
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

This commit is contained in:
Christian Zimmermann 2023-09-08 19:18:54 +02:00
parent 1eea0e8a3f
commit b0a5b1d13f
11 changed files with 168 additions and 7 deletions

View file

@ -100,7 +100,7 @@ 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
{ {
CXZ_WARNING("FORMAT / BLOCKSIZES!!!"); this->checkFormatCompatibility(i->deepFormat());
return coproot(*this, i); return coproot(*this, i);
} }
@ -108,15 +108,17 @@ namespace CNORXZ
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
{ {
CXZ_WARNING("FORMAT / BLOCKSIZES!!!"); auto i = mindexPtr(pack);
return coproot(*this, mindexPtr(pack)); this->checkFormatCompatibility(i->deepFormat());
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
{ {
CXZ_WARNING("FORMAT / BLOCKSIZES!!!"); auto i = yindexPtr(pack);
return coproot(*this, yindexPtr(pack)); this->checkFormatCompatibility(i->deepFormat());
return coproot(*this, i);
} }
/****************************** /******************************

View file

@ -69,6 +69,8 @@ namespace CNORXZ
template <class Acc> template <class Acc>
const_iterator itLexSave(const Acc& acc) const; const_iterator itLexSave(const Acc& acc) const;
void checkFormatCompatibility(const Vector<SizeT>& f) const { CXZ_WARNING("FORMAT / BLOCKSIZES!!!"); }
}; };
template <typename T> template <typename T>

View file

@ -25,6 +25,7 @@
#include "isq.h" #include "isq.h"
#include "iter.h" #include "iter.h"
#include "uuid.h" #include "uuid.h"
#include "utils.h"
#include "config.h" #include "config.h"
#include "base.cc.h" #include "base.cc.h"

136
src/include/base/utils.h Normal file
View file

@ -0,0 +1,136 @@
#ifndef __cxz_utils_h__
#define __cxz_utils_h__
#include <cstdlib>
#include "types.h"
namespace CNORXZ
{
template <typename T, SizeT N>
Vector<T> toVec(const Arr<T,N>& a)
{
return iter<0,N>( [&](auto i) { return std::get<i>(a); },
[](const auto&... e) { return Vector<T> { e... }; } );
}
template <typename T>
Vector<T> toVec(const Vector<T>& a)
{
return a;
}
template <typename T>
Vector<T> toVec(const T& a)
{
return Vector<T> { a };
}
template <typename T, SizeT N1, SizeT N2>
constexpr Arr<T,N1+N2> cat2(const Arr<T,N1>& a1, const Arr<T,N2>& a2)
{
return iter<0,N1+N2>
( [&](auto i) { if constexpr(i < N1) { return std::get<i>(a1); } else { return std::get<i-N1>(a2); } },
[](const auto&... e) { return Arr<T,N1+N2> { e... }; } );
}
template <typename T, SizeT N1>
constexpr Arr<T,N1+1> cat2(const Arr<T,N1>& a1, const T& a2)
{
return iter<0,N1>
( [&](auto i) { return std::get<i>(a1); },
[](const auto&... e) { return Arr<T,N1+1> { e..., a2 }; } );
}
template <typename T, SizeT N1>
constexpr Arr<T,N1+1> cat2(const T& a1, const Arr<T,N1>& a2)
{
return iter<0,N1>
( [&](auto i) { return std::get<i>(a2); },
[](const auto&... e) { return Arr<T,N1+1> { a1, e... }; } );
}
template <typename T>
constexpr Arr<T,2> cat2(const T& a1, const T& a2)
{
return Arr<T,2> { a1, a2 };
}
template <typename T, SizeT N2>
Vector<T> cat2(const Vector<T>& a1, const Arr<T,N2>& a2)
{
Vector<T> o(a1.size()+N2);
std::copy(a1.begin(), a1.end(), o.begin());
std::copy(a2.begin(), a2.end(), o.begin()+a1.size());
return o;
}
template <typename T, SizeT N1>
Vector<T> cat2(const Arr<T,N1>& a1, const Vector<T>& a2)
{
Vector<T> o(N1+a2.size());
std::copy(a1.begin(), a1.end(), o.begin());
std::copy(a2.begin(), a2.end(), o.begin()+N1);
return o;
}
template <typename T>
Vector<T> cat2(const Vector<T>& a1, const Vector<T>& a2)
{
Vector<T> o(a1.size()+a2.size());
std::copy(a1.begin(), a1.end(), o.begin());
std::copy(a2.begin(), a2.end(), o.begin()+a1.size());
return o;
}
template <typename T>
Vector<T> cat2(const Vector<T>& a1, const T& a2)
{
Vector<T> o(a1);
o.push_back(a2);
return o;
}
template <typename T, SizeT N1>
Vector<T> cat2(const T& a1, const Vector<T>& a2)
{
Vector<T> o { a1 };
o.insert(o.end(), a2.begin(), a2.end());
return o;
}
template <typename T1, typename T2, typename... Ts>
decltype(auto) concat(const T1& a1, const T2& a2, const Ts&... as)
{
if constexpr(sizeof...(Ts) != 0){
return cat2(a1, concat(a2, as...));
}
else {
return cat2(a1, a2);
}
}
template <typename T, SizeT N>
constexpr Arr<T,N> mul(const Arr<T,N>& a, const T& b)
{
return iter<0,N>( [&](auto i) { return std::get<i>(a) * b },
[](const auto&... e) { return Arr<T,N> { e... }; } );
}
template <typename T>
Vector<T> mul(const Vector<T>& a, const T& b)
{
Vector<T> o(a.size());
std::transform(a.begin(), a.end(), o.begin(), [&](const auto& x) { return x*b; } );
return o;
}
template <typename T>
constexpr T mul(const T& a, const T& b)
{
return a*b;
}
}
#endif

View file

@ -47,6 +47,8 @@ namespace CNORXZ
CIndex& at(const SizeT& metaPos); CIndex& at(const SizeT& metaPos);
COpRoot<SizeT,CIndex> xpr(const Sptr<CIndex>& _this) const; COpRoot<SizeT,CIndex> xpr(const Sptr<CIndex>& _this) const;
SizeT deepFormat() const { return 1; }
template <class Index> template <class Index>
decltype(auto) formatFrom(const Index& ind) const; decltype(auto) formatFrom(const Index& ind) const;

View file

@ -482,8 +482,8 @@ namespace CNORXZ
template <class FormatT, class... Indices> template <class FormatT, class... Indices>
auto GMIndex<FormatT,Indices...>::deepFormat() const auto GMIndex<FormatT,Indices...>::deepFormat() const
{ {
return iter<0,NI>( [&](auto i) { return std::get<i>(mIPack)->deepFormat(); }, return iter<0,NI>( [&](auto i) { return mul(std::get<i>(mIPack)->deepFormat(), mFormat[i]); },
[&](const auto&... e) { return (e * ...); } ); [&](const auto&... e) { return concat(e, ...); } );
} }
template <class FormatT, class... Indices> template <class FormatT, class... Indices>

View file

@ -126,6 +126,12 @@ namespace CNORXZ
return coproot(mMetaPtr,_this); return coproot(mMetaPtr,_this);
} }
template <typename MetaType>
SizeT UIndex<MetaType>::deepFormat() const
{
return 1;
}
template <typename MetaType> template <typename MetaType>
size_t UIndex<MetaType>::dim() const // = 1 size_t UIndex<MetaType>::dim() const // = 1
{ {

View file

@ -55,6 +55,8 @@ namespace CNORXZ
UIndex& at(const MetaT& metaPos); UIndex& at(const MetaT& metaPos);
decltype(auto) xpr(const Sptr<UIndex<MetaType>>& _this) const; decltype(auto) xpr(const Sptr<UIndex<MetaType>>& _this) const;
SizeT deepFormat() const;
template <class Index> template <class Index>
decltype(auto) formatFrom(const Index& ind) const; decltype(auto) formatFrom(const Index& ind) const;

View file

@ -126,6 +126,13 @@ namespace CNORXZ
{ {
return mI->stepSize(id); return mI->stepSize(id);
} }
template <class Index, typename Meta>
Vector<SizeT> XIndex<Index,Meta>::deepFormat() const
{
return toVec( mI->deepFormat() );
}
/* /*
template <class Index, typename Meta> template <class Index, typename Meta>
Vector<XIndexPtr> XIndex<Index,Meta>::pack() const Vector<XIndexPtr> XIndex<Index,Meta>::pack() const

View file

@ -38,6 +38,7 @@ namespace CNORXZ
virtual SizeT dim() const = 0; virtual SizeT dim() const = 0;
virtual RangePtr range() const = 0; virtual RangePtr range() const = 0;
virtual UPos stepSize(const IndexId<0>& id) const = 0; virtual UPos stepSize(const IndexId<0>& id) const = 0;
virtual Vector<SizeT> deepFormat() const = 0;
//virtual Vector<XIndexPtr> pack() const = 0; //virtual Vector<XIndexPtr> pack() const = 0;
//virtual Vector<SizeT> format() const = 0; //virtual Vector<SizeT> format() const = 0;
//virtual XIndexPtr setBlockSizes(const Vector<SizeT>& bs) = 0; //virtual XIndexPtr setBlockSizes(const Vector<SizeT>& bs) = 0;
@ -91,6 +92,7 @@ namespace CNORXZ
virtual SizeT dim() const override final; virtual SizeT dim() const override final;
virtual RangePtr range() const override final; virtual RangePtr range() const override final;
virtual UPos stepSize(const IndexId<0>& id) const override final; virtual UPos stepSize(const IndexId<0>& id) const override final;
virtual Vector<SizeT> deepFormat() const override final;
//virtual Vector<XIndexPtr> pack() const override final; //virtual Vector<XIndexPtr> pack() const override final;
//virtual Vector<SizeT> format() const override final; //virtual Vector<SizeT> format() const override final;
//virtual XIndexPtr setBlockSizes(const Vector<SizeT>& bs) override final; //virtual XIndexPtr setBlockSizes(const Vector<SizeT>& bs) override final;

View file

@ -65,6 +65,7 @@ namespace CNORXZ
YIndex& operator()(); YIndex& operator()();
const DPack& pack() const; const DPack& pack() const;
Vector<SizeT> deepFormat() const;
const YFormat& format() const; const YFormat& format() const;
const YFormat& lexFormat() const; const YFormat& lexFormat() const;
YIndex& setFormat(const YFormat& bs); YIndex& setFormat(const YFormat& bs);