im com...
This commit is contained in:
parent
61cef892f3
commit
16f062b069
6 changed files with 88 additions and 0 deletions
|
@ -7,6 +7,23 @@
|
|||
|
||||
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>
|
||||
decltype(auto) CIndex::ifor(const Xpr& xpr, F&& f) const
|
||||
{
|
||||
|
|
|
@ -42,6 +42,12 @@ namespace CNORXZ
|
|||
SizeT meta() const;
|
||||
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>
|
||||
decltype(auto) ifor(const Xpr& xpr, F&& f) const;
|
||||
|
||||
|
|
|
@ -101,6 +101,7 @@ namespace CNORXZ
|
|||
return mPtrId;
|
||||
}
|
||||
|
||||
|
||||
/****************************
|
||||
* Non-member functions *
|
||||
****************************/
|
||||
|
|
|
@ -54,6 +54,12 @@ namespace CNORXZ
|
|||
decltype(auto) meta() const { return THIS().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>
|
||||
decltype(auto) ifor(const Xpr& xpr, F&& f) const
|
||||
{ return THIS().ifor(xpr,std::forward<F>(f)); }
|
||||
|
@ -75,6 +81,10 @@ namespace CNORXZ
|
|||
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>
|
||||
struct index_has_const_size
|
||||
{ static constexpr bool value = false; };
|
||||
|
|
|
@ -406,6 +406,48 @@ namespace CNORXZ
|
|||
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 Xpr, class F>
|
||||
constexpr decltype(auto) GMIndex<BlockType,Indices...>::ifor(const Xpr& xpr, F&& f) const
|
||||
|
|
|
@ -63,6 +63,18 @@ namespace CNORXZ
|
|||
MetaType meta() const;
|
||||
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>
|
||||
constexpr decltype(auto) ifor(const Xpr& xpr, F&& f) const;
|
||||
|
||||
|
|
Loading…
Reference in a new issue