#ifndef GRID_VECTOR_UNOPS #define GRID_VECTOR_UNOPS #include namespace Grid { template struct SqrtRealFunctor { scalar operator()(const scalar &a) const { return sqrt(real(a)); } }; template struct RSqrtRealFunctor { scalar operator()(const scalar &a) const { return scalar(1.0/sqrt(real(a))); } }; template struct CosRealFunctor { scalar operator()(const scalar &a) const { return cos(real(a)); } }; template struct SinRealFunctor { scalar operator()(const scalar &a) const { return sin(real(a)); } }; template struct LogRealFunctor { scalar operator()(const scalar &a) const { return log(real(a)); } }; template struct ExpRealFunctor { scalar operator()(const scalar &a) const { return exp(real(a)); } }; template struct NotFunctor { scalar operator()(const scalar &a) const { return (!a); } }; template struct AbsRealFunctor { scalar operator()(const scalar &a) const { return std::abs(real(a)); } }; template struct PowRealFunctor { double y; PowRealFunctor(double _y) : y(_y) {}; scalar operator()(const scalar &a) const { return pow(real(a),y); } }; template struct ModIntFunctor { Integer y; ModIntFunctor(Integer _y) : y(_y) {}; scalar operator()(const scalar &a) const { return Integer(a)%y; } }; template struct RealFunctor { scalar operator()(const scalar &a) const { return real(a); } }; template struct ImagFunctor { scalar operator()(const scalar &a) const { return imag(a); } }; template < class S, class V > inline Grid_simd real(const Grid_simd &r) { return SimdApply(RealFunctor(),r); } template < class S, class V > inline Grid_simd imag(const Grid_simd &r) { return SimdApply(ImagFunctor(),r); } template < class S, class V > inline Grid_simd sqrt(const Grid_simd &r) { return SimdApply(SqrtRealFunctor(),r); } template < class S, class V > inline Grid_simd rsqrt(const Grid_simd &r) { return SimdApply(RSqrtRealFunctor(),r); } template < class S, class V > inline Grid_simd cos(const Grid_simd &r) { return SimdApply(CosRealFunctor(),r); } template < class S, class V > inline Grid_simd sin(const Grid_simd &r) { return SimdApply(CosRealFunctor(),r); } template < class S, class V > inline Grid_simd log(const Grid_simd &r) { return SimdApply(LogRealFunctor(),r); } template < class S, class V > inline Grid_simd abs(const Grid_simd &r) { return SimdApply(AbsRealFunctor(),r); } template < class S, class V > inline Grid_simd exp(const Grid_simd &r) { return SimdApply(ExpRealFunctor(),r); } template < class S, class V > inline Grid_simd Not(const Grid_simd &r) { return SimdApply(NotFunctor(),r); } template < class S, class V > inline Grid_simd pow(const Grid_simd &r,double y) { return SimdApply(PowRealFunctor(y),r); } template < class S, class V > inline Grid_simd mod(const Grid_simd &r,Integer y) { return SimdApply(ModIntFunctor(y),r); } //////////////////////////////////////////////////////////////////////////// // Allows us to assign into **conformable** real vectors from complex //////////////////////////////////////////////////////////////////////////// // template < class S, class V > // inline auto ComplexRemove(const Grid_simd &c) -> Grid_simd::Real,V> { // Grid_simd::Real,V> ret; // ret.v = c.v; // return ret; // } template struct AndFunctor { scalar operator()(const scalar &x, const scalar &y) const { return x & y; } }; template struct OrFunctor { scalar operator()(const scalar &x, const scalar &y) const { return x | y; } }; template struct AndAndFunctor { scalar operator()(const scalar &x, const scalar &y) const { return x && y; } }; template struct OrOrFunctor { scalar operator()(const scalar &x, const scalar &y) const { return x || y; } }; //////////////////////////////// // Calls to simd binop functors //////////////////////////////// template < class S, class V > inline Grid_simd operator &(const Grid_simd &x,const Grid_simd &y) { return SimdApplyBinop(AndFunctor(),x,y); } template < class S, class V > inline Grid_simd operator &&(const Grid_simd &x,const Grid_simd &y) { return SimdApplyBinop(AndAndFunctor(),x,y); } template < class S, class V > inline Grid_simd operator |(const Grid_simd &x,const Grid_simd &y) { return SimdApplyBinop(OrFunctor(),x,y); } template < class S, class V > inline Grid_simd operator ||(const Grid_simd &x,const Grid_simd &y) { return SimdApplyBinop(OrOrFunctor(),x,y); } } #endif