#ifndef GRID_COMPARISON_H #define GRID_COMPARISON_H namespace Grid { // Generic list of functors template class veq { public: vInteger operator()(const lobj &lhs, const robj &rhs) { return lhs == rhs; } }; template class vne { public: vInteger operator()(const lobj &lhs, const robj &rhs) { return lhs != rhs; } }; template class vlt { public: vInteger operator()(const lobj &lhs, const robj &rhs) { return lhs < rhs; } }; template class vle { public: vInteger operator()(const lobj &lhs, const robj &rhs) { return lhs <= rhs; } }; template class vgt { public: vInteger operator()(const lobj &lhs, const robj &rhs) { return lhs > rhs; } }; template class vge { public: vInteger operator()(const lobj &lhs, const robj &rhs) { return lhs >= rhs; } }; // Generic list of functors template class seq { public: Integer operator()(const lobj &lhs, const robj &rhs) { return lhs == rhs; } }; template class sne { public: Integer operator()(const lobj &lhs, const robj &rhs) { return lhs != rhs; } }; template class slt { public: Integer operator()(const lobj &lhs, const robj &rhs) { return lhs < rhs; } }; template class sle { public: Integer operator()(const lobj &lhs, const robj &rhs) { return lhs <= rhs; } }; template class sgt { public: Integer operator()(const lobj &lhs, const robj &rhs) { return lhs > rhs; } }; template class sge { public: Integer operator()(const lobj &lhs, const robj &rhs) { return lhs >= rhs; } }; ////////////////////////////////////////////////////////////////////////////////////////////////////// // Integer gets extra relational functions. Could also implement these for RealF, RealD etc.. ////////////////////////////////////////////////////////////////////////////////////////////////////// template inline vInteger Comparison(sfunctor sop,const vInteger & lhs, const vInteger & rhs) { std::vector vlhs(vInteger::Nsimd()); // Use functors to reduce this to single implementation std::vector vrhs(vInteger::Nsimd()); vInteger ret; extract(lhs,vlhs); extract(rhs,vrhs); for(int s=0;s(),lhs,rhs); } inline vInteger operator <= (const vInteger & lhs, const vInteger & rhs) { return Comparison(sle(),lhs,rhs); } inline vInteger operator > (const vInteger & lhs, const vInteger & rhs) { return Comparison(sgt(),lhs,rhs); } inline vInteger operator >= (const vInteger & lhs, const vInteger & rhs) { return Comparison(sge(),lhs,rhs); } inline vInteger operator == (const vInteger & lhs, const vInteger & rhs) { return Comparison(seq(),lhs,rhs); } inline vInteger operator != (const vInteger & lhs, const vInteger & rhs) { return Comparison(sne(),lhs,rhs); } ////////////////////////////////////////////////////////////////////////// // relational operators // // Support <,>,<=,>=,==,!= // //Query supporting bitwise &, |, ^, ! //Query supporting logical &&, ||, ////////////////////////////////////////////////////////////////////////// template inline Lattice LLComparison(vfunctor op,const Lattice &lhs,const Lattice &rhs) { Lattice ret(rhs._grid); #pragma omp parallel for for(int ss=0;ssoSites(); ss++){ ret._odata[ss]=op(lhs._odata[ss],rhs._odata[ss]); } return ret; } template inline Lattice LSComparison(vfunctor op,const Lattice &lhs,const robj &rhs) { Lattice ret(lhs._grid); #pragma omp parallel for for(int ss=0;ssoSites(); ss++){ ret._odata[ss]=op(lhs._odata[ss],rhs); } return ret; } template inline Lattice SLComparison(vfunctor op,const lobj &lhs,const Lattice &rhs) { Lattice ret(rhs._grid); #pragma omp parallel for for(int ss=0;ssoSites(); ss++){ ret._odata[ss]=op(lhs._odata[ss],rhs); } return ret; } // Less than template inline Lattice operator < (const Lattice & lhs, const Lattice & rhs) { return LLComparison(vlt(),lhs,rhs); } template inline Lattice operator < (const Lattice & lhs, const robj & rhs) { return LSComparison(vlt(),lhs,rhs); } template inline Lattice operator < (const lobj & lhs, const Lattice & rhs) { return SLComparison(vlt(),lhs,rhs); } // Less than equal template inline Lattice operator <= (const Lattice & lhs, const Lattice & rhs) { return LLComparison(vle(),lhs,rhs); } template inline Lattice operator <= (const Lattice & lhs, const robj & rhs) { return LSComparison(vle(),lhs,rhs); } template inline Lattice operator <= (const lobj & lhs, const Lattice & rhs) { return SLComparison(vle(),lhs,rhs); } // Greater than template inline Lattice operator > (const Lattice & lhs, const Lattice & rhs) { return LLComparison(vgt(),lhs,rhs); } template inline Lattice operator > (const Lattice & lhs, const robj & rhs) { return LSComparison(vgt(),lhs,rhs); } template inline Lattice operator > (const lobj & lhs, const Lattice & rhs) { return SLComparison(vgt(),lhs,rhs); } // Greater than equal template inline Lattice operator >= (const Lattice & lhs, const Lattice & rhs) { return LLComparison(vge(),lhs,rhs); } template inline Lattice operator >= (const Lattice & lhs, const robj & rhs) { return LSComparison(vge(),lhs,rhs); } template inline Lattice operator >= (const lobj & lhs, const Lattice & rhs) { return SLComparison(vge(),lhs,rhs); } // equal template inline Lattice operator == (const Lattice & lhs, const Lattice & rhs) { return LLComparison(veq(),lhs,rhs); } template inline Lattice operator == (const Lattice & lhs, const robj & rhs) { return LSComparison(veq(),lhs,rhs); } template inline Lattice operator == (const lobj & lhs, const Lattice & rhs) { return SLComparison(veq(),lhs,rhs); } // not equal template inline Lattice operator != (const Lattice & lhs, const Lattice & rhs) { return LLComparison(vne(),lhs,rhs); } template inline Lattice operator != (const Lattice & lhs, const robj & rhs) { return LSComparison(vne(),lhs,rhs); } template inline Lattice operator != (const lobj & lhs, const Lattice & rhs) { return SLComparison(vne(),lhs,rhs); } } #endif