mrange: zip; todo: for all other index types

This commit is contained in:
Christian Zimmermann 2022-12-14 01:48:17 +01:00
parent 6963dd82cd
commit 0fbd2d6f5b
3 changed files with 48 additions and 1 deletions

View file

@ -434,6 +434,50 @@ namespace CNORXZ
return mIPack; return mIPack;
} }
template <class BlockType, class... Indices>
template <class Index, class F, class G>
constexpr decltype(auto) GMIndex<BlockType,Indices...>::zip(const Index& ind, const F& f, const G& g) const
{
static_assert(is_index<Index>::value, "got non-index type");
if constexpr(has_static_sub<Index>::value){
static_assert(index_dim<Index>::value == NI,
"got static-dimensional index with wrong dimension");
if constexpr(std::is_same<G,NoF>::value or std::is_same<F,NoF>::value){
iter<0,NI>( [&](auto i) { return std::get<i>(mIPack)->zip(*std::get<i>(ind.pack()), f); },
NoF {} );
f(*this, ind);
return;
}
else {
return iter<0,NI>( [&](auto i) { return std::get<i>(mIPack)->zip(*std::get<i>(ind.pack()), f); },
[](auto... e) { return g(std::make_tuple(e...), f(*this, ind)); } );
}
}
else if constexpr(has_sub<Index>::value){
CXZ_ASSERT(ind.dim() == NI, "got index with wrong dimension = " << ind.dim()
<< ", expected: " << NI);
if constexpr(std::is_same<G,NoF>::value or std::is_same<F,NoF>::value){
iter<0,NI>( [&](auto i) { return std::get<i>(mIPack)->zip(*ind.pack()[i],f); },
NoF {} );
f(*this, ind);
return;
}
else {
return iter<0,NI>( [&](auto i) { return std::get<i>(mIPack)->zip(*ind.pack()[i],f); },
[](auto... e) { return g(std::make_tuple(e...), f(*this, ind)); } );
}
}
else {
if constexpr(std::is_same<F,NoF>::value){
f(*this, ind);
return;
}
else {
return f(*this, ind);
}
}
}
template <class BlockType, class... Indices> template <class BlockType, class... Indices>
const auto& GMIndex<BlockType,Indices...>::blockSizes() const const auto& GMIndex<BlockType,Indices...>::blockSizes() const
{ {

View file

@ -70,6 +70,9 @@ namespace CNORXZ
GMIndex& operator()(const Sptr<MIndex<Indices...>>& mi); GMIndex& operator()(const Sptr<MIndex<Indices...>>& mi);
GMIndex& operator()(); GMIndex& operator()();
template <class Index, class F = NoF, class G = NoF>
constexpr decltype(auto) zip(const Index& ind, const F& f, const G& g) const; // also non-const version !!!
const IndexPack& pack() const; const IndexPack& pack() const;
const auto& blockSizes() const; const auto& blockSizes() const;
const auto& lexBlockSizes() const; const auto& lexBlockSizes() const;