diff --git a/src/include/array/array_base.cc.h b/src/include/array/array_base.cc.h index 0cab6c7..90db3ce 100644 --- a/src/include/array/array_base.cc.h +++ b/src/include/array/array_base.cc.h @@ -100,7 +100,7 @@ namespace CNORXZ template COpRoot CArrayBase::operator()(const Sptr& i) const { - CXZ_WARNING("FORMAT / BLOCKSIZES!!!"); + this->checkFormatCompatibility(i->deepFormat()); return coproot(*this, i); } @@ -108,15 +108,17 @@ namespace CNORXZ template inline decltype(auto) CArrayBase::operator()(const SPack& pack) const { - CXZ_WARNING("FORMAT / BLOCKSIZES!!!"); - return coproot(*this, mindexPtr(pack)); + auto i = mindexPtr(pack); + this->checkFormatCompatibility(i->deepFormat()); + return coproot(*this, i); } template inline decltype(auto) CArrayBase::operator()(const DPack& pack) const { - CXZ_WARNING("FORMAT / BLOCKSIZES!!!"); - return coproot(*this, yindexPtr(pack)); + auto i = yindexPtr(pack); + this->checkFormatCompatibility(i->deepFormat()); + return coproot(*this, i); } /****************************** diff --git a/src/include/array/array_base.h b/src/include/array/array_base.h index 0580b15..7bec6f0 100644 --- a/src/include/array/array_base.h +++ b/src/include/array/array_base.h @@ -69,6 +69,8 @@ namespace CNORXZ template const_iterator itLexSave(const Acc& acc) const; + + void checkFormatCompatibility(const Vector& f) const { CXZ_WARNING("FORMAT / BLOCKSIZES!!!"); } }; template diff --git a/src/include/base/base.h b/src/include/base/base.h index 033801f..e6a401a 100644 --- a/src/include/base/base.h +++ b/src/include/base/base.h @@ -25,6 +25,7 @@ #include "isq.h" #include "iter.h" #include "uuid.h" +#include "utils.h" #include "config.h" #include "base.cc.h" diff --git a/src/include/base/utils.h b/src/include/base/utils.h new file mode 100644 index 0000000..8646cfa --- /dev/null +++ b/src/include/base/utils.h @@ -0,0 +1,136 @@ + +#ifndef __cxz_utils_h__ +#define __cxz_utils_h__ + +#include +#include "types.h" + +namespace CNORXZ +{ + template + Vector toVec(const Arr& a) + { + return iter<0,N>( [&](auto i) { return std::get(a); }, + [](const auto&... e) { return Vector { e... }; } ); + } + + template + Vector toVec(const Vector& a) + { + return a; + } + + template + Vector toVec(const T& a) + { + return Vector { a }; + } + + template + constexpr Arr cat2(const Arr& a1, const Arr& a2) + { + return iter<0,N1+N2> + ( [&](auto i) { if constexpr(i < N1) { return std::get(a1); } else { return std::get(a2); } }, + [](const auto&... e) { return Arr { e... }; } ); + } + + template + constexpr Arr cat2(const Arr& a1, const T& a2) + { + return iter<0,N1> + ( [&](auto i) { return std::get(a1); }, + [](const auto&... e) { return Arr { e..., a2 }; } ); + } + + template + constexpr Arr cat2(const T& a1, const Arr& a2) + { + return iter<0,N1> + ( [&](auto i) { return std::get(a2); }, + [](const auto&... e) { return Arr { a1, e... }; } ); + } + + template + constexpr Arr cat2(const T& a1, const T& a2) + { + return Arr { a1, a2 }; + } + + template + Vector cat2(const Vector& a1, const Arr& a2) + { + Vector 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 + Vector cat2(const Arr& a1, const Vector& a2) + { + Vector o(N1+a2.size()); + std::copy(a1.begin(), a1.end(), o.begin()); + std::copy(a2.begin(), a2.end(), o.begin()+N1); + return o; + } + + template + Vector cat2(const Vector& a1, const Vector& a2) + { + Vector 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 + Vector cat2(const Vector& a1, const T& a2) + { + Vector o(a1); + o.push_back(a2); + return o; + } + + template + Vector cat2(const T& a1, const Vector& a2) + { + Vector o { a1 }; + o.insert(o.end(), a2.begin(), a2.end()); + return o; + } + + template + 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 + constexpr Arr mul(const Arr& a, const T& b) + { + return iter<0,N>( [&](auto i) { return std::get(a) * b }, + [](const auto&... e) { return Arr { e... }; } ); + } + + template + Vector mul(const Vector& a, const T& b) + { + Vector o(a.size()); + std::transform(a.begin(), a.end(), o.begin(), [&](const auto& x) { return x*b; } ); + return o; + } + + template + constexpr T mul(const T& a, const T& b) + { + return a*b; + } + +} + +#endif diff --git a/src/include/ranges/crange.h b/src/include/ranges/crange.h index 913796a..6c344c0 100644 --- a/src/include/ranges/crange.h +++ b/src/include/ranges/crange.h @@ -47,6 +47,8 @@ namespace CNORXZ CIndex& at(const SizeT& metaPos); COpRoot xpr(const Sptr& _this) const; + SizeT deepFormat() const { return 1; } + template decltype(auto) formatFrom(const Index& ind) const; diff --git a/src/include/ranges/mrange.cc.h b/src/include/ranges/mrange.cc.h index 3a6801b..2a5efbc 100644 --- a/src/include/ranges/mrange.cc.h +++ b/src/include/ranges/mrange.cc.h @@ -482,8 +482,8 @@ namespace CNORXZ template auto GMIndex::deepFormat() const { - return iter<0,NI>( [&](auto i) { return std::get(mIPack)->deepFormat(); }, - [&](const auto&... e) { return (e * ...); } ); + return iter<0,NI>( [&](auto i) { return mul(std::get(mIPack)->deepFormat(), mFormat[i]); }, + [&](const auto&... e) { return concat(e, ...); } ); } template diff --git a/src/include/ranges/urange.cc.h b/src/include/ranges/urange.cc.h index c35a5e7..ebeeab5 100644 --- a/src/include/ranges/urange.cc.h +++ b/src/include/ranges/urange.cc.h @@ -126,6 +126,12 @@ namespace CNORXZ return coproot(mMetaPtr,_this); } + template + SizeT UIndex::deepFormat() const + { + return 1; + } + template size_t UIndex::dim() const // = 1 { diff --git a/src/include/ranges/urange.h b/src/include/ranges/urange.h index 78b62e5..54a1923 100644 --- a/src/include/ranges/urange.h +++ b/src/include/ranges/urange.h @@ -55,6 +55,8 @@ namespace CNORXZ UIndex& at(const MetaT& metaPos); decltype(auto) xpr(const Sptr>& _this) const; + SizeT deepFormat() const; + template decltype(auto) formatFrom(const Index& ind) const; diff --git a/src/include/ranges/xindex.cc.h b/src/include/ranges/xindex.cc.h index 6fd6601..65df9e8 100644 --- a/src/include/ranges/xindex.cc.h +++ b/src/include/ranges/xindex.cc.h @@ -126,6 +126,13 @@ namespace CNORXZ { return mI->stepSize(id); } + + template + Vector XIndex::deepFormat() const + { + return toVec( mI->deepFormat() ); + } + /* template Vector XIndex::pack() const diff --git a/src/include/ranges/xindex.h b/src/include/ranges/xindex.h index 9940b4a..93bb23d 100644 --- a/src/include/ranges/xindex.h +++ b/src/include/ranges/xindex.h @@ -38,6 +38,7 @@ namespace CNORXZ virtual SizeT dim() const = 0; virtual RangePtr range() const = 0; virtual UPos stepSize(const IndexId<0>& id) const = 0; + virtual Vector deepFormat() const = 0; //virtual Vector pack() const = 0; //virtual Vector format() const = 0; //virtual XIndexPtr setBlockSizes(const Vector& bs) = 0; @@ -91,6 +92,7 @@ namespace CNORXZ virtual SizeT dim() const override final; virtual RangePtr range() const override final; virtual UPos stepSize(const IndexId<0>& id) const override final; + virtual Vector deepFormat() const override final; //virtual Vector pack() const override final; //virtual Vector format() const override final; //virtual XIndexPtr setBlockSizes(const Vector& bs) override final; diff --git a/src/include/ranges/yrange.h b/src/include/ranges/yrange.h index 8e058ea..4104a5a 100644 --- a/src/include/ranges/yrange.h +++ b/src/include/ranges/yrange.h @@ -65,6 +65,7 @@ namespace CNORXZ YIndex& operator()(); const DPack& pack() const; + Vector deepFormat() const; const YFormat& format() const; const YFormat& lexFormat() const; YIndex& setFormat(const YFormat& bs);