index: remove xpr() from base type + add trait to check if expression is available
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
This commit is contained in:
parent
eee1805f88
commit
129c27a28d
17 changed files with 170 additions and 65 deletions
4
TODO
4
TODO
|
@ -10,13 +10,9 @@ include/ranges/index_base.cc.h@110: "if this assert never applies, remove mPtrId
|
||||||
include/ranges/mrange.cc.h@633: "TODO: ZRange (meta and index pos static!)" [long]
|
include/ranges/mrange.cc.h@633: "TODO: ZRange (meta and index pos static!)" [long]
|
||||||
include/ranges/urange.cc.h@366: "else general transform using DType (better than nothing), to be implemented" [urgent]
|
include/ranges/urange.cc.h@366: "else general transform using DType (better than nothing), to be implemented" [urgent]
|
||||||
include/ranges/urange.cc.h@430: "else general transform using DType (better than nothing), to be implemented" [urgent]
|
include/ranges/urange.cc.h@430: "else general transform using DType (better than nothing), to be implemented" [urgent]
|
||||||
include/ranges/prange.cc.h@193: "implement" [urgent]
|
|
||||||
include/ranges/prange.cc.h@325: "implement" [urgent]
|
|
||||||
include/ranges/xindex.cc.h@183: "IMPLEMENT" [urgent]
|
|
||||||
include/xpr/for.cc.h@314: "check for write access" [check]
|
include/xpr/for.cc.h@314: "check for write access" [check]
|
||||||
include/ranges/srange.cc.h@292: "TODO: check for selected static sizes of SRange -> return SRange" [long]
|
include/ranges/srange.cc.h@292: "TODO: check for selected static sizes of SRange -> return SRange" [long]
|
||||||
lib/ranges/crange.cc@114: "preliminary solution (TODO: implement xpr that simply returns PosT value)" [long]
|
lib/ranges/crange.cc@114: "preliminary solution (TODO: implement xpr that simply returns PosT value)" [long]
|
||||||
lib/ranges/yrange.cc@348: "IMPLEMENT" [urgent]
|
|
||||||
|
|
||||||
opt/hdf5/lib/h5_group.cc@166: "IMPLEMENT" [urgent]
|
opt/hdf5/lib/h5_group.cc@166: "IMPLEMENT" [urgent]
|
||||||
opt/hdf5/include/h5_group.cc.h@34: "not implemented" [urgent]
|
opt/hdf5/include/h5_group.cc.h@34: "not implemented" [urgent]
|
||||||
|
|
|
@ -215,6 +215,16 @@ namespace CNORXZ
|
||||||
/** cast the range */
|
/** cast the range */
|
||||||
static Sptr<CRange> func(const RangePtr& r);
|
static Sptr<CRange> func(const RangePtr& r);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** ***
|
||||||
|
CIndex can be used as expression
|
||||||
|
@see index_expression_exists
|
||||||
|
*/
|
||||||
|
template <>
|
||||||
|
struct index_expression_exists<CIndex>
|
||||||
|
{
|
||||||
|
static constexpr bool value = true;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -62,12 +62,9 @@ namespace CNORXZ
|
||||||
String stringMeta() const;
|
String stringMeta() const;
|
||||||
DType meta() const;
|
DType meta() const;
|
||||||
DIndex& at(const DType& meta);
|
DIndex& at(const DType& meta);
|
||||||
DXpr<SizeT> xpr(const Sptr<DIndex>& _this) const;
|
|
||||||
RangePtr prange(const DIndex& end) const;
|
RangePtr prange(const DIndex& end) const;
|
||||||
Vector<SizeT> deepFormat() const;
|
Vector<SizeT> deepFormat() const;
|
||||||
|
|
||||||
//DXpr<None> ifor(const DXpr<None>& xpr, NoF&& f) const;
|
|
||||||
|
|
||||||
template <class Xpr, class F>
|
template <class Xpr, class F>
|
||||||
decltype(auto) ifor(const Xpr& xpr, F&& f) const;
|
decltype(auto) ifor(const Xpr& xpr, F&& f) const;
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,16 @@ namespace CNORXZ
|
||||||
static constexpr bool value = true;
|
static constexpr bool value = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** ***
|
||||||
|
EIndex can be used as expression
|
||||||
|
@see index_expression_exists
|
||||||
|
*/
|
||||||
|
template <typename MetaT, SizeT S, SizeT L>
|
||||||
|
struct index_expression_exists<EIndex<MetaT,S,L>>
|
||||||
|
{
|
||||||
|
static constexpr bool value = true;
|
||||||
|
};
|
||||||
|
|
||||||
template <typename MetaT, SizeT S, SizeT L, class I1>
|
template <typename MetaT, SizeT S, SizeT L, class I1>
|
||||||
decltype(auto) operator*(const Sptr<EIndex<MetaT,S,L>>& a, const Sptr<I1>& b);
|
decltype(auto) operator*(const Sptr<EIndex<MetaT,S,L>>& a, const Sptr<I1>& b);
|
||||||
|
|
||||||
|
|
|
@ -143,6 +143,19 @@ namespace CNORXZ
|
||||||
return std::make_shared<IndexInterface<I,MetaType>>( *i - n );
|
return std::make_shared<IndexInterface<I,MetaType>>( *i - n );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class I>
|
||||||
|
Sptr<I> moveToPtr(I&& i)
|
||||||
|
{
|
||||||
|
return std::make_shared<I>(std::forward(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class I>
|
||||||
|
decltype(auto) xpr(const Sptr<I>& i)
|
||||||
|
{
|
||||||
|
static_assert(is_index<I>::value, "got non-index type");
|
||||||
|
static_assert(index_expression_exists<I>::value, "expression for given index type does not exist");
|
||||||
|
return i->xpr(i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -164,12 +164,6 @@ namespace CNORXZ
|
||||||
*/
|
*/
|
||||||
I& at(const MetaType& meta) { return THIS().at(meta); }
|
I& at(const MetaType& meta) { return THIS().at(meta); }
|
||||||
|
|
||||||
/** create expression on this index
|
|
||||||
|
|
||||||
@param _this pointer to this index
|
|
||||||
*/
|
|
||||||
decltype(auto) xpr(const Sptr<I>& _this) const { return THIS().xpr(_this); }
|
|
||||||
|
|
||||||
/** create partial range starting at this index' position and ending
|
/** create partial range starting at this index' position and ending
|
||||||
at the position of input index. The end position is included!
|
at the position of input index. The end position is included!
|
||||||
@param end end index
|
@param end end index
|
||||||
|
@ -210,33 +204,6 @@ 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>
|
|
||||||
struct index_has_const_size
|
|
||||||
{ static constexpr bool value = false; };
|
|
||||||
|
|
||||||
template <class I>
|
|
||||||
struct index_const_size
|
|
||||||
{ static constexpr SizeT value = 0; };
|
|
||||||
|
|
||||||
template <class I>
|
|
||||||
struct index_dim
|
|
||||||
{ static constexpr SizeT value = 1; };
|
|
||||||
|
|
||||||
template <class T>
|
|
||||||
struct has_sub
|
|
||||||
{ static constexpr bool value = false; };
|
|
||||||
|
|
||||||
template <class T>
|
|
||||||
struct has_static_sub
|
|
||||||
{ static constexpr bool value = false; };
|
|
||||||
|
|
||||||
template <class I>
|
|
||||||
struct index_is_multi
|
|
||||||
{ static constexpr bool value = false; };
|
|
||||||
|
|
||||||
template <class I, typename MetaType>
|
template <class I, typename MetaType>
|
||||||
IndexPtr<I,MetaType>& operator++(const IndexPtr<I,MetaType>& i);
|
IndexPtr<I,MetaType>& operator++(const IndexPtr<I,MetaType>& i);
|
||||||
|
@ -252,7 +219,10 @@ namespace CNORXZ
|
||||||
IndexPtr<I,MetaType> operator-(const IndexPtr<I,MetaType>& i, Int n);
|
IndexPtr<I,MetaType> operator-(const IndexPtr<I,MetaType>& i, Int n);
|
||||||
|
|
||||||
template <class I>
|
template <class I>
|
||||||
Sptr<I> moveToPtr(I&& i) { return std::make_shared<I>(std::forward(i)); }
|
Sptr<I> moveToPtr(I&& i);
|
||||||
|
|
||||||
|
template <class I>
|
||||||
|
decltype(auto) xpr(const Sptr<I>& i);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
92
src/include/ranges/index_traits.h
Normal file
92
src/include/ranges/index_traits.h
Normal file
|
@ -0,0 +1,92 @@
|
||||||
|
// -*- C++ -*-
|
||||||
|
/**
|
||||||
|
|
||||||
|
@file include/ranges/index_traits.h
|
||||||
|
@brief index traits
|
||||||
|
|
||||||
|
Copyright (c) 2022 Christian Zimmermann. All rights reserved.
|
||||||
|
Mail: chizeta@f3l.de
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
#ifndef __cxz_index_traits__
|
||||||
|
#define __cxz_index_traits__
|
||||||
|
|
||||||
|
namespace CNORXZ
|
||||||
|
{
|
||||||
|
/** *****
|
||||||
|
check if given type is index-type
|
||||||
|
|
||||||
|
@tparam I type to be checked
|
||||||
|
**/
|
||||||
|
template <class I>
|
||||||
|
struct is_index
|
||||||
|
{ static constexpr bool value = std::is_base_of<IndexInterface<I,typename I::MetaType>,I>::value; };
|
||||||
|
|
||||||
|
/** *****
|
||||||
|
check if given type is index-type with a static range size
|
||||||
|
|
||||||
|
@tparam I type to be checked
|
||||||
|
**/
|
||||||
|
template <class I>
|
||||||
|
struct index_has_const_size
|
||||||
|
{ static constexpr bool value = false; };
|
||||||
|
|
||||||
|
/** *****
|
||||||
|
return static range size of an index (0 if there is no static size)
|
||||||
|
|
||||||
|
@tparam I type to be checked
|
||||||
|
**/
|
||||||
|
template <class I>
|
||||||
|
struct index_const_size
|
||||||
|
{ static constexpr SizeT value = 0; };
|
||||||
|
|
||||||
|
/** *****
|
||||||
|
return the static dimension of an index (1 if index is not statically multi-dimensional)
|
||||||
|
|
||||||
|
@tparam I type to be checked
|
||||||
|
**/
|
||||||
|
template <class I>
|
||||||
|
struct index_dim
|
||||||
|
{ static constexpr SizeT value = 1; };
|
||||||
|
|
||||||
|
/** *****
|
||||||
|
check if given type is index-type with sub-indices
|
||||||
|
|
||||||
|
@tparam I type to be checked
|
||||||
|
**/
|
||||||
|
template <class T>
|
||||||
|
struct has_sub
|
||||||
|
{ static constexpr bool value = false; };
|
||||||
|
|
||||||
|
/** *****
|
||||||
|
check if given type is index-type with static sub-indices
|
||||||
|
|
||||||
|
@tparam I type to be checked
|
||||||
|
**/
|
||||||
|
template <class T>
|
||||||
|
struct has_static_sub
|
||||||
|
{ static constexpr bool value = false; };
|
||||||
|
|
||||||
|
/** *****
|
||||||
|
check if given type is a statically multi-index-type
|
||||||
|
|
||||||
|
@tparam I type to be checked
|
||||||
|
**/
|
||||||
|
template <class I>
|
||||||
|
struct index_is_multi
|
||||||
|
{ static constexpr bool value = false; };
|
||||||
|
|
||||||
|
/** *****
|
||||||
|
check if given type is index-type that can be used in an expression,
|
||||||
|
i.e. has a member function xpr()
|
||||||
|
|
||||||
|
@tparam I type to be checked
|
||||||
|
**/
|
||||||
|
template <class I>
|
||||||
|
struct index_expression_exists
|
||||||
|
{ static constexpr bool value = false; };
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -49,6 +49,16 @@ namespace CNORXZ
|
||||||
static constexpr bool value = is_index<Index>::value;
|
static constexpr bool value = is_index<Index>::value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** ***
|
||||||
|
LIndex can be used as expression if this is case for its base type
|
||||||
|
@see index_expression_exists
|
||||||
|
*/
|
||||||
|
template <class Index, SizeT L>
|
||||||
|
struct index_expression_exists<LIndex<Index,L>>
|
||||||
|
{
|
||||||
|
static constexpr bool value = index_expression_exists<Index>::value;
|
||||||
|
};
|
||||||
|
|
||||||
template <class Index, SizeT L, class I1>
|
template <class Index, SizeT L, class I1>
|
||||||
decltype(auto) operator*(const Sptr<LIndex<Index,L>>& a, const Sptr<I1>& b);
|
decltype(auto) operator*(const Sptr<LIndex<Index,L>>& a, const Sptr<I1>& b);
|
||||||
|
|
||||||
|
|
|
@ -234,6 +234,16 @@ namespace CNORXZ
|
||||||
{
|
{
|
||||||
static Sptr<MRange<Ranges...>> func(const RangePtr& r);
|
static Sptr<MRange<Ranges...>> func(const RangePtr& r);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** ***
|
||||||
|
MIndex can be used as expression if all its sub-indices can be used as expression
|
||||||
|
@see index_expression_exists
|
||||||
|
*/
|
||||||
|
template <class... Indices>
|
||||||
|
struct index_expression_exists<MIndex<Indices...>>
|
||||||
|
{
|
||||||
|
static constexpr bool value = (index_expression_exists<Indices>::value and ...);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
#include "range_base.h"
|
#include "range_base.h"
|
||||||
#include "index_base.h"
|
#include "index_base.h"
|
||||||
|
#include "index_traits.h"
|
||||||
#include "mrange.h"
|
#include "mrange.h"
|
||||||
#include "xindex.h"
|
#include "xindex.h"
|
||||||
#include "yrange.h"
|
#include "yrange.h"
|
||||||
|
|
|
@ -134,6 +134,15 @@ namespace CNORXZ
|
||||||
static Sptr<SRange<MetaT,S>> func(const RangePtr& r);
|
static Sptr<SRange<MetaT,S>> func(const RangePtr& r);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** ***
|
||||||
|
SIndex can be used as expression
|
||||||
|
@see index_expression_exists
|
||||||
|
*/
|
||||||
|
template <typename MetaT, SizeT S>
|
||||||
|
struct index_expression_exists<SIndex<MetaT,S>>
|
||||||
|
{
|
||||||
|
static constexpr bool value = true;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -144,6 +144,16 @@ namespace CNORXZ
|
||||||
|
|
||||||
template <typename MetaT>
|
template <typename MetaT>
|
||||||
RangePtr urange(const Vector<MetaT>& space);
|
RangePtr urange(const Vector<MetaT>& space);
|
||||||
|
|
||||||
|
/** ***
|
||||||
|
UIndex can be used as expression
|
||||||
|
@see index_expression_exists
|
||||||
|
*/
|
||||||
|
template <typename MetaT>
|
||||||
|
struct index_expression_exists<UIndex<MetaT>>
|
||||||
|
{
|
||||||
|
static constexpr bool value = true;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -177,15 +177,6 @@ namespace CNORXZ
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Index, typename Meta>
|
|
||||||
DXpr<SizeT> XIndex<Index,Meta>::xpr(const XIndexPtr& _this) const
|
|
||||||
{
|
|
||||||
CXZ_ERROR("IMPLEMENT!!!");
|
|
||||||
auto xthis = std::dynamic_pointer_cast<Index>(_this);
|
|
||||||
//mI->xpr(xthis)
|
|
||||||
return DXpr<SizeT>( );
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class Index, typename Meta>
|
template <class Index, typename Meta>
|
||||||
DXpr<None> XIndex<Index,Meta>::ifor(const DXpr<None>& xpr, NoF&& f) const
|
DXpr<None> XIndex<Index,Meta>::ifor(const DXpr<None>& xpr, NoF&& f) const
|
||||||
{
|
{
|
||||||
|
|
|
@ -56,7 +56,6 @@ namespace CNORXZ
|
||||||
virtual String stringMeta() const = 0;
|
virtual String stringMeta() const = 0;
|
||||||
virtual DType meta() const = 0;
|
virtual DType meta() const = 0;
|
||||||
virtual XIndexBase& at(const DType& meta) = 0;
|
virtual XIndexBase& at(const DType& meta) = 0;
|
||||||
virtual DXpr<SizeT> xpr(const XIndexPtr& _this) const = 0;
|
|
||||||
|
|
||||||
virtual DXpr<None> ifor(const DXpr<None>& xpr, NoF&& f) const = 0;
|
virtual DXpr<None> ifor(const DXpr<None>& xpr, NoF&& f) const = 0;
|
||||||
|
|
||||||
|
@ -109,7 +108,6 @@ namespace CNORXZ
|
||||||
virtual String stringMeta() const override final;
|
virtual String stringMeta() const override final;
|
||||||
virtual DType meta() const override final;
|
virtual DType meta() const override final;
|
||||||
virtual XIndexBase& at(const DType& meta) override final;
|
virtual XIndexBase& at(const DType& meta) override final;
|
||||||
virtual DXpr<SizeT> xpr(const XIndexPtr& _this) const override final;
|
|
||||||
|
|
||||||
virtual DXpr<None> ifor(const DXpr<None>& xpr, NoF&& f) const override final;
|
virtual DXpr<None> ifor(const DXpr<None>& xpr, NoF&& f) const override final;
|
||||||
|
|
||||||
|
|
|
@ -67,7 +67,6 @@ namespace CNORXZ
|
||||||
String stringMeta() const;
|
String stringMeta() const;
|
||||||
Vector<DType> meta() const;
|
Vector<DType> meta() const;
|
||||||
YIndex& at(const Vector<DType>& meta);
|
YIndex& at(const Vector<DType>& meta);
|
||||||
DXpr<SizeT> xpr(const Sptr<YIndex>& _this) const;
|
|
||||||
|
|
||||||
DXpr<None> ifor(const DXpr<None>& xpr, NoF&& f) const;
|
DXpr<None> ifor(const DXpr<None>& xpr, NoF&& f) const;
|
||||||
|
|
||||||
|
|
|
@ -167,11 +167,6 @@ namespace CNORXZ
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
DXpr<SizeT> DIndex::xpr(const Sptr<DIndex>& _this) const
|
|
||||||
{
|
|
||||||
return mI->xpr(_this->xptr());
|
|
||||||
}
|
|
||||||
|
|
||||||
RangePtr DIndex::prange(const DIndex& end) const
|
RangePtr DIndex::prange(const DIndex& end) const
|
||||||
{
|
{
|
||||||
return mI->prange( end.xptr() );
|
return mI->prange( end.xptr() );
|
||||||
|
|
|
@ -343,12 +343,6 @@ namespace CNORXZ
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
DXpr<SizeT> YIndex::xpr(const Sptr<YIndex>& _this) const
|
|
||||||
{
|
|
||||||
CXZ_ERROR("IMPLEMENT!!!" << _this->lmax().val());
|
|
||||||
return DXpr<SizeT>();
|
|
||||||
}
|
|
||||||
|
|
||||||
DXpr<None> YIndex::ifor(const DXpr<None>& xpr, NoF&& f) const
|
DXpr<None> YIndex::ifor(const DXpr<None>& xpr, NoF&& f) const
|
||||||
{
|
{
|
||||||
return mkIFor(0, xpr, std::forward<NoF>(f));
|
return mkIFor(0, xpr, std::forward<NoF>(f));
|
||||||
|
|
Loading…
Reference in a new issue