OpCont + adapt ifor memeber functions

This commit is contained in:
Christian Zimmermann 2022-10-30 22:28:40 +01:00
parent c9f69ad25d
commit 6b2bbc3020
19 changed files with 159 additions and 54 deletions

View file

@ -106,6 +106,60 @@ namespace CNORXZ
}
/****************
* OpCont *
****************/
template <typename T, class IndexT>
constexpr OpCont<T,IndexT>::OpCont(const Sptr<Index>& ind) :
mIndex(ind),
mC(mIndex.max())
{}
template <typename T, class IndexT>
template <class PosT>
constexpr decltype(auto) OpCont<T,IndexT>::operator()(const PosT& pos) const
{
if constexpr(is_epos_type<PosT>::value){
if constexpr(pos_type_is_consecutive<PosT>::value){
return vreg(mC.data(),pos);
}
else {
// non-consecutive data cannot be directly accessed
// so there is no non-const (write) access!
return vreg(const_cast<const T*>(mData),pos);
}
}
else {
return mC[pos.val()];
}
}
template <typename T, class IndexT>
constexpr decltype(auto) OpCont<T,IndexT>::operator()() const
{
return mC[0];
}
template <typename T, class IndexT>
template <SizeT I>
constexpr decltype(auto) OpCont<T,IndexT>::rootSteps(const IndexId<I>& id) const
{
return mIndex->stepSize(id);
}
template <typename T, class IndexT>
T* OpCont<T,IndexT>::data()
{
return mC.data();
}
template <typename T, class IndexT>
const T* OpCont<T,IndexT>::data() const
{
return mC.data();
}
/****************
* OpRoot *
****************/
@ -139,7 +193,7 @@ namespace CNORXZ
}
template <typename T, class IndexT>
constexpr OpRoot<T,IndexT>& OpRoot<T,IndexT>::operator=(const OpRoot<T,IndexT>& in)
constexpr OpRoot<T,IndexT>& OpRoot<T,IndexT>::operator=(const OpRoot<T,IndexT>& o)
{
a(mInd, [](auto& a, const auto& b) { a = b; }, o)
return *this;
@ -176,7 +230,12 @@ namespace CNORXZ
{
return mIndex->stepSize(id);
}
template <typename T, class IndexT>
T* OpRoot<T,IndexT>::data() const
{
return mData;
}
/*******************
* Operation *

View file

@ -56,8 +56,6 @@ namespace CNORXZ
class COpRoot : public COpInterface<COpRoot<T,IndexT>>
{
public:
typedef T value_type;
typedef OpInterface<T,COpRoot<T,IndexT>> OI;
constexpr COpRoot(const DArrayBase<T>& a, const Sptr<IndexT>& ind);
@ -83,6 +81,25 @@ namespace CNORXZ
{
// operation container (intermediate operation results)
// TO BE IMPLEMENTED!!!
public:
typedef OpInterface<OpCont<T,IndexT>> OI;
constexpr OpCont(const Sptr<Index>& ind);
template <class PosT>
constexpr decltype(auto) operator()(const PosT& pos) const;
constexpr decltype(auto) operator()() const;
template <SizeT I>
constexpr decltype(auto) rootSteps(const IndexId<I>& id) const;
T* data();
const T* data() const;
private:
Sptr<IndexT> mIndex;
Vector<T> mC;
};
@ -90,7 +107,6 @@ namespace CNORXZ
class OpRoot : public OpInterface<OpRoot<T,IndexT>>
{
public:
typedef T value_type;
typedef OpInterface<OpRoot<T,IndexT>> OI;
constexpr OpRoot(MDArrayBase<T>& a, const Sptr<IndexT>& ind);

View file

@ -6,10 +6,10 @@
namespace CNORXZ
{
template <class Xpr>
decltype(auto) CIndex::ifor(const Xpr& xpr) const
template <class Xpr, class F>
decltype(auto) CIndex::ifor(const Xpr& xpr, F&& f) const
{
return For<0,Xpr>(this->max(), this->id(), xpr, NoF());
return For<0,Xpr,F>(this->max(), this->id(), xpr, std::forward<F>(f));
}
}

View file

@ -43,8 +43,8 @@ namespace CNORXZ
SizeT meta() const;
CIndex& at(const SizeT& metaPos);
template <class Xpr>
decltype(auto) ifor(const Xpr& xpr) const;
template <class Xpr, class F = NoF>
decltype(auto) ifor(const Xpr& xpr, F&& f) const;
private:
Sptr<RangeType> mRangePtr;

View file

@ -50,7 +50,7 @@ namespace CNORXZ
DType meta() const;
DIndex& at(const DType& meta);
DXpr<SizeT> ifor(const DXpr<SizeT>& xpr) const;
DXpr<SizeT> ifor(const DXpr<SizeT>& xpr, std::function<SizeT(SizeT,SizeT)>&& f) const;
private:
XIndexPtr mI;

View file

@ -7,6 +7,7 @@
#include "range_base.h"
#include "xpr/index_id.h"
#include "xpr/xpr_base.h"
#include "xpr/func.h"
namespace CNORXZ
{
@ -55,8 +56,9 @@ namespace CNORXZ
decltype(auto) meta() const { return THIS().meta(); }
I& at(const MetaType& meta) { return THIS().at(meta); }
template <class Xpr>
decltype(auto) ifor(const Xpr& xpr) const { return THIS().ifor(xpr); }
template <class Xpr, class F = NoF>
decltype(auto) ifor(const Xpr& xpr, F&& f) const
{ return THIS().ifor(xpr,std::forward<F>(f)); }
protected:
SizeT mPos = 0;

View file

@ -145,10 +145,10 @@ namespace CNORXZ
}
template <typename MetaType>
template <class Xpr>
decltype(auto) UIndex<MetaType>::ifor(const Xpr& xpr) const
template <class Xpr, class F>
decltype(auto) UIndex<MetaType>::ifor(const Xpr& xpr, F&& f) const
{
return For<0,Xpr>(this->max(), this->id(), xpr);
return For<0,Xpr>(this->max(), this->id(), xpr, std::forward<F>(f));
}
/**********************

View file

@ -48,8 +48,8 @@ namespace CNORXZ
const MetaType& meta() const;
UIndex& at(const MetaType& metaPos);
template <class Xpr>
decltype(auto) ifor(const Xpr& xpr) const;
template <class Xpr, class F>
decltype(auto) ifor(const Xpr& xpr, F&& f) const;
private:
Sptr<RangeType> mRangePtr;

View file

@ -155,9 +155,10 @@ namespace CNORXZ
}
template <class Index, typename Meta>
DXpr<SizeT> XIndex<Index,Meta>::ifor(const DXpr<SizeT>& xpr) const
DXpr<SizeT> XIndex<Index,Meta>::ifor(const DXpr<SizeT>& xpr,
std::function<SizeT(SizeT,SizeT)>&& f) const
{
return DXpr<SizeT>(mI->ifor(xpr));
return DXpr<SizeT>(mI->ifor(xpr, std::forward<std::function<SizeT(SizeT,SizeT)>>(f)));
}
}

View file

@ -42,7 +42,8 @@ namespace CNORXZ
virtual DType meta() const = 0;
virtual XIndexBase& at(const DType& meta) = 0;
virtual DXpr<SizeT> ifor(const DXpr<SizeT>& xpr) const = 0;
virtual DXpr<SizeT> ifor(const DXpr<SizeT>& xpr,
std::function<SizeT(SizeT,SizeT)>&& f) const = 0;
};
//Sptr<XIndexBase>& operator++(Sptr<XIndexBase>& i);
@ -91,7 +92,8 @@ namespace CNORXZ
virtual DType meta() const override final;
virtual XIndexBase& at(const DType& meta) override final;
virtual DXpr<SizeT> ifor(const DXpr<SizeT>& xpr) const override final;
virtual DXpr<SizeT> ifor(const DXpr<SizeT>& xpr,
std::function<SizeT(SizeT,SizeT)>&& f) const override final;
private:
IndexPtr<Index,Meta> mI;

View file

@ -51,7 +51,7 @@ namespace CNORXZ
DType meta() const;
YIndex& at(const DType& meta);
DXpr<SizeT> ifor(const DXpr<SizeT>& xpr) const;
DXpr<SizeT> ifor(const DXpr<SizeT>& xpr, std::function<SizeT(SizeT,SizeT)>&& f) const;
private:

View file

@ -8,21 +8,6 @@
namespace CNORXZ
{
/*************
* ZeroF *
*************/
template <typename... T>
constexpr decltype(auto) ZeroF::operator()(const T&... as) const
{
return 0;
}
template <typename... T>
constexpr decltype(auto) NoF::operator()(const T&... as) const
{
return;
}
/***********
* For *

View file

@ -4,22 +4,10 @@
#include "base/base.h"
#include "xpr_base.h"
#include "func.h"
namespace CNORXZ
{
class ZeroF
{
public:
template <typename... T>
constexpr decltype(auto) operator()(const T&... as) const;
};
class NoF
{
public:
template <typename... T>
constexpr decltype(auto) operator()(const T&... as) const;
};
template <SizeT L, class Xpr, class F = NoF>
class For : public XprInterface<For<L,Xpr,F>>

24
src/include/xpr/func.cc.h Normal file
View file

@ -0,0 +1,24 @@
#ifndef __cxz_func_cc_h__
#define __cxz_func_cc_h__
#include "func.h"
namespace CNORXZ
{
template <typename... T>
constexpr decltype(auto) ZeroF::operator()(const T&... as) const
{
return 0;
}
template <typename... T>
constexpr decltype(auto) NoF::operator()(const T&... as) const
{
return;
}
}
#endif

25
src/include/xpr/func.h Normal file
View file

@ -0,0 +1,25 @@
#ifndef __cxz_func_h__
#define __cxz_func_h__
#include "base/base.h"
namespace CNORXZ
{
class ZeroF
{
public:
template <typename... T>
constexpr decltype(auto) operator()(const T&... as) const;
};
class NoF
{
public:
template <typename... T>
constexpr decltype(auto) operator()(const T&... as) const;
};
}
#endif

View file

@ -4,3 +4,4 @@
#include "xpr_base.cc.h"
#include "for.cc.h"
#include "index_id.cc.h"
#include "func.cc.h"

View file

@ -4,5 +4,6 @@
#include "xpr_base.h"
#include "for.h"
#include "index_id.h"
#include "func.h"
#include "xpr.cc.h"

View file

@ -138,9 +138,9 @@ namespace CNORXZ
return *this;
}
DXpr<SizeT> DIndex::ifor(const DXpr<SizeT>& xpr) const
DXpr<SizeT> DIndex::ifor(const DXpr<SizeT>& xpr, std::function<SizeT(SizeT,SizeT)>&& f) const
{
return DXpr<SizeT>(mI->ifor(xpr));
return DXpr<SizeT>(mI->ifor(xpr, std::forward<std::function<SizeT(SizeT,SizeT)>>(f)) );
}
}

View file

@ -171,9 +171,10 @@ namespace CNORXZ
return *this;
}
DXpr<SizeT> YIndex::ifor(const DXpr<SizeT>& xpr) const
DXpr<SizeT> YIndex::ifor(const DXpr<SizeT>& xpr, std::function<SizeT(SizeT,SizeT)>&& f) const
{
assert(0);
f(0,0);
return DXpr<SizeT>();
}