/************************************************************************************* Grid physics library, www.github.com/paboyle/Grid Source file: ./lib/lattice/Lattice_comparison.h Copyright (C) 2015 Author: Azusa Yamaguchi Author: Peter Boyle This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. See the full license in the file "LICENSE" in the top level distribution directory *************************************************************************************/ /* END LEGAL */ #ifndef GRID_LATTICE_COMPARISON_H #define GRID_LATTICE_COMPARISON_H namespace Grid { ////////////////////////////////////////////////////////////////////////// // relational operators // // Support <,>,<=,>=,==,!= // //Query supporting bitwise &, |, ^, ! //Query supporting logical &&, ||, ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// // compare lattice to lattice ////////////////////////////////////////////////////////////////////////// template inline Lattice LLComparison(vfunctor op,const Lattice &lhs,const Lattice &rhs) { Lattice ret(rhs._grid); PARALLEL_FOR_LOOP for(int ss=0;ssoSites(); ss++){ ret._odata[ss]=op(lhs._odata[ss],rhs._odata[ss]); } return ret; } ////////////////////////////////////////////////////////////////////////// // compare lattice to scalar ////////////////////////////////////////////////////////////////////////// template inline Lattice LSComparison(vfunctor op,const Lattice &lhs,const robj &rhs) { Lattice ret(lhs._grid); PARALLEL_FOR_LOOP for(int ss=0;ssoSites(); ss++){ ret._odata[ss]=op(lhs._odata[ss],rhs); } return ret; } ////////////////////////////////////////////////////////////////////////// // compare scalar to lattice ////////////////////////////////////////////////////////////////////////// template inline Lattice SLComparison(vfunctor op,const lobj &lhs,const Lattice &rhs) { Lattice ret(rhs._grid); PARALLEL_FOR_LOOP for(int ss=0;ssoSites(); ss++){ ret._odata[ss]=op(lhs._odata[ss],rhs); } return ret; } ////////////////////////////////////////////////////////////////////////// // Map to functors ////////////////////////////////////////////////////////////////////////// // 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