/************************************************************************************* Grid physics library, www.github.com/paboyle/Grid Source file: ./lib/tensors/Tensor_transpose.h Copyright (C) 2015 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_MATH_TRANSPOSE_H #define GRID_MATH_TRANSPOSE_H NAMESPACE_BEGIN(Grid); ///////////////////////////////////////////////////////////////// // Transpose all indices ///////////////////////////////////////////////////////////////// accelerator_inline ComplexD transpose(ComplexD &rhs){ return rhs;} accelerator_inline ComplexF transpose(ComplexF &rhs){ return rhs;} accelerator_inline RealD transpose(RealD &rhs){ return rhs;} accelerator_inline RealF transpose(RealF &rhs){ return rhs;} template accelerator_inline typename std::enable_if::value, iMatrix >::type transpose(iMatrix arg) { iMatrix ret; for(int i=0;i accelerator_inline typename std::enable_if::notvalue, iMatrix >::type transpose(iMatrix arg) { iMatrix ret; for(int i=0;i accelerator_inline typename std::enable_if::value, iScalar >::type transpose(iScalar arg) { iScalar ret; ret._internal = transpose(arg._internal); // NB recurses return ret; } template accelerator_inline typename std::enable_if::notvalue, iScalar >::type transpose(iScalar arg) { iScalar ret; ret._internal = arg._internal; // NB recursion stops return ret; } //////////////////////////////////////////////////////////////////////////////////////////// // Transpose a specific index; instructive to compare this style of recursion termination // to that of adj; which is easiers? //////////////////////////////////////////////////////////////////////////////////////////// #if 0 template accelerator_inline typename std::enable_if,Level>::value, iMatrix >::type transposeIndex (const iMatrix &arg) { iMatrix ret; for(int i=0;i accelerator_inline typename std::enable_if,Level>::notvalue, iMatrix >::type transposeIndex (const iMatrix &arg) { iMatrix ret; for(int i=0;i(arg._internal[i][j]); }} return ret; } template accelerator_inline typename std::enable_if,Level>::notvalue, iScalar >::type transposeIndex (const iScalar &arg) { iScalar ret; ret._internal=transposeIndex(arg._internal); return ret; } template accelerator_inline typename std::enable_if,Level>::value, iScalar >::type transposeIndex (const iScalar &arg) { return arg; } #endif NAMESPACE_END(Grid); #endif