2022-10-16 00:55:14 +02:00
|
|
|
|
|
|
|
#ifndef __cxz_for_h__
|
|
|
|
#define __cxz_for_h__
|
|
|
|
|
|
|
|
#include "base/base.h"
|
|
|
|
#include "xpr_base.h"
|
2022-10-30 22:28:40 +01:00
|
|
|
#include "func.h"
|
2022-10-16 00:55:14 +02:00
|
|
|
|
|
|
|
namespace CNORXZ
|
|
|
|
{
|
2022-10-23 18:29:07 +02:00
|
|
|
|
|
|
|
template <SizeT L, class Xpr, class F = NoF>
|
|
|
|
class For : public XprInterface<For<L,Xpr,F>>
|
2022-10-16 00:55:14 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
DEFAULT_MEMBERS(For);
|
|
|
|
|
2022-10-23 18:29:07 +02:00
|
|
|
constexpr For(SizeT size, const IndexId<L>& id, const Xpr& xpr, F&& f);
|
2022-10-16 00:55:14 +02:00
|
|
|
|
2022-10-21 00:21:47 +02:00
|
|
|
template <class PosT>
|
2022-10-23 18:29:07 +02:00
|
|
|
inline decltype(auto) operator()(const PosT& last) const;
|
2022-10-16 00:55:14 +02:00
|
|
|
|
2022-10-23 18:29:07 +02:00
|
|
|
inline decltype(auto) operator()() const;
|
2022-10-16 00:55:14 +02:00
|
|
|
|
2022-10-16 18:37:14 +02:00
|
|
|
template <SizeT I>
|
|
|
|
inline decltype(auto) rootSteps(const IndexId<I>& id) const;
|
2022-10-16 00:55:14 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
SizeT mSize = 0;
|
2022-10-16 18:37:14 +02:00
|
|
|
IndexId<L> mId;
|
2022-10-16 00:55:14 +02:00
|
|
|
Xpr mXpr;
|
2022-10-16 23:05:48 +02:00
|
|
|
typedef decltype(mXpr.rootSteps(mId)) XPosT;
|
|
|
|
XPosT mExt;
|
2022-10-23 18:29:07 +02:00
|
|
|
F mF;
|
2022-10-16 00:55:14 +02:00
|
|
|
};
|
|
|
|
|
2022-11-22 00:58:50 +01:00
|
|
|
template <SizeT L, class Xpr, class F>
|
|
|
|
constexpr decltype(auto) mkFor(SizeT size, const IndexId<L>& id, const Xpr& xpr, F&& f);
|
|
|
|
|
|
|
|
template <SizeT L, class Xpr>
|
|
|
|
constexpr decltype(auto) mkFor(SizeT size, const IndexId<L>& id, const Xpr& xpr);
|
|
|
|
|
2022-10-16 00:55:14 +02:00
|
|
|
// unrolled loop:
|
2022-10-23 18:29:07 +02:00
|
|
|
template <SizeT N, SizeT L, class Xpr, class F = NoF>
|
|
|
|
class SFor : public XprInterface<SFor<N,L,Xpr,F>>
|
2022-10-16 00:55:14 +02:00
|
|
|
{
|
|
|
|
public:
|
2022-10-16 23:05:48 +02:00
|
|
|
DEFAULT_MEMBERS(SFor);
|
2022-10-16 00:55:14 +02:00
|
|
|
|
2022-10-23 18:29:07 +02:00
|
|
|
constexpr SFor(const IndexId<L>& id, const Xpr& xpr, F&& f);
|
2022-10-16 00:55:14 +02:00
|
|
|
|
2022-10-21 00:21:47 +02:00
|
|
|
template <class PosT>
|
2022-10-23 18:29:07 +02:00
|
|
|
constexpr decltype(auto) operator()(const PosT& last) const;
|
2022-10-16 00:55:14 +02:00
|
|
|
|
2022-10-23 18:29:07 +02:00
|
|
|
constexpr decltype(auto) operator()() const;
|
2022-10-16 00:55:14 +02:00
|
|
|
|
2022-10-16 18:37:14 +02:00
|
|
|
template <SizeT I>
|
|
|
|
constexpr decltype(auto) rootSteps(const IndexId<I>& id) const;
|
2022-10-16 00:55:14 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2022-10-21 00:21:47 +02:00
|
|
|
template <SizeT I, class PosT>
|
2022-10-23 18:29:07 +02:00
|
|
|
constexpr decltype(auto) exec(const PosT& last) const;
|
2022-10-16 00:55:14 +02:00
|
|
|
|
|
|
|
template <SizeT I>
|
2022-10-23 18:29:07 +02:00
|
|
|
constexpr decltype(auto) exec() const;
|
2022-10-16 18:37:14 +02:00
|
|
|
|
2022-11-22 00:58:50 +01:00
|
|
|
template <SizeT I, class PosT>
|
|
|
|
inline void exec2(const PosT& last) const;
|
|
|
|
|
|
|
|
template <SizeT I>
|
|
|
|
inline void exec2() const;
|
|
|
|
|
2022-10-16 18:37:14 +02:00
|
|
|
IndexId<L> mId;
|
2022-10-16 00:55:14 +02:00
|
|
|
Xpr mXpr;
|
2022-11-22 00:58:50 +01:00
|
|
|
typedef decltype(mXpr.rootSteps(mId)) XPosT;
|
2022-10-16 23:05:48 +02:00
|
|
|
XPosT mExt;
|
2022-10-23 18:29:07 +02:00
|
|
|
F mF;
|
2022-10-16 00:55:14 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2022-11-22 00:58:50 +01:00
|
|
|
template <SizeT N, SizeT L, class Xpr, class F>
|
|
|
|
constexpr decltype(auto) mkSFor(const IndexId<L>& id, const Xpr& xpr, F&& f);
|
|
|
|
|
|
|
|
template <SizeT N, SizeT L, class Xpr>
|
|
|
|
constexpr decltype(auto) mkSFor(const IndexId<L>& id, const Xpr& xpr);
|
2022-10-16 00:55:14 +02:00
|
|
|
|
2023-01-30 01:13:14 +01:00
|
|
|
// partial for:
|
|
|
|
template <SizeT L1, SizeT L2, class Xpr, class F = NoF>
|
|
|
|
class PFor : public XprInterface<PFor<L1,L2,Xpr,F>>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DEFAULT_MEMBERS(PFor);
|
|
|
|
|
|
|
|
constexpr PFor(SizeT size, const IndexId<L1>& id1, const IndexId<L2>& id2,
|
|
|
|
const SizeT* map, const Xpr& xpr, F&& f);
|
|
|
|
|
|
|
|
template <class PosT>
|
|
|
|
inline decltype(auto) operator()(const PosT& last) const;
|
|
|
|
|
|
|
|
inline decltype(auto) operator()() const;
|
|
|
|
|
|
|
|
template <SizeT I>
|
|
|
|
inline decltype(auto) rootSteps(const IndexId<I>& id) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
SizeT mSize = 0;
|
|
|
|
IndexId<L1> mId1;
|
|
|
|
IndexId<L2> mId2;
|
|
|
|
Xpr mXpr;
|
|
|
|
typedef decltype(mXpr.rootSteps(mId1)) XPosT1;
|
|
|
|
typedef decltype(mXpr.rootSteps(mId2)) XPosT2;
|
|
|
|
XPosT1 mExt1;
|
|
|
|
XPosT2 mExt2;
|
|
|
|
FPos mPart;
|
|
|
|
F mF;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <SizeT L, class Xpr, class F>
|
|
|
|
constexpr decltype(auto) mkFor(SizeT size, const IndexId<L>& id, const Xpr& xpr, F&& f);
|
|
|
|
|
|
|
|
template <SizeT L, class Xpr>
|
|
|
|
constexpr decltype(auto) mkFor(SizeT size, const IndexId<L>& id, const Xpr& xpr);
|
|
|
|
|
2022-10-16 00:55:14 +02:00
|
|
|
// multi-threading
|
2022-10-23 18:29:07 +02:00
|
|
|
template <SizeT L, class Xpr, class F = NoF>
|
|
|
|
class TFor : public XprInterface<TFor<L,Xpr,F>>
|
2022-10-16 00:55:14 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
DEFAULT_MEMBERS(TFor);
|
|
|
|
|
2022-10-23 18:29:07 +02:00
|
|
|
constexpr TFor(SizeT size, const IndexId<L>& id, const Xpr& xpr, F&& f);
|
2022-10-16 00:55:14 +02:00
|
|
|
|
2022-10-21 00:21:47 +02:00
|
|
|
template <class PosT>
|
2022-10-23 18:29:07 +02:00
|
|
|
inline decltype(auto) operator()(const PosT& last) const;
|
2022-10-16 00:55:14 +02:00
|
|
|
|
2022-10-23 18:29:07 +02:00
|
|
|
inline decltype(auto) operator()() const;
|
2022-10-16 00:55:14 +02:00
|
|
|
|
2022-10-16 18:37:14 +02:00
|
|
|
template <SizeT I>
|
|
|
|
inline decltype(auto) rootSteps(const IndexId<I>& id) const;
|
2022-10-16 00:55:14 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
SizeT mSize = 0;
|
2022-10-18 00:30:05 +02:00
|
|
|
IndexId<L> mId;
|
2022-10-16 00:55:14 +02:00
|
|
|
Xpr mXpr;
|
2022-10-16 23:05:48 +02:00
|
|
|
typedef decltype(mXpr.rootSteps(mId)) XPosT;
|
|
|
|
XPosT mExt;
|
2022-10-23 18:29:07 +02:00
|
|
|
F mF;
|
2022-10-16 00:55:14 +02:00
|
|
|
};
|
|
|
|
|
2022-10-18 00:30:05 +02:00
|
|
|
// Extension For (Vectorization)
|
2022-10-21 00:21:47 +02:00
|
|
|
template <SizeT N, SizeT L, class Xpr>
|
|
|
|
class EFor : public XprInterface<EFor<N,L,Xpr>>
|
2022-10-18 00:30:05 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
DEFAULT_MEMBERS(EFor);
|
|
|
|
|
2022-10-21 00:21:47 +02:00
|
|
|
constexpr EFor(const IndexId<L>& id, const Xpr& xpr);
|
2022-10-18 00:30:05 +02:00
|
|
|
|
2022-10-21 00:21:47 +02:00
|
|
|
template <class PosT>
|
2022-10-23 18:29:07 +02:00
|
|
|
constexpr decltype(auto) operator()(const PosT& last) const;
|
2022-10-18 00:30:05 +02:00
|
|
|
|
2022-10-23 18:29:07 +02:00
|
|
|
constexpr decltype(auto) operator()() const;
|
2022-10-18 00:30:05 +02:00
|
|
|
|
|
|
|
template <SizeT I>
|
|
|
|
constexpr decltype(auto) rootSteps(const IndexId<I>& id) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
IndexId<L> mId;
|
|
|
|
Xpr mXpr;
|
|
|
|
typedef decltype(mXpr.rootSteps(mId)) XPosT;
|
|
|
|
XPosT mExt;
|
|
|
|
};
|
2022-10-16 00:55:14 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|