32#ifndef GRID_LATTICE_ET_H
33#define GRID_LATTICE_ET_H
47template <
class iobj,
class vobj,
class robj>
53 typename std::remove_const<vobj>::type ret= iffalse;
58template <
class iobj,
class vobj,
class robj>
63 typename std::remove_const<vobj>::type ret;
65 typedef typename vobj::scalar_object scalar_object;
67 typedef typename vobj::vector_type vector_type;
69 const int Nsimd = vobj::vector_type::Nsimd();
79 for (
int s = 0; s < Nsimd; s++) {
80 if (mask[s]) falsevals[s] = truevals[s];
83 merge(ret, falsevals);
103sobj
eval(
const uint64_t ss,
const sobj &arg)
118sobj
vecEval(
const uint64_t ss,
const sobj &arg)
135 ->
decltype(expr.op.func(
vecEval(ss, expr.arg1)))
137 return expr.op.func(
vecEval(ss, expr.arg1) );
142 ->
decltype(expr.op.func(
vecEval(ss,expr.arg1),
vecEval(ss,expr.arg2)))
144 return expr.op.func(
vecEval(ss,expr.arg1),
vecEval(ss,expr.arg2) );
159 ->
decltype(expr.op.func(
eval(ss, expr.arg1)))
161 return expr.op.func(
eval(ss, expr.arg1) );
166 ->
decltype(expr.op.func(
eval(ss,expr.arg1),
eval(ss,expr.arg2)))
168 return expr.op.func(
eval(ss,expr.arg1),
eval(ss,expr.arg2) );
173 ->
decltype(expr.op.func(
eval(ss, expr.arg1),
175 eval(ss, expr.arg3)))
179 typedef decltype(
vecEval(ss, expr.arg2)) rvobj;
180 typedef typename std::remove_reference<rvobj>::type vobj;
182 const int Nsimd = vobj::vector_type::Nsimd();
184 auto vpred =
vecEval(ss,expr.arg1);
190 return expr.op.func(mask[s],
192 eval(ss, expr.arg3));
194 return expr.op.func(
eval(ss, expr.arg1),
196 eval(ss, expr.arg3));
206template <class T1,typename std::enable_if<is_lattice<T1>::value,
T1>
::type * =
nullptr>
209 lat.Conformable(grid);
212template <class T1,typename std::enable_if<!is_lattice<T1>::value,
T1>
::type * =
nullptr>
217template <
typename Op,
typename T1>
224template <
typename Op,
typename T1,
typename T2>
231template <
typename Op,
typename T1,
typename T2,
typename T3>
244template <class T1,typename std::enable_if<is_lattice<T1>::value,
T1>
::type * =
nullptr>
247 if ((cb ==
Odd) || (cb ==
Even)) {
248 assert(cb == lat.Checkerboard());
250 cb = lat.Checkerboard();
252template <class T1,typename std::enable_if<!is_lattice<T1>::value,
T1>
::type * =
nullptr>
254template <
typename Op,
typename T1>
inline
259template <
typename Op,
typename T1,
typename T2>
inline
265template <
typename Op,
typename T1,
typename T2,
typename T3>
277template <class T1,typename std::enable_if<is_lattice<T1>::value,
T1>
::type * =
nullptr>
282template <class T1,typename std::enable_if<!is_lattice<T1>::value,
T1>
::type * =
nullptr>
285template <
typename Op,
typename T1>
inline
291template <
typename Op,
typename T1,
typename T2>
inline
297template <
typename Op,
typename T1,
typename T2,
typename T3>
308template <class T1,typename std::enable_if<is_lattice<T1>::value,
T1>
::type * =
nullptr>
313template <class T1,typename std::enable_if<!is_lattice<T1>::value,
T1>
::type * =
nullptr>
316template <
typename Op,
typename T1>
inline
321template <
typename Op,
typename T1,
typename T2>
inline
327template <
typename Op,
typename T1,
typename T2,
typename T3>
338#define GridUnopClass(name, ret) \
340 template<class _arg> static auto accelerator_inline func(const _arg a) -> decltype(ret) { return ret; } \
365#define GridBinOpClass(name, combination) \
367 template <class _left, class _right> \
368 static auto accelerator_inline \
369 func(const _left &lhs, const _right &rhs) \
370 -> decltype(combination) const \
372 return combination; \
388#define GridTrinOpClass(name, combination) \
390 template <class _predicate,class _left, class _right> \
391 static auto accelerator_inline \
392 func(const _predicate &pred, const _left &lhs, const _right &rhs) \
393 -> decltype(combination) const \
395 return combination; \
401 typename std::remove_reference<_predicate>::type,
402 typename std::remove_reference<_left>::type,
403 typename std::remove_reference<_right>::type>(pred, lhs,rhs)));
408#define GRID_UNOP(name) name
409#define GRID_BINOP(name) name
410#define GRID_TRINOP(name) name
412#define GRID_DEF_UNOP(op, name) \
413 template <typename T1, typename std::enable_if<is_lattice<T1>::value||is_lattice_expr<T1>::value,T1>::type * = nullptr> \
414 inline auto op(const T1 &arg) ->decltype(LatticeUnaryExpression<GRID_UNOP(name),T1>(GRID_UNOP(name)(), arg)) \
416 return LatticeUnaryExpression<GRID_UNOP(name),T1>(GRID_UNOP(name)(), arg); \
419#define GRID_BINOP_LEFT(op, name) \
420 template <typename T1, typename T2, \
421 typename std::enable_if<is_lattice<T1>::value||is_lattice_expr<T1>::value,T1>::type * = nullptr> \
422 inline auto op(const T1 &lhs, const T2 &rhs) \
423 ->decltype(LatticeBinaryExpression<GRID_BINOP(name),T1,T2>(GRID_BINOP(name)(),lhs,rhs)) \
425 return LatticeBinaryExpression<GRID_BINOP(name),T1,T2>(GRID_BINOP(name)(),lhs,rhs);\
428#define GRID_BINOP_RIGHT(op, name) \
429 template <typename T1, typename T2, \
430 typename std::enable_if<!is_lattice<T1>::value&&!is_lattice_expr<T1>::value,T1>::type * = nullptr, \
431 typename std::enable_if< is_lattice<T2>::value|| is_lattice_expr<T2>::value,T2>::type * = nullptr> \
432 inline auto op(const T1 &lhs, const T2 &rhs) \
433 ->decltype(LatticeBinaryExpression<GRID_BINOP(name),T1,T2>(GRID_BINOP(name)(),lhs, rhs)) \
435 return LatticeBinaryExpression<GRID_BINOP(name),T1,T2>(GRID_BINOP(name)(),lhs, rhs); \
438#define GRID_DEF_BINOP(op, name) \
439 GRID_BINOP_LEFT(op, name); \
440 GRID_BINOP_RIGHT(op, name);
442#define GRID_DEF_TRINOP(op, name) \
443 template <typename T1, typename T2, typename T3> \
444 inline auto op(const T1 &pred, const T2 &lhs, const T3 &rhs) \
445 ->decltype(LatticeTrinaryExpression<GRID_TRINOP(name),T1,T2,T3>(GRID_TRINOP(name)(),pred, lhs, rhs)) \
447 return LatticeTrinaryExpression<GRID_TRINOP(name),T1,T2,T3>(GRID_TRINOP(name)(),pred, lhs, rhs); \
491template <
class Op,
class T1>
495 Lattice<
typename std::remove_const<
decltype(expr.op.func(
vecEval(0, expr.arg1)))>
::type > ret(expr);
498template <
class Op,
class T1,
class T2>
505template <
class Op,
class T1,
class T2,
class T3>
507 ->
Lattice<
typename std::remove_const<
decltype(expr.op.func(
vecEval(0, expr.arg1),
511 Lattice<
typename std::remove_const<
decltype(expr.op.func(
vecEval(0, expr.arg1),
516#define EXPRESSION_CLOSURE(function) \
517 template<class Expression,typename std::enable_if<is_lattice_expr<Expression>::value,void>::type * = nullptr> \
518 auto function(Expression &expr) -> decltype(function(closure(expr))) \
520 return function(closure(expr)); \
530#undef GRID_DEF_TRINOP
accelerator_inline int acceleratorSIMTlane(int Nsimd)
#define accelerator_inline
accelerator_inline void timesMinusI(Grid_simd2< S, V > &ret, const Grid_simd2< S, V > &in)
accelerator_inline void timesI(Grid_simd2< S, V > &ret, const Grid_simd2< S, V > &in)
accelerator_inline Grid_simd2< S, V > trace(const Grid_simd2< S, V > &arg)
accelerator_inline Grid_simd< S, V > cos(const Grid_simd< S, V > &r)
accelerator_inline Grid_simd< S, V > abs(const Grid_simd< S, V > &r)
accelerator_inline Grid_simd< S, V > asin(const Grid_simd< S, V > &r)
accelerator_inline Grid_simd< S, V > sin(const Grid_simd< S, V > &r)
accelerator_inline Grid_simd< S, V > Not(const Grid_simd< S, V > &r)
accelerator_inline Grid_simd< S, V > acos(const Grid_simd< S, V > &r)
accelerator_inline Grid_simd< S, V > exp(const Grid_simd< S, V > &r)
accelerator_inline Grid_simd< S, V > sqrt(const Grid_simd< S, V > &r)
accelerator_inline Grid_simd< S, V > log(const Grid_simd< S, V > &r)
accelerator_inline void GridFromExpression(GridBase *&grid, const T1 &lat)
#define GRID_DEF_BINOP(op, name)
auto closure(const LatticeUnaryExpression< Op, T1 > &expr) -> Lattice< typename std::remove_const< decltype(expr.op.func(vecEval(0, expr.arg1)))>::type >
accelerator_inline sobj eval(const uint64_t ss, const sobj &arg)
void ExpressionViewOpen(T1 &lat)
#define GRID_DEF_UNOP(op, name)
accelerator_inline sobj vecEval(const uint64_t ss, const sobj &arg)
#define GridTrinOpClass(name, combination)
#define GridUnopClass(name, ret)
#define GRID_DEF_TRINOP(op, name)
void ExpressionViewClose(T1 &lat)
accelerator_inline vobj predicatedWhere(const iobj &predicate, const vobj &iftrue, const robj &iffalse)
void CBFromExpression(int &cb, const T1 &lat)
#define GridBinOpClass(name, combination)
std::is_base_of< LatticeExpressionBase, T > is_lattice_expr
#define NAMESPACE_BEGIN(A)
accelerator_inline iScalar< vtype > ProjectOnSpGroup(const iScalar< vtype > &r)
accelerator_inline iScalar< vtype > SpTa(const iScalar< vtype > &r)
accelerator_inline iScalar< vtype > ProjectOnGroup(const iScalar< vtype > &r)
accelerator_inline iScalar< vtype > Ta(const iScalar< vtype > &r)
accelerator_inline std::enable_if<!isGridTensor< T >::value, T >::type TensorRemove(T arg)
accelerator_inline ComplexD transpose(ComplexD &rhs)
Lattice< T >::vector_object type