im com...

This commit is contained in:
Christian Zimmermann 2022-12-21 22:06:17 +01:00
parent 61cef892f3
commit 16f062b069
6 changed files with 88 additions and 0 deletions

View file

@ -7,6 +7,23 @@
namespace CNORXZ namespace CNORXZ
{ {
template <class Index>
decltype(auto) CIndex::format(const Sptr<Index>& ind) const
{
return ind;
}
template <class Index>
decltype(auto) CIndex::slice(const Sptr<Index>& ind) const
{
if(ind != nullptr){
if(ind->dim() != 0) {
return Sptr<CIndex>();
}
}
return std::make_shared<CIndex>(*this);
}
template <class Xpr, class F> template <class Xpr, class F>
decltype(auto) CIndex::ifor(const Xpr& xpr, F&& f) const decltype(auto) CIndex::ifor(const Xpr& xpr, F&& f) const
{ {

View file

@ -42,6 +42,12 @@ namespace CNORXZ
SizeT meta() const; SizeT meta() const;
CIndex& at(const SizeT& metaPos); CIndex& at(const SizeT& metaPos);
template <class Index>
decltype(auto) format(const Sptr<Index>& ind) const;
template <class Index>
decltype(auto) slice(const Sptr<Index>& ind) const;
template <class Xpr, class F = NoF> template <class Xpr, class F = NoF>
decltype(auto) ifor(const Xpr& xpr, F&& f) const; decltype(auto) ifor(const Xpr& xpr, F&& f) const;

View file

@ -101,6 +101,7 @@ namespace CNORXZ
return mPtrId; return mPtrId;
} }
/**************************** /****************************
* Non-member functions * * Non-member functions *
****************************/ ****************************/

View file

@ -53,6 +53,12 @@ namespace CNORXZ
String stringMeta() const { return THIS().stringMeta(); } String stringMeta() const { return THIS().stringMeta(); }
decltype(auto) meta() const { return THIS().meta(); } decltype(auto) meta() const { return THIS().meta(); }
I& at(const MetaType& meta) { return THIS().at(meta); } I& at(const MetaType& meta) { return THIS().at(meta); }
template <class Index>
decltype(auto) format(const Sptr<Index>& ind) const { return THIS().format(ind); }
template <class Index>
decltype(auto) slice(const Sptr<Index>& ind) const { return THIS().slice(ind); }
template <class Xpr, class F = NoF> template <class Xpr, class F = NoF>
decltype(auto) ifor(const Xpr& xpr, F&& f) const decltype(auto) ifor(const Xpr& xpr, F&& f) const
@ -75,6 +81,10 @@ namespace CNORXZ
PtrId mPtrId = 0; PtrId mPtrId = 0;
}; };
template <class I>
struct is_index
{ static constexpr bool value = std::is_base_of<IndexInterface<I,typename I::MetaType>,I>::value; };
template <class I> template <class I>
struct index_has_const_size struct index_has_const_size
{ static constexpr bool value = false; }; { static constexpr bool value = false; };

View file

@ -406,6 +406,48 @@ namespace CNORXZ
return *this; return *this;
} }
template <class BlockType, class... Indices>
template <class Index>
decltype(auto) GMIndex<BlockType,Indices...>::format(const Sptr<Index>& ind) const
{
static_assert(is_index<Index>::value, "got non-index type");
static_assert(has_sub<Index>::value, "try to format single index");
if constexpr(has_static_sub<Index>::value){
static_assert(index_dim<Index>::value == NI, "got index with conflicting static dimension");
typedef std::remove_reference<decltype(ind->blockSizes())>::type BT;
return iter<0,NI>
( [&](auto i) {
std::get<i>(mIPack)->format(std::get<i>(ind->pack()));
},
[](const auto&... e) {
return std::make_shared<GMIndex<BT,Indices...>>
(mBlockSizes, e... );
} );
}
else {
typedef Arr<UPos,NI> BT;
auto pack = ind->pack();
CXZ_ASSERT(pack.size() == NI, "attempt to format index of dimension " << NI
<< " using index of dimension " << bs.size());
auto bs = ind->blockSizes();
return iter<0,NI>
( [&](auto i) {
return std::get<i>(mIPack)->format(pack[i]);
},
[](const auto&... e) {
return std::make_shared<GMIndex<BlockType,Indices...>>
(mBlockSizes, e... );
} );
}
}
template <class BlockType, class... Indices>
template <class Index>
decltype(auto) GMIndex<BlockType,Indices...>::slice(const Sptr<Index>& ind) const
{
static_assert(is_index<Index>::value, "got non-index type");
}
template <class BlockType, class... Indices> template <class BlockType, class... Indices>
template <class Xpr, class F> template <class Xpr, class F>
constexpr decltype(auto) GMIndex<BlockType,Indices...>::ifor(const Xpr& xpr, F&& f) const constexpr decltype(auto) GMIndex<BlockType,Indices...>::ifor(const Xpr& xpr, F&& f) const

View file

@ -63,6 +63,18 @@ namespace CNORXZ
MetaType meta() const; MetaType meta() const;
GMIndex& at(const MetaType& metaPos); GMIndex& at(const MetaType& metaPos);
template <class Index>
decltype(auto) format(const Sptr<Index>& ind) const;
// -> IndexInterface;
// replace index instances xor replace blockSizes of ind by that of *this
// return result as new instance
template <class Index>
decltype(auto) slice(const Sptr<Index>& ind) const;
// -> IndexInterface;
// drop index instance or drop blockSize if that if ind is Null
// return result as new instance
template <class Xpr, class F> template <class Xpr, class F>
constexpr decltype(auto) ifor(const Xpr& xpr, F&& f) const; constexpr decltype(auto) ifor(const Xpr& xpr, F&& f) const;