#ifndef GRID_MATH_PEEK_H #define GRID_MATH_PEEK_H namespace Grid { ////////////////////////////////////////////////////////////////////////////// // Peek on a specific index; returns a scalar in that index, tensor inherits rest ////////////////////////////////////////////////////////////////////////////// // If we hit the right index, return scalar with no further recursion //template inline ComplexF peekIndex(const ComplexF arg) { return arg;} //template inline ComplexD peekIndex(const ComplexD arg) { return arg;} //template inline RealF peekIndex(const RealF arg) { return arg;} //template inline RealD peekIndex(const RealD arg) { return arg;} // Scalar peek, no indices template inline auto peekIndex(const iScalar &arg) -> typename std::enable_if,Level>::value, // Index matches iScalar >::type // return scalar { return arg; } // Vector peek, one index template inline auto peekIndex(const iVector &arg,int i) -> typename std::enable_if,Level>::value, // Index matches iScalar >::type // return scalar { iScalar ret; // return scalar ret._internal = arg._internal[i]; return ret; } // Matrix peek, two indices template inline auto peekIndex(const iMatrix &arg,int i,int j) -> typename std::enable_if,Level>::value, // Index matches iScalar >::type // return scalar { iScalar ret; // return scalar ret._internal = arg._internal[i][j]; return ret; } ///////////// // No match peek for scalar,vector,matrix must forward on either 0,1,2 args. Must have 9 routines with notvalue ///////////// // scalar template inline auto peekIndex(const iScalar &arg) -> // Scalar 0 index typename std::enable_if,Level>::notvalue, // Index does NOT match iScalar(arg._internal))> >::type { iScalar(arg._internal))> ret; ret._internal= peekIndex(arg._internal); return ret; } template inline auto peekIndex(const iScalar &arg,int i) -> // Scalar 1 index typename std::enable_if,Level>::notvalue, // Index does NOT match iScalar(arg._internal,i))> >::type { iScalar(arg._internal,i))> ret; ret._internal=peekIndex(arg._internal,i); return ret; } template inline auto peekIndex(const iScalar &arg,int i,int j) -> // Scalar, 2 index typename std::enable_if,Level>::notvalue, // Index does NOT match iScalar(arg._internal,i,j))> >::type { iScalar(arg._internal,i,j))> ret; ret._internal=peekIndex(arg._internal,i,j); return ret; } // vector template inline auto peekIndex(const iVector &arg) -> typename std::enable_if,Level>::notvalue, // Index does not match iVector(arg._internal[0])),N> >::type { iVector(arg._internal[0])),N> ret; for(int ii=0;ii(arg._internal[ii]); } return ret; } template inline auto peekIndex(const iVector &arg,int i) -> typename std::enable_if,Level>::notvalue, // Index does not match iVector(arg._internal[0],i)),N> >::type { iVector(arg._internal[0],i)),N> ret; for(int ii=0;ii(arg._internal[ii],i); } return ret; } template inline auto peekIndex(const iVector &arg,int i,int j) -> typename std::enable_if,Level>::notvalue, // Index does not match iVector(arg._internal[0],i,j)),N> >::type { iVector(arg._internal[0],i,j)),N> ret; for(int ii=0;ii(arg._internal[ii],i,j); } return ret; } // matrix template inline auto peekIndex(const iMatrix &arg) -> typename std::enable_if,Level>::notvalue, // Index does not match iMatrix(arg._internal[0][0])),N> >::type { iMatrix(arg._internal[0][0])),N> ret; for(int ii=0;ii(arg._internal[ii][jj]);// Could avoid this because peeking a scalar is dumb }} return ret; } template inline auto peekIndex(const iMatrix &arg,int i) -> typename std::enable_if,Level>::notvalue, // Index does not match iMatrix(arg._internal[0],i)),N> >::type { iMatrix(arg._internal[0],i)),N> ret; for(int ii=0;ii(arg._internal[ii][jj],i); }} return ret; } template inline auto peekIndex(const iMatrix &arg,int i,int j) -> typename std::enable_if,Level>::notvalue, // Index does not match iMatrix(arg._internal[0][0],i,j)),N> >::type { iMatrix(arg._internal[0][0],i,j)),N> ret; for(int ii=0;ii(arg._internal[ii][jj],i,j); }} return ret; } } #endif