mirror of
https://github.com/paboyle/Grid.git
synced 2025-04-28 06:35:55 +01:00
Tensor reformatted with NAMESPACE too
This commit is contained in:
parent
f4272aa6fd
commit
c037244874
@ -1,4 +1,4 @@
|
|||||||
/*************************************************************************************
|
/*************************************************************************************
|
||||||
|
|
||||||
Grid physics library, www.github.com/paboyle/Grid
|
Grid physics library, www.github.com/paboyle/Grid
|
||||||
|
|
||||||
@ -24,72 +24,72 @@ Author: neo <cossu@post.kek.jp>
|
|||||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
See the full license in the file "LICENSE" in the top level distribution directory
|
See the full license in the file "LICENSE" in the top level distribution directory
|
||||||
*************************************************************************************/
|
*************************************************************************************/
|
||||||
/* END LEGAL */
|
/* END LEGAL */
|
||||||
#ifndef GRID_MATH_TA_H
|
#ifndef GRID_MATH_TA_H
|
||||||
#define GRID_MATH_TA_H
|
#define GRID_MATH_TA_H
|
||||||
|
|
||||||
|
|
||||||
namespace Grid {
|
NAMESPACE_BEGIN(Grid);
|
||||||
|
|
||||||
///////////////////////////////////////////////
|
///////////////////////////////////////////////
|
||||||
// Ta function for scalar, vector, matrix
|
// Ta function for scalar, vector, matrix
|
||||||
///////////////////////////////////////////////
|
///////////////////////////////////////////////
|
||||||
/*
|
/*
|
||||||
inline ComplexF Ta( const ComplexF &arg){ return arg;}
|
inline ComplexF Ta( const ComplexF &arg){ return arg;}
|
||||||
inline ComplexD Ta( const ComplexD &arg){ return arg;}
|
inline ComplexD Ta( const ComplexD &arg){ return arg;}
|
||||||
inline RealF Ta( const RealF &arg){ return arg;}
|
inline RealF Ta( const RealF &arg){ return arg;}
|
||||||
inline RealD Ta( const RealD &arg){ return arg;}
|
inline RealD Ta( const RealD &arg){ return arg;}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
template<class vtype> inline iScalar<vtype> Ta(const iScalar<vtype>&r)
|
template<class vtype> inline iScalar<vtype> Ta(const iScalar<vtype>&r)
|
||||||
{
|
{
|
||||||
iScalar<vtype> ret;
|
iScalar<vtype> ret;
|
||||||
ret._internal = Ta(r._internal);
|
ret._internal = Ta(r._internal);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
template<class vtype,int N> inline iVector<vtype,N> Ta(const iVector<vtype,N>&r)
|
template<class vtype,int N> inline iVector<vtype,N> Ta(const iVector<vtype,N>&r)
|
||||||
{
|
{
|
||||||
iVector<vtype,N> ret;
|
iVector<vtype,N> ret;
|
||||||
for(int i=0;i<N;i++){
|
for(int i=0;i<N;i++){
|
||||||
ret._internal[i] = Ta(r._internal[i]);
|
ret._internal[i] = Ta(r._internal[i]);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
template<class vtype,int N> inline iMatrix<vtype,N> Ta(const iMatrix<vtype,N> &arg)
|
template<class vtype,int N> inline iMatrix<vtype,N> Ta(const iMatrix<vtype,N> &arg)
|
||||||
{
|
{
|
||||||
iMatrix<vtype,N> ret;
|
iMatrix<vtype,N> ret;
|
||||||
|
|
||||||
double factor = (1.0/(double)N);
|
double factor = (1.0/(double)N);
|
||||||
ret= (arg - adj(arg))*0.5;
|
ret= (arg - adj(arg))*0.5;
|
||||||
ret=ret - (trace(ret)*factor);
|
ret=ret - (trace(ret)*factor);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////
|
///////////////////////////////////////////////
|
||||||
// ProjectOnGroup function for scalar, vector, matrix
|
// ProjectOnGroup function for scalar, vector, matrix
|
||||||
// Projects on orthogonal, unitary group
|
// Projects on orthogonal, unitary group
|
||||||
///////////////////////////////////////////////
|
///////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
template<class vtype> inline iScalar<vtype> ProjectOnGroup(const iScalar<vtype>&r)
|
template<class vtype> inline iScalar<vtype> ProjectOnGroup(const iScalar<vtype>&r)
|
||||||
{
|
{
|
||||||
iScalar<vtype> ret;
|
iScalar<vtype> ret;
|
||||||
ret._internal = ProjectOnGroup(r._internal);
|
ret._internal = ProjectOnGroup(r._internal);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
template<class vtype,int N> inline iVector<vtype,N> ProjectOnGroup(const iVector<vtype,N>&r)
|
template<class vtype,int N> inline iVector<vtype,N> ProjectOnGroup(const iVector<vtype,N>&r)
|
||||||
{
|
{
|
||||||
iVector<vtype,N> ret;
|
iVector<vtype,N> ret;
|
||||||
for(int i=0;i<N;i++){
|
for(int i=0;i<N;i++){
|
||||||
ret._internal[i] = ProjectOnGroup(r._internal[i]);
|
ret._internal[i] = ProjectOnGroup(r._internal[i]);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
template<class vtype,int N, typename std::enable_if< GridTypeMapper<vtype>::TensorLevel == 0 >::type * =nullptr>
|
template<class vtype,int N, typename std::enable_if< GridTypeMapper<vtype>::TensorLevel == 0 >::type * =nullptr>
|
||||||
inline iMatrix<vtype,N> ProjectOnGroup(const iMatrix<vtype,N> &arg)
|
inline iMatrix<vtype,N> ProjectOnGroup(const iMatrix<vtype,N> &arg)
|
||||||
{
|
{
|
||||||
// need a check for the group type?
|
// need a check for the group type?
|
||||||
iMatrix<vtype,N> ret(arg);
|
iMatrix<vtype,N> ret(arg);
|
||||||
vtype nrm;
|
vtype nrm;
|
||||||
@ -117,9 +117,8 @@ namespace Grid {
|
|||||||
}
|
}
|
||||||
// assuming the determinant is ok
|
// assuming the determinant is ok
|
||||||
return ret;
|
return ret;
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NAMESPACE_END(Grid);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/*************************************************************************************
|
/*************************************************************************************
|
||||||
|
|
||||||
Grid physics library, www.github.com/paboyle/Grid
|
Grid physics library, www.github.com/paboyle/Grid
|
||||||
|
|
||||||
@ -23,8 +23,8 @@ Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
|||||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
See the full license in the file "LICENSE" in the top level distribution directory
|
See the full license in the file "LICENSE" in the top level distribution directory
|
||||||
*************************************************************************************/
|
*************************************************************************************/
|
||||||
/* END LEGAL */
|
/* END LEGAL */
|
||||||
#ifndef GRID_MATH_ARITH_H
|
#ifndef GRID_MATH_ARITH_H
|
||||||
#define GRID_MATH_ARITH_H
|
#define GRID_MATH_ARITH_H
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/*************************************************************************************
|
/*************************************************************************************
|
||||||
|
|
||||||
Grid physics library, www.github.com/paboyle/Grid
|
Grid physics library, www.github.com/paboyle/Grid
|
||||||
|
|
||||||
@ -24,53 +24,53 @@ Author: neo <cossu@post.kek.jp>
|
|||||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
See the full license in the file "LICENSE" in the top level distribution directory
|
See the full license in the file "LICENSE" in the top level distribution directory
|
||||||
*************************************************************************************/
|
*************************************************************************************/
|
||||||
/* END LEGAL */
|
/* END LEGAL */
|
||||||
#ifndef GRID_MATH_ARITH_ADD_H
|
#ifndef GRID_MATH_ARITH_ADD_H
|
||||||
#define GRID_MATH_ARITH_ADD_H
|
#define GRID_MATH_ARITH_ADD_H
|
||||||
|
|
||||||
namespace Grid {
|
NAMESPACE_BEGIN(Grid);
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
/////////////////////////////////////////// ADD ///////////////////////////////////////////
|
/////////////////////////////////////////// ADD ///////////////////////////////////////////
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
// ADD is simple for now; cannot mix types and straightforward template
|
// ADD is simple for now; cannot mix types and straightforward template
|
||||||
// Scalar +/- Scalar
|
// Scalar +/- Scalar
|
||||||
// Vector +/- Vector
|
// Vector +/- Vector
|
||||||
// Matrix +/- Matrix
|
// Matrix +/- Matrix
|
||||||
template<class vtype,class ltype,class rtype> strong_inline void add(iScalar<vtype> * __restrict__ ret,
|
template<class vtype,class ltype,class rtype> strong_inline void add(iScalar<vtype> * __restrict__ ret,
|
||||||
const iScalar<ltype> * __restrict__ lhs,
|
const iScalar<ltype> * __restrict__ lhs,
|
||||||
const iScalar<rtype> * __restrict__ rhs)
|
const iScalar<rtype> * __restrict__ rhs)
|
||||||
{
|
{
|
||||||
add(&ret->_internal,&lhs->_internal,&rhs->_internal);
|
add(&ret->_internal,&lhs->_internal,&rhs->_internal);
|
||||||
}
|
}
|
||||||
template<class vtype,class ltype,class rtype,int N> strong_inline void add(iVector<vtype,N> * __restrict__ ret,
|
template<class vtype,class ltype,class rtype,int N> strong_inline void add(iVector<vtype,N> * __restrict__ ret,
|
||||||
const iVector<ltype,N> * __restrict__ lhs,
|
const iVector<ltype,N> * __restrict__ lhs,
|
||||||
const iVector<rtype,N> * __restrict__ rhs)
|
const iVector<rtype,N> * __restrict__ rhs)
|
||||||
{
|
{
|
||||||
for(int c=0;c<N;c++){
|
for(int c=0;c<N;c++){
|
||||||
ret->_internal[c]=lhs->_internal[c]+rhs->_internal[c];
|
ret->_internal[c]=lhs->_internal[c]+rhs->_internal[c];
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class vtype,class ltype,class rtype, int N> strong_inline void add(iMatrix<vtype,N> * __restrict__ ret,
|
template<class vtype,class ltype,class rtype, int N> strong_inline void add(iMatrix<vtype,N> * __restrict__ ret,
|
||||||
const iMatrix<ltype,N> * __restrict__ lhs,
|
const iMatrix<ltype,N> * __restrict__ lhs,
|
||||||
const iMatrix<rtype,N> * __restrict__ rhs)
|
const iMatrix<rtype,N> * __restrict__ rhs)
|
||||||
{
|
{
|
||||||
for(int c2=0;c2<N;c2++){
|
for(int c2=0;c2<N;c2++){
|
||||||
for(int c1=0;c1<N;c1++){
|
for(int c1=0;c1<N;c1++){
|
||||||
add(&ret->_internal[c1][c2],&lhs->_internal[c1][c2],&rhs->_internal[c1][c2]);
|
add(&ret->_internal[c1][c2],&lhs->_internal[c1][c2],&rhs->_internal[c1][c2]);
|
||||||
}}
|
}}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
template<class vtype,class ltype,class rtype, int N> strong_inline void add(iMatrix<vtype,N> * __restrict__ ret,
|
template<class vtype,class ltype,class rtype, int N> strong_inline void add(iMatrix<vtype,N> * __restrict__ ret,
|
||||||
const iScalar<ltype> * __restrict__ lhs,
|
const iScalar<ltype> * __restrict__ lhs,
|
||||||
const iMatrix<rtype,N> * __restrict__ rhs)
|
const iMatrix<rtype,N> * __restrict__ rhs)
|
||||||
{
|
{
|
||||||
for(int c2=0;c2<N;c2++){
|
for(int c2=0;c2<N;c2++){
|
||||||
for(int c1=0;c1<N;c1++){
|
for(int c1=0;c1<N;c1++){
|
||||||
if ( c1==c2)
|
if ( c1==c2)
|
||||||
@ -79,11 +79,11 @@ namespace Grid {
|
|||||||
ret->_internal[c1][c2]=lhs->_internal[c1][c2];
|
ret->_internal[c1][c2]=lhs->_internal[c1][c2];
|
||||||
}}
|
}}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
template<class vtype,class ltype,class rtype, int N> strong_inline void add(iMatrix<vtype,N> * __restrict__ ret,
|
template<class vtype,class ltype,class rtype, int N> strong_inline void add(iMatrix<vtype,N> * __restrict__ ret,
|
||||||
const iMatrix<ltype,N> * __restrict__ lhs,
|
const iMatrix<ltype,N> * __restrict__ lhs,
|
||||||
const iScalar<rtype> * __restrict__ rhs)
|
const iScalar<rtype> * __restrict__ rhs)
|
||||||
{
|
{
|
||||||
for(int c2=0;c2<N;c2++){
|
for(int c2=0;c2<N;c2++){
|
||||||
for(int c1=0;c1<N;c1++){
|
for(int c1=0;c1<N;c1++){
|
||||||
if ( c1==c2)
|
if ( c1==c2)
|
||||||
@ -92,55 +92,54 @@ namespace Grid {
|
|||||||
ret->_internal[c1][c2]=lhs->_internal[c1][c2];
|
ret->_internal[c1][c2]=lhs->_internal[c1][c2];
|
||||||
}}
|
}}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// + operator for scalar, vector, matrix
|
// + operator for scalar, vector, matrix
|
||||||
template<class ltype,class rtype>
|
template<class ltype,class rtype>
|
||||||
//strong_inline auto operator + (iScalar<ltype>& lhs,iScalar<rtype>&& rhs) -> iScalar<decltype(lhs._internal + rhs._internal)>
|
//strong_inline auto operator + (iScalar<ltype>& lhs,iScalar<rtype>&& rhs) -> iScalar<decltype(lhs._internal + rhs._internal)>
|
||||||
strong_inline auto operator + (const iScalar<ltype>& lhs,const iScalar<rtype>& rhs) -> iScalar<decltype(lhs._internal + rhs._internal)>
|
strong_inline auto operator + (const iScalar<ltype>& lhs,const iScalar<rtype>& rhs) -> iScalar<decltype(lhs._internal + rhs._internal)>
|
||||||
{
|
{
|
||||||
typedef iScalar<decltype(lhs._internal+rhs._internal)> ret_t;
|
typedef iScalar<decltype(lhs._internal+rhs._internal)> ret_t;
|
||||||
ret_t ret;
|
ret_t ret;
|
||||||
add(&ret,&lhs,&rhs);
|
add(&ret,&lhs,&rhs);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
template<class ltype,class rtype,int N>
|
template<class ltype,class rtype,int N>
|
||||||
strong_inline auto operator + (const iVector<ltype,N>& lhs,const iVector<rtype,N>& rhs) ->iVector<decltype(lhs._internal[0]+rhs._internal[0]),N>
|
strong_inline auto operator + (const iVector<ltype,N>& lhs,const iVector<rtype,N>& rhs) ->iVector<decltype(lhs._internal[0]+rhs._internal[0]),N>
|
||||||
{
|
{
|
||||||
typedef iVector<decltype(lhs._internal[0]+rhs._internal[0]),N> ret_t;
|
typedef iVector<decltype(lhs._internal[0]+rhs._internal[0]),N> ret_t;
|
||||||
ret_t ret;
|
ret_t ret;
|
||||||
add(&ret,&lhs,&rhs);
|
add(&ret,&lhs,&rhs);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
template<class ltype,class rtype,int N>
|
template<class ltype,class rtype,int N>
|
||||||
strong_inline auto operator + (const iMatrix<ltype,N>& lhs,const iMatrix<rtype,N>& rhs) ->iMatrix<decltype(lhs._internal[0][0]+rhs._internal[0][0]),N>
|
strong_inline auto operator + (const iMatrix<ltype,N>& lhs,const iMatrix<rtype,N>& rhs) ->iMatrix<decltype(lhs._internal[0][0]+rhs._internal[0][0]),N>
|
||||||
{
|
{
|
||||||
typedef iMatrix<decltype(lhs._internal[0][0]+rhs._internal[0][0]),N> ret_t;
|
typedef iMatrix<decltype(lhs._internal[0][0]+rhs._internal[0][0]),N> ret_t;
|
||||||
ret_t ret;
|
ret_t ret;
|
||||||
add(&ret,&lhs,&rhs);
|
add(&ret,&lhs,&rhs);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
template<class ltype,class rtype,int N>
|
template<class ltype,class rtype,int N>
|
||||||
strong_inline auto operator + (const iScalar<ltype>& lhs,const iMatrix<rtype,N>& rhs)->iMatrix<decltype(lhs._internal+rhs._internal[0][0]),N>
|
strong_inline auto operator + (const iScalar<ltype>& lhs,const iMatrix<rtype,N>& rhs)->iMatrix<decltype(lhs._internal+rhs._internal[0][0]),N>
|
||||||
{
|
{
|
||||||
typedef iMatrix<decltype(lhs._internal+rhs._internal[0][0]),N> ret_t;
|
typedef iMatrix<decltype(lhs._internal+rhs._internal[0][0]),N> ret_t;
|
||||||
ret_t ret;
|
ret_t ret;
|
||||||
add(&ret,&lhs,&rhs);
|
add(&ret,&lhs,&rhs);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class ltype,class rtype,int N>
|
template<class ltype,class rtype,int N>
|
||||||
strong_inline auto operator + (const iMatrix<ltype,N>& lhs,const iScalar<rtype>& rhs)->iMatrix<decltype(lhs._internal[0][0]+rhs._internal),N>
|
strong_inline auto operator + (const iMatrix<ltype,N>& lhs,const iScalar<rtype>& rhs)->iMatrix<decltype(lhs._internal[0][0]+rhs._internal),N>
|
||||||
{
|
{
|
||||||
typedef iMatrix<decltype(lhs._internal[0][0]+rhs._internal),N> ret_t;
|
typedef iMatrix<decltype(lhs._internal[0][0]+rhs._internal),N> ret_t;
|
||||||
ret_t ret;
|
ret_t ret;
|
||||||
add(&ret,&lhs,&rhs);
|
add(&ret,&lhs,&rhs);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NAMESPACE_END(Grid);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/*************************************************************************************
|
/*************************************************************************************
|
||||||
|
|
||||||
Grid physics library, www.github.com/paboyle/Grid
|
Grid physics library, www.github.com/paboyle/Grid
|
||||||
|
|
||||||
@ -23,30 +23,29 @@ Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
|||||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
See the full license in the file "LICENSE" in the top level distribution directory
|
See the full license in the file "LICENSE" in the top level distribution directory
|
||||||
*************************************************************************************/
|
*************************************************************************************/
|
||||||
/* END LEGAL */
|
/* END LEGAL */
|
||||||
#ifndef GRID_MATH_ARITH_MAC_H
|
#ifndef GRID_MATH_ARITH_MAC_H
|
||||||
#define GRID_MATH_ARITH_MAC_H
|
#define GRID_MATH_ARITH_MAC_H
|
||||||
|
|
||||||
namespace Grid {
|
NAMESPACE_BEGIN(Grid);
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
/////////////////////////////////////////// MAC ///////////////////////////////////////////
|
/////////////////////////////////////////// MAC ///////////////////////////////////////////
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
///////////////////////////
|
///////////////////////////
|
||||||
|
|
||||||
///////////////////////////
|
///////////////////////////
|
||||||
// Legal multiplication table
|
// Legal multiplication table
|
||||||
///////////////////////////
|
///////////////////////////
|
||||||
// scal x scal = scal
|
// scal x scal = scal
|
||||||
// mat x mat = mat
|
// mat x mat = mat
|
||||||
// mat x scal = mat
|
// mat x scal = mat
|
||||||
// scal x mat = mat
|
// scal x mat = mat
|
||||||
// mat x vec = vec
|
// mat x vec = vec
|
||||||
// vec x scal = vec
|
// vec x scal = vec
|
||||||
// scal x vec = vec
|
// scal x vec = vec
|
||||||
///////////////////////////
|
///////////////////////////
|
||||||
template<class rtype,class vtype,class mtype>
|
template<class rtype,class vtype,class mtype>
|
||||||
strong_inline void mac(iScalar<rtype> * __restrict__ ret,const iScalar<vtype> * __restrict__ lhs,const iScalar<mtype> * __restrict__ rhs)
|
strong_inline void mac(iScalar<rtype> * __restrict__ ret,const iScalar<vtype> * __restrict__ lhs,const iScalar<mtype> * __restrict__ rhs)
|
||||||
{
|
{
|
||||||
@ -103,6 +102,7 @@ strong_inline void mac(iVector<rrtype,N> * __restrict__ ret,const iVector<ltype,
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
NAMESPACE_END(Grid);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/*************************************************************************************
|
/*************************************************************************************
|
||||||
|
|
||||||
Grid physics library, www.github.com/paboyle/Grid
|
Grid physics library, www.github.com/paboyle/Grid
|
||||||
|
|
||||||
@ -23,17 +23,16 @@ Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
|||||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
See the full license in the file "LICENSE" in the top level distribution directory
|
See the full license in the file "LICENSE" in the top level distribution directory
|
||||||
*************************************************************************************/
|
*************************************************************************************/
|
||||||
/* END LEGAL */
|
/* END LEGAL */
|
||||||
#ifndef GRID_MATH_ARITH_MUL_H
|
#ifndef GRID_MATH_ARITH_MUL_H
|
||||||
#define GRID_MATH_ARITH_MUL_H
|
#define GRID_MATH_ARITH_MUL_H
|
||||||
|
|
||||||
namespace Grid {
|
NAMESPACE_BEGIN(Grid);
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////// MUL ///////////////////////////////////////////
|
||||||
/////////////////////////////////////////// MUL ///////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
template<class rtype,class vtype,class mtype>
|
template<class rtype,class vtype,class mtype>
|
||||||
strong_inline void mult(iScalar<rtype> * __restrict__ ret,const iScalar<mtype> * __restrict__ lhs,const iScalar<vtype> * __restrict__ rhs){
|
strong_inline void mult(iScalar<rtype> * __restrict__ ret,const iScalar<mtype> * __restrict__ lhs,const iScalar<vtype> * __restrict__ rhs){
|
||||||
@ -159,21 +158,21 @@ iMatrix<rtype,N> operator / (const iMatrix<rtype,N>& lhs,const iScalar<vtype>& r
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
// Glue operators to mult routines. Must resolve return type cleverly from typeof(internal)
|
// Glue operators to mult routines. Must resolve return type cleverly from typeof(internal)
|
||||||
// since nesting matrix<scalar> x matrix<matrix>-> matrix<matrix>
|
// since nesting matrix<scalar> x matrix<matrix>-> matrix<matrix>
|
||||||
// while matrix<scalar> x matrix<scalar>-> matrix<scalar>
|
// while matrix<scalar> x matrix<scalar>-> matrix<scalar>
|
||||||
// so return type depends on argument types in nasty way.
|
// so return type depends on argument types in nasty way.
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
// scal x scal = scal
|
// scal x scal = scal
|
||||||
// mat x mat = mat
|
// mat x mat = mat
|
||||||
// mat x scal = mat
|
// mat x scal = mat
|
||||||
// scal x mat = mat
|
// scal x mat = mat
|
||||||
// mat x vec = vec
|
// mat x vec = vec
|
||||||
// vec x scal = vec
|
// vec x scal = vec
|
||||||
// scal x vec = vec
|
// scal x vec = vec
|
||||||
//
|
//
|
||||||
// We can special case scalar_type ??
|
// We can special case scalar_type ??
|
||||||
template<class l,class r>
|
template<class l,class r>
|
||||||
strong_inline auto operator * (const iScalar<l>& lhs,const iScalar<r>& rhs) -> iScalar<decltype(lhs._internal * rhs._internal)>
|
strong_inline auto operator * (const iScalar<l>& lhs,const iScalar<r>& rhs) -> iScalar<decltype(lhs._internal * rhs._internal)>
|
||||||
{
|
{
|
||||||
@ -247,7 +246,7 @@ auto operator * (const iVector<l,N>& lhs,const iScalar<r>& rhs) -> iVector<declt
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NAMESPACE_END(Grid);
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/*************************************************************************************
|
/*************************************************************************************
|
||||||
|
|
||||||
Grid physics library, www.github.com/paboyle/Grid
|
Grid physics library, www.github.com/paboyle/Grid
|
||||||
|
|
||||||
@ -24,13 +24,12 @@ Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
|||||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
See the full license in the file "LICENSE" in the top level distribution directory
|
See the full license in the file "LICENSE" in the top level distribution directory
|
||||||
*************************************************************************************/
|
*************************************************************************************/
|
||||||
/* END LEGAL */
|
/* END LEGAL */
|
||||||
#ifndef GRID_MATH_ARITH_SCALAR_H
|
#ifndef GRID_MATH_ARITH_SCALAR_H
|
||||||
#define GRID_MATH_ARITH_SCALAR_H
|
#define GRID_MATH_ARITH_SCALAR_H
|
||||||
|
|
||||||
namespace Grid {
|
NAMESPACE_BEGIN(Grid);
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// Must support native C++ types Integer, Complex, Real
|
// Must support native C++ types Integer, Complex, Real
|
||||||
@ -283,6 +282,6 @@ template<class l,int N> strong_inline iMatrix<l,N> operator - (Integer lhs,const
|
|||||||
return slhs-rhs;
|
return slhs-rhs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NAMESPACE_END(Grid);
|
||||||
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/*************************************************************************************
|
/*************************************************************************************
|
||||||
|
|
||||||
Grid physics library, www.github.com/paboyle/Grid
|
Grid physics library, www.github.com/paboyle/Grid
|
||||||
|
|
||||||
@ -24,17 +24,16 @@ Author: neo <cossu@post.kek.jp>
|
|||||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
See the full license in the file "LICENSE" in the top level distribution directory
|
See the full license in the file "LICENSE" in the top level distribution directory
|
||||||
*************************************************************************************/
|
*************************************************************************************/
|
||||||
/* END LEGAL */
|
/* END LEGAL */
|
||||||
#ifndef GRID_MATH_ARITH_SUB_H
|
#ifndef GRID_MATH_ARITH_SUB_H
|
||||||
#define GRID_MATH_ARITH_SUB_H
|
#define GRID_MATH_ARITH_SUB_H
|
||||||
|
|
||||||
namespace Grid {
|
NAMESPACE_BEGIN(Grid);
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////// SUB ///////////////////////////////////////////
|
||||||
/////////////////////////////////////////// SUB ///////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
|
|
||||||
// SUB is simple for now; cannot mix types and straightforward template
|
// SUB is simple for now; cannot mix types and straightforward template
|
||||||
@ -96,7 +95,7 @@ template<class vtype,class ltype,class rtype, int N> strong_inline void sub(iMat
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// - operator for scalar, vector, matrix
|
// - operator for scalar, vector, matrix
|
||||||
template<class ltype,class rtype> strong_inline auto
|
template<class ltype,class rtype> strong_inline auto
|
||||||
operator - (const iScalar<ltype>& lhs, const iScalar<rtype>& rhs) -> iScalar<decltype(lhs._internal - rhs._internal)>
|
operator - (const iScalar<ltype>& lhs, const iScalar<rtype>& rhs) -> iScalar<decltype(lhs._internal - rhs._internal)>
|
||||||
{
|
{
|
||||||
@ -138,7 +137,6 @@ strong_inline auto operator - (const iMatrix<ltype,N>& lhs,const iScalar<rtype>&
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NAMESPACE_END(Grid);
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -20,11 +20,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
See the full license in the file "LICENSE" in the top level distribution
|
See the full license in the file "LICENSE" in the top level distribution
|
||||||
directory
|
directory
|
||||||
*************************************************************************************/
|
*************************************************************************************/
|
||||||
/* END LEGAL */
|
/* END LEGAL */
|
||||||
#ifndef GRID_MATH_TENSORS_H
|
#ifndef GRID_MATH_TENSORS_H
|
||||||
#define GRID_MATH_TENSORS_H
|
#define GRID_MATH_TENSORS_H
|
||||||
|
|
||||||
namespace Grid {
|
NAMESPACE_BEGIN(Grid);
|
||||||
|
|
||||||
///////////////////////////////////////////////////
|
///////////////////////////////////////////////////
|
||||||
// Scalar, Vector, Matrix objects.
|
// Scalar, Vector, Matrix objects.
|
||||||
@ -44,7 +44,7 @@ class GridTensorBase {};
|
|||||||
|
|
||||||
template <class vtype>
|
template <class vtype>
|
||||||
class iScalar {
|
class iScalar {
|
||||||
public:
|
public:
|
||||||
vtype _internal;
|
vtype _internal;
|
||||||
|
|
||||||
typedef vtype element;
|
typedef vtype element;
|
||||||
@ -191,7 +191,7 @@ strong_inline auto TensorRemove(iScalar<vtype> arg)
|
|||||||
|
|
||||||
template <class vtype, int N>
|
template <class vtype, int N>
|
||||||
class iVector {
|
class iVector {
|
||||||
public:
|
public:
|
||||||
vtype _internal[N];
|
vtype _internal[N];
|
||||||
|
|
||||||
typedef vtype element;
|
typedef vtype element;
|
||||||
@ -307,7 +307,7 @@ class iVector {
|
|||||||
|
|
||||||
template <class vtype, int N>
|
template <class vtype, int N>
|
||||||
class iMatrix {
|
class iMatrix {
|
||||||
public:
|
public:
|
||||||
vtype _internal[N][N];
|
vtype _internal[N][N];
|
||||||
|
|
||||||
typedef vtype element;
|
typedef vtype element;
|
||||||
@ -362,53 +362,53 @@ class iMatrix {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
friend strong_inline void zeroit(iMatrix<vtype,N> &that){
|
friend strong_inline void zeroit(iMatrix<vtype,N> &that){
|
||||||
for(int i=0;i<N;i++){
|
for(int i=0;i<N;i++){
|
||||||
for(int j=0;j<N;j++){
|
for(int j=0;j<N;j++){
|
||||||
zeroit(that._internal[i][j]);
|
zeroit(that._internal[i][j]);
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
friend strong_inline void prefetch(iMatrix<vtype,N> &that){
|
friend strong_inline void prefetch(iMatrix<vtype,N> &that){
|
||||||
for(int i=0;i<N;i++)
|
for(int i=0;i<N;i++)
|
||||||
for(int j=0;j<N;j++)
|
for(int j=0;j<N;j++)
|
||||||
prefetch(that._internal[i][j]);
|
prefetch(that._internal[i][j]);
|
||||||
}
|
}
|
||||||
friend strong_inline void vstream(iMatrix<vtype,N> &out,const iMatrix<vtype,N> &in){
|
friend strong_inline void vstream(iMatrix<vtype,N> &out,const iMatrix<vtype,N> &in){
|
||||||
for(int i=0;i<N;i++){
|
for(int i=0;i<N;i++){
|
||||||
for(int j=0;j<N;j++){
|
for(int j=0;j<N;j++){
|
||||||
vstream(out._internal[i][j],in._internal[i][j]);
|
vstream(out._internal[i][j],in._internal[i][j]);
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
friend strong_inline void vbroadcast(iMatrix<vtype,N> &out,const iMatrix<vtype,N> &in,int lane){
|
friend strong_inline void vbroadcast(iMatrix<vtype,N> &out,const iMatrix<vtype,N> &in,int lane){
|
||||||
for(int i=0;i<N;i++){
|
for(int i=0;i<N;i++){
|
||||||
for(int j=0;j<N;j++){
|
for(int j=0;j<N;j++){
|
||||||
vbroadcast(out._internal[i][j],in._internal[i][j],lane);
|
vbroadcast(out._internal[i][j],in._internal[i][j],lane);
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
friend strong_inline void permute(iMatrix<vtype,N> &out,const iMatrix<vtype,N> &in,int permutetype){
|
friend strong_inline void permute(iMatrix<vtype,N> &out,const iMatrix<vtype,N> &in,int permutetype){
|
||||||
for(int i=0;i<N;i++){
|
for(int i=0;i<N;i++){
|
||||||
for(int j=0;j<N;j++){
|
for(int j=0;j<N;j++){
|
||||||
permute(out._internal[i][j],in._internal[i][j],permutetype);
|
permute(out._internal[i][j],in._internal[i][j],permutetype);
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
friend strong_inline void rotate(iMatrix<vtype,N> &out,const iMatrix<vtype,N> &in,int rot){
|
friend strong_inline void rotate(iMatrix<vtype,N> &out,const iMatrix<vtype,N> &in,int rot){
|
||||||
for(int i=0;i<N;i++){
|
for(int i=0;i<N;i++){
|
||||||
for(int j=0;j<N;j++){
|
for(int j=0;j<N;j++){
|
||||||
rotate(out._internal[i][j],in._internal[i][j],rot);
|
rotate(out._internal[i][j],in._internal[i][j],rot);
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
friend strong_inline void exchange(iMatrix<vtype,N> &out1,iMatrix<vtype,N> &out2,
|
friend strong_inline void exchange(iMatrix<vtype,N> &out1,iMatrix<vtype,N> &out2,
|
||||||
const iMatrix<vtype,N> &in1,const iMatrix<vtype,N> &in2,int type){
|
const iMatrix<vtype,N> &in1,const iMatrix<vtype,N> &in2,int type){
|
||||||
for(int i=0;i<N;i++){
|
for(int i=0;i<N;i++){
|
||||||
for(int j=0;j<N;j++){
|
for(int j=0;j<N;j++){
|
||||||
exchange(out1._internal[i][j],out2._internal[i][j],
|
exchange(out1._internal[i][j],out2._internal[i][j],
|
||||||
in1._internal[i][j], in2._internal[i][j],type);
|
in1._internal[i][j], in2._internal[i][j],type);
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unary negation
|
// Unary negation
|
||||||
friend strong_inline iMatrix<vtype, N> operator-(const iMatrix<vtype, N> &r) {
|
friend strong_inline iMatrix<vtype, N> operator-(const iMatrix<vtype, N> &r) {
|
||||||
iMatrix<vtype, N> ret;
|
iMatrix<vtype, N> ret;
|
||||||
for (int i = 0; i < N; i++) {
|
for (int i = 0; i < N; i++) {
|
||||||
for (int j = 0; j < N; j++) {
|
for (int j = 0; j < N; j++) {
|
||||||
@ -416,30 +416,30 @@ class iMatrix {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
// *=,+=,-= operators inherit from corresponding "*,-,+" behaviour
|
// *=,+=,-= operators inherit from corresponding "*,-,+" behaviour
|
||||||
template <class T>
|
template <class T>
|
||||||
strong_inline iMatrix<vtype, N> &operator*=(const T &r) {
|
strong_inline iMatrix<vtype, N> &operator*=(const T &r) {
|
||||||
*this = (*this) * r;
|
*this = (*this) * r;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
template <class T>
|
template <class T>
|
||||||
strong_inline iMatrix<vtype, N> &operator-=(const T &r) {
|
strong_inline iMatrix<vtype, N> &operator-=(const T &r) {
|
||||||
*this = (*this) - r;
|
*this = (*this) - r;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
template <class T>
|
template <class T>
|
||||||
strong_inline iMatrix<vtype, N> &operator+=(const T &r) {
|
strong_inline iMatrix<vtype, N> &operator+=(const T &r) {
|
||||||
*this = (*this) + r;
|
*this = (*this) + r;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns an lvalue reference
|
// returns an lvalue reference
|
||||||
strong_inline vtype &operator()(int i, int j) { return _internal[i][j]; }
|
strong_inline vtype &operator()(int i, int j) { return _internal[i][j]; }
|
||||||
strong_inline const vtype &operator()(int i, int j) const {
|
strong_inline const vtype &operator()(int i, int j) const {
|
||||||
return _internal[i][j];
|
return _internal[i][j];
|
||||||
}
|
}
|
||||||
friend std::ostream &operator<<(std::ostream &stream,
|
friend std::ostream &operator<<(std::ostream &stream,
|
||||||
const iMatrix<vtype, N> &o) {
|
const iMatrix<vtype, N> &o) {
|
||||||
stream << "M<" << N << ">{";
|
stream << "M<" << N << ">{";
|
||||||
for (int i = 0; i < N; i++) {
|
for (int i = 0; i < N; i++) {
|
||||||
@ -453,11 +453,11 @@ class iMatrix {
|
|||||||
}
|
}
|
||||||
stream << "}";
|
stream << "}";
|
||||||
return stream;
|
return stream;
|
||||||
};
|
};
|
||||||
|
|
||||||
// strong_inline vtype && operator ()(int i,int j) {
|
// strong_inline vtype && operator ()(int i,int j) {
|
||||||
// return _internal[i][j];
|
// return _internal[i][j];
|
||||||
// }
|
// }
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class v>
|
template <class v>
|
||||||
@ -478,7 +478,9 @@ void vprefetch(const iMatrix<v, N> &vv) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
NAMESPACE_END(Grid);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/*************************************************************************************
|
/*************************************************************************************
|
||||||
|
|
||||||
Grid physics library, www.github.com/paboyle/Grid
|
Grid physics library, www.github.com/paboyle/Grid
|
||||||
|
|
||||||
@ -23,29 +23,31 @@ Author: neo <cossu@post.kek.jp>
|
|||||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
See the full license in the file "LICENSE" in the top level distribution directory
|
See the full license in the file "LICENSE" in the top level distribution directory
|
||||||
*************************************************************************************/
|
*************************************************************************************/
|
||||||
/* END LEGAL */
|
/* END LEGAL */
|
||||||
#ifndef GRID_MATH_DET_H
|
#ifndef GRID_MATH_DET_H
|
||||||
#define GRID_MATH_DET_H
|
#define GRID_MATH_DET_H
|
||||||
namespace Grid {
|
|
||||||
///////////////////////////////////////////////
|
|
||||||
// Determinant function for scalar, vector, matrix
|
|
||||||
///////////////////////////////////////////////
|
|
||||||
inline ComplexF Determinant( const ComplexF &arg){ return arg;}
|
|
||||||
inline ComplexD Determinant( const ComplexD &arg){ return arg;}
|
|
||||||
inline RealF Determinant( const RealF &arg){ return arg;}
|
|
||||||
inline RealD Determinant( const RealD &arg){ return arg;}
|
|
||||||
|
|
||||||
template<class vtype> inline auto Determinant(const iScalar<vtype>&r) -> iScalar<decltype(Determinant(r._internal))>
|
NAMESPACE_BEGIN(Grid);
|
||||||
{
|
|
||||||
|
///////////////////////////////////////////////
|
||||||
|
// Determinant function for scalar, vector, matrix
|
||||||
|
///////////////////////////////////////////////
|
||||||
|
inline ComplexF Determinant( const ComplexF &arg){ return arg;}
|
||||||
|
inline ComplexD Determinant( const ComplexD &arg){ return arg;}
|
||||||
|
inline RealF Determinant( const RealF &arg){ return arg;}
|
||||||
|
inline RealD Determinant( const RealD &arg){ return arg;}
|
||||||
|
|
||||||
|
template<class vtype> inline auto Determinant(const iScalar<vtype>&r) -> iScalar<decltype(Determinant(r._internal))>
|
||||||
|
{
|
||||||
iScalar<decltype(Determinant(r._internal))> ret;
|
iScalar<decltype(Determinant(r._internal))> ret;
|
||||||
ret._internal = Determinant(r._internal);
|
ret._internal = Determinant(r._internal);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class vtype,int N, typename std::enable_if< GridTypeMapper<vtype>::TensorLevel == 0 >::type * =nullptr>
|
template<class vtype,int N, typename std::enable_if< GridTypeMapper<vtype>::TensorLevel == 0 >::type * =nullptr>
|
||||||
inline iScalar<vtype> Determinant(const iMatrix<vtype,N> &arg)
|
inline iScalar<vtype> Determinant(const iMatrix<vtype,N> &arg)
|
||||||
{
|
{
|
||||||
iMatrix<vtype,N> ret(arg);
|
iMatrix<vtype,N> ret(arg);
|
||||||
iScalar<vtype> det = vtype(1.0);
|
iScalar<vtype> det = vtype(1.0);
|
||||||
/* Conversion of matrix to upper triangular */
|
/* Conversion of matrix to upper triangular */
|
||||||
@ -64,9 +66,8 @@ namespace Grid {
|
|||||||
det *= ret._internal[i][i];
|
det *= ret._internal[i][i];
|
||||||
|
|
||||||
return det;
|
return det;
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NAMESPACE_END(Grid);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/*************************************************************************************
|
/*************************************************************************************
|
||||||
|
|
||||||
Grid physics library, www.github.com/paboyle/Grid
|
Grid physics library, www.github.com/paboyle/Grid
|
||||||
|
|
||||||
@ -23,41 +23,41 @@ Author: neo <cossu@post.kek.jp>
|
|||||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
See the full license in the file "LICENSE" in the top level distribution directory
|
See the full license in the file "LICENSE" in the top level distribution directory
|
||||||
*************************************************************************************/
|
*************************************************************************************/
|
||||||
/* END LEGAL */
|
/* END LEGAL */
|
||||||
#ifndef GRID_MATH_EXP_H
|
#ifndef GRID_MATH_EXP_H
|
||||||
#define GRID_MATH_EXP_H
|
#define GRID_MATH_EXP_H
|
||||||
|
|
||||||
#define DEFAULT_MAT_EXP 12
|
#define DEFAULT_MAT_EXP 12
|
||||||
|
|
||||||
namespace Grid {
|
NAMESPACE_BEGIN(Grid);
|
||||||
|
|
||||||
///////////////////////////////////////////////
|
///////////////////////////////////////////////
|
||||||
// Exponentiate function for scalar, vector, matrix
|
// Exponentiate function for scalar, vector, matrix
|
||||||
///////////////////////////////////////////////
|
///////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
template<class vtype> inline iScalar<vtype> Exponentiate(const iScalar<vtype>&r, RealD alpha , Integer Nexp = DEFAULT_MAT_EXP)
|
template<class vtype> inline iScalar<vtype> Exponentiate(const iScalar<vtype>&r, RealD alpha , Integer Nexp = DEFAULT_MAT_EXP)
|
||||||
{
|
{
|
||||||
iScalar<vtype> ret;
|
iScalar<vtype> ret;
|
||||||
ret._internal = Exponentiate(r._internal, alpha, Nexp);
|
ret._internal = Exponentiate(r._internal, alpha, Nexp);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class vtype, int N> inline iVector<vtype, N> Exponentiate(const iVector<vtype,N>&r, RealD alpha , Integer Nexp = DEFAULT_MAT_EXP)
|
template<class vtype, int N> inline iVector<vtype, N> Exponentiate(const iVector<vtype,N>&r, RealD alpha , Integer Nexp = DEFAULT_MAT_EXP)
|
||||||
{
|
{
|
||||||
iVector<vtype, N> ret;
|
iVector<vtype, N> ret;
|
||||||
for (int i = 0; i < N; i++)
|
for (int i = 0; i < N; i++)
|
||||||
ret._internal[i] = Exponentiate(r._internal[i], alpha, Nexp);
|
ret._internal[i] = Exponentiate(r._internal[i], alpha, Nexp);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Specialisation: Cayley-Hamilton exponential for SU(3)
|
// Specialisation: Cayley-Hamilton exponential for SU(3)
|
||||||
template<class vtype, typename std::enable_if< GridTypeMapper<vtype>::TensorLevel == 0>::type * =nullptr>
|
template<class vtype, typename std::enable_if< GridTypeMapper<vtype>::TensorLevel == 0>::type * =nullptr>
|
||||||
inline iMatrix<vtype,3> Exponentiate(const iMatrix<vtype,3> &arg, RealD alpha , Integer Nexp = DEFAULT_MAT_EXP )
|
inline iMatrix<vtype,3> Exponentiate(const iMatrix<vtype,3> &arg, RealD alpha , Integer Nexp = DEFAULT_MAT_EXP )
|
||||||
{
|
{
|
||||||
// for SU(3) 2x faster than the std implementation using Nexp=12
|
// for SU(3) 2x faster than the std implementation using Nexp=12
|
||||||
// notice that it actually computes
|
// notice that it actually computes
|
||||||
// exp ( input matrix )
|
// exp ( input matrix )
|
||||||
@ -114,14 +114,14 @@ template<class vtype, int N> inline iVector<vtype, N> Exponentiate(const iVector
|
|||||||
f2 = h2 * fden;
|
f2 = h2 * fden;
|
||||||
|
|
||||||
return (f0 * unit + timesMinusI(f1) * arg*alpha - f2 * iQ2);
|
return (f0 * unit + timesMinusI(f1) * arg*alpha - f2 * iQ2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// General exponential
|
// General exponential
|
||||||
template<class vtype,int N, typename std::enable_if< GridTypeMapper<vtype>::TensorLevel == 0 >::type * =nullptr>
|
template<class vtype,int N, typename std::enable_if< GridTypeMapper<vtype>::TensorLevel == 0 >::type * =nullptr>
|
||||||
inline iMatrix<vtype,N> Exponentiate(const iMatrix<vtype,N> &arg, RealD alpha , Integer Nexp = DEFAULT_MAT_EXP )
|
inline iMatrix<vtype,N> Exponentiate(const iMatrix<vtype,N> &arg, RealD alpha , Integer Nexp = DEFAULT_MAT_EXP )
|
||||||
{
|
{
|
||||||
// notice that it actually computes
|
// notice that it actually computes
|
||||||
// exp ( input matrix )
|
// exp ( input matrix )
|
||||||
// the i sign is coming from outside
|
// the i sign is coming from outside
|
||||||
@ -135,10 +135,8 @@ template<class vtype,int N, typename std::enable_if< GridTypeMapper<vtype>::Tens
|
|||||||
}
|
}
|
||||||
return temp;
|
return temp;
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NAMESPACE_END(Grid);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/*************************************************************************************
|
/*************************************************************************************
|
||||||
|
|
||||||
Grid physics library, www.github.com/paboyle/Grid
|
Grid physics library, www.github.com/paboyle/Grid
|
||||||
|
|
||||||
@ -27,8 +27,8 @@ Author: Christopher Kelly <ckelly@phys.columbia.edu>
|
|||||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
See the full license in the file "LICENSE" in the top level distribution directory
|
See the full license in the file "LICENSE" in the top level distribution directory
|
||||||
*************************************************************************************/
|
*************************************************************************************/
|
||||||
/* END LEGAL */
|
/* END LEGAL */
|
||||||
#ifndef GRID_EXTRACT_H
|
#ifndef GRID_EXTRACT_H
|
||||||
#define GRID_EXTRACT_H
|
#define GRID_EXTRACT_H
|
||||||
/////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////
|
||||||
@ -37,12 +37,12 @@ Author: Christopher Kelly <ckelly@phys.columbia.edu>
|
|||||||
|
|
||||||
namespace Grid{
|
namespace Grid{
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// Extract/merge a fundamental vector type, to pointer array with offset
|
// Extract/merge a fundamental vector type, to pointer array with offset
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
template<class vsimd,class scalar>
|
template<class vsimd,class scalar>
|
||||||
inline void extract(typename std::enable_if<!isGridTensor<vsimd>::value, const vsimd >::type * y,
|
inline void extract(typename std::enable_if<!isGridTensor<vsimd>::value, const vsimd >::type * y,
|
||||||
std::vector<scalar *> &extracted,int offset){
|
std::vector<scalar *> &extracted,int offset){
|
||||||
// FIXME: bounce off memory is painful
|
// FIXME: bounce off memory is painful
|
||||||
static const int Nsimd=sizeof(vsimd)/sizeof(scalar);
|
static const int Nsimd=sizeof(vsimd)/sizeof(scalar);
|
||||||
@ -53,12 +53,12 @@ inline void extract(typename std::enable_if<!isGridTensor<vsimd>::value, const v
|
|||||||
for(int i=0;i<Nextr;i++){
|
for(int i=0;i<Nextr;i++){
|
||||||
extracted[i][offset] = buf[i*s];
|
extracted[i][offset] = buf[i*s];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
// Merge simd vector from array of scalars to pointer array with offset
|
// Merge simd vector from array of scalars to pointer array with offset
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
template<class vsimd,class scalar>
|
template<class vsimd,class scalar>
|
||||||
inline void merge(typename std::enable_if<!isGridTensor<vsimd>::value, vsimd >::type * y,
|
inline void merge(typename std::enable_if<!isGridTensor<vsimd>::value, vsimd >::type * y,
|
||||||
std::vector<scalar *> &extracted,int offset){
|
std::vector<scalar *> &extracted,int offset){
|
||||||
|
|
||||||
static const int Nsimd=sizeof(vsimd)/sizeof(scalar);
|
static const int Nsimd=sizeof(vsimd)/sizeof(scalar);
|
||||||
@ -73,13 +73,13 @@ inline void merge(typename std::enable_if<!isGridTensor<vsimd>::value, vsimd >::
|
|||||||
buf[i*s+ii]=extracted[i][offset];
|
buf[i*s+ii]=extracted[i][offset];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// Extract a fundamental vector type to scalar array
|
// Extract a fundamental vector type to scalar array
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
template<class vsimd,class scalar>
|
template<class vsimd,class scalar>
|
||||||
inline void extract(typename std::enable_if<!isGridTensor<vsimd>::value, const vsimd >::type &y,std::vector<scalar> &extracted){
|
inline void extract(typename std::enable_if<!isGridTensor<vsimd>::value, const vsimd >::type &y,std::vector<scalar> &extracted){
|
||||||
|
|
||||||
int Nextr=extracted.size();
|
int Nextr=extracted.size();
|
||||||
int Nsimd=vsimd::Nsimd();
|
int Nsimd=vsimd::Nsimd();
|
||||||
@ -103,13 +103,13 @@ inline void extract(typename std::enable_if<!isGridTensor<vsimd>::value, const v
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
// Merge simd vector from array of scalars
|
// Merge simd vector from array of scalars
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
template<class vsimd,class scalar>
|
template<class vsimd,class scalar>
|
||||||
inline void merge(typename std::enable_if<!isGridTensor<vsimd>::value, vsimd >::type &y,std::vector<scalar> &extracted){
|
inline void merge(typename std::enable_if<!isGridTensor<vsimd>::value, vsimd >::type &y,std::vector<scalar> &extracted){
|
||||||
int Nextr=extracted.size();
|
int Nextr=extracted.size();
|
||||||
static const int Nsimd=vsimd::Nsimd();
|
static const int Nsimd=vsimd::Nsimd();
|
||||||
int s=Nsimd/Nextr;
|
int s=Nsimd/Nextr;
|
||||||
@ -120,13 +120,13 @@ inline void merge(typename std::enable_if<!isGridTensor<vsimd>::value, vsimd >::
|
|||||||
buf[i*s+ii]=extracted[i]; // replicates value
|
buf[i*s+ii]=extracted[i]; // replicates value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
// Extract to contiguous array scalar object
|
// Extract to contiguous array scalar object
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
template<class vobj> inline void extract(const vobj &vec,std::vector<typename vobj::scalar_object> &extracted)
|
template<class vobj> inline void extract(const vobj &vec,std::vector<typename vobj::scalar_object> &extracted)
|
||||||
{
|
{
|
||||||
typedef typename vobj::scalar_type scalar_type ;
|
typedef typename vobj::scalar_type scalar_type ;
|
||||||
typedef typename vobj::vector_type vector_type ;
|
typedef typename vobj::vector_type vector_type ;
|
||||||
|
|
||||||
@ -143,13 +143,13 @@ template<class vobj> inline void extract(const vobj &vec,std::vector<typename vo
|
|||||||
for(int w=0;w<words;w++){
|
for(int w=0;w<words;w++){
|
||||||
extract<vector_type,scalar_type>(&vp[w],pointers,w);
|
extract<vector_type,scalar_type>(&vp[w],pointers,w);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
// Extract to a bunch of scalar object pointers, with offset
|
// Extract to a bunch of scalar object pointers, with offset
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
template<class vobj> inline
|
template<class vobj> inline
|
||||||
void extract(const vobj &vec,std::vector<typename vobj::scalar_object *> &extracted, int offset)
|
void extract(const vobj &vec,std::vector<typename vobj::scalar_object *> &extracted, int offset)
|
||||||
{
|
{
|
||||||
typedef typename vobj::scalar_type scalar_type ;
|
typedef typename vobj::scalar_type scalar_type ;
|
||||||
typedef typename vobj::vector_type vector_type ;
|
typedef typename vobj::vector_type vector_type ;
|
||||||
|
|
||||||
@ -166,14 +166,14 @@ void extract(const vobj &vec,std::vector<typename vobj::scalar_object *> &extrac
|
|||||||
pointer[w] = vp[i*s+w*Nsimd];
|
pointer[w] = vp[i*s+w*Nsimd];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
// Extract to a bunch of scalar object pointers of different scalar type, with offset. Useful for precision change
|
// Extract to a bunch of scalar object pointers of different scalar type, with offset. Useful for precision change
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
template<class vobj, class sobj> inline
|
template<class vobj, class sobj> inline
|
||||||
void extract1(const vobj &vec,std::vector<sobj*> &extracted, int offset)
|
void extract1(const vobj &vec,std::vector<sobj*> &extracted, int offset)
|
||||||
{
|
{
|
||||||
typedef typename vobj::scalar_type vobj_scalar_type ;
|
typedef typename vobj::scalar_type vobj_scalar_type ;
|
||||||
typedef typename vobj::vector_type vobj_vector_type ;
|
typedef typename vobj::vector_type vobj_vector_type ;
|
||||||
|
|
||||||
@ -192,15 +192,15 @@ void extract1(const vobj &vec,std::vector<sobj*> &extracted, int offset)
|
|||||||
pointer[w] = vp[i*s+w*Nsimd];
|
pointer[w] = vp[i*s+w*Nsimd];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
// Merge a contiguous array of scalar objects
|
// Merge a contiguous array of scalar objects
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
template<class vobj> inline
|
template<class vobj> inline
|
||||||
void merge(vobj &vec,std::vector<typename vobj::scalar_object> &extracted)
|
void merge(vobj &vec,std::vector<typename vobj::scalar_object> &extracted)
|
||||||
{
|
{
|
||||||
typedef typename vobj::scalar_type scalar_type ;
|
typedef typename vobj::scalar_type scalar_type ;
|
||||||
typedef typename vobj::vector_type vector_type ;
|
typedef typename vobj::vector_type vector_type ;
|
||||||
|
|
||||||
@ -218,14 +218,14 @@ void merge(vobj &vec,std::vector<typename vobj::scalar_object> &extracted)
|
|||||||
for(int w=0;w<words;w++){
|
for(int w=0;w<words;w++){
|
||||||
merge<vector_type,scalar_type>(&vp[w],pointers,w);
|
merge<vector_type,scalar_type>(&vp[w],pointers,w);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
// Merge a bunch of different scalar object pointers, with offset
|
// Merge a bunch of different scalar object pointers, with offset
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
template<class vobj> inline
|
template<class vobj> inline
|
||||||
void merge(vobj &vec,std::vector<typename vobj::scalar_object *> &extracted,int offset)
|
void merge(vobj &vec,std::vector<typename vobj::scalar_object *> &extracted,int offset)
|
||||||
{
|
{
|
||||||
typedef typename vobj::scalar_type scalar_type ;
|
typedef typename vobj::scalar_type scalar_type ;
|
||||||
typedef typename vobj::vector_type vector_type ;
|
typedef typename vobj::vector_type vector_type ;
|
||||||
|
|
||||||
@ -250,8 +250,8 @@ void merge(vobj &vec,std::vector<typename vobj::scalar_object *> &extracted,int
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class vobj> inline void merge1(vobj &vec,std::vector<typename vobj::scalar_object *> &extracted,int offset)
|
template<class vobj> inline void merge1(vobj &vec,std::vector<typename vobj::scalar_object *> &extracted,int offset)
|
||||||
{
|
{
|
||||||
typedef typename vobj::scalar_type scalar_type ;
|
typedef typename vobj::scalar_type scalar_type ;
|
||||||
typedef typename vobj::vector_type vector_type ;
|
typedef typename vobj::vector_type vector_type ;
|
||||||
|
|
||||||
@ -266,10 +266,10 @@ template<class vobj> inline void merge1(vobj &vec,std::vector<typename vobj::sca
|
|||||||
for(int i=0;i<Nsimd;i++){
|
for(int i=0;i<Nsimd;i++){
|
||||||
vp[w*Nsimd+i] = ((scalar_type *)&extracted[i][offset])[w];
|
vp[w*Nsimd+i] = ((scalar_type *)&extracted[i][offset])[w];
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class vobj> inline void merge2(vobj &vec,std::vector<typename vobj::scalar_object *> &extracted,int offset)
|
template<class vobj> inline void merge2(vobj &vec,std::vector<typename vobj::scalar_object *> &extracted,int offset)
|
||||||
{
|
{
|
||||||
typedef typename vobj::scalar_type scalar_type ;
|
typedef typename vobj::scalar_type scalar_type ;
|
||||||
typedef typename vobj::vector_type vector_type ;
|
typedef typename vobj::vector_type vector_type ;
|
||||||
|
|
||||||
@ -286,7 +286,7 @@ template<class vobj> inline void merge2(vobj &vec,std::vector<typename vobj::sca
|
|||||||
vp[w*Nsimd+i] =pointer[w];
|
vp[w*Nsimd+i] =pointer[w];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/*************************************************************************************
|
/*************************************************************************************
|
||||||
|
|
||||||
Grid physics library, www.github.com/paboyle/Grid
|
Grid physics library, www.github.com/paboyle/Grid
|
||||||
|
|
||||||
@ -23,8 +23,8 @@ Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
|||||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
See the full license in the file "LICENSE" in the top level distribution directory
|
See the full license in the file "LICENSE" in the top level distribution directory
|
||||||
*************************************************************************************/
|
*************************************************************************************/
|
||||||
/* END LEGAL */
|
/* END LEGAL */
|
||||||
#ifndef GRID_TENSOR_INDEX_H
|
#ifndef GRID_TENSOR_INDEX_H
|
||||||
#define GRID_TENSOR_INDEX_H
|
#define GRID_TENSOR_INDEX_H
|
||||||
|
|
||||||
@ -35,18 +35,18 @@ Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
|||||||
// trace of a different index can distribute across the vector index in a replicated way
|
// trace of a different index can distribute across the vector index in a replicated way
|
||||||
// but we do not trace a vector index.
|
// but we do not trace a vector index.
|
||||||
|
|
||||||
namespace Grid {
|
NAMESPACE_BEGIN(Grid);
|
||||||
|
|
||||||
/* Needed?
|
/* Needed?
|
||||||
template<int Level> inline ComplexF traceIndex(const ComplexF arg) { return arg;}
|
template<int Level> inline ComplexF traceIndex(const ComplexF arg) { return arg;}
|
||||||
template<int Level> inline ComplexD traceIndex(const ComplexD arg) { return arg;}
|
template<int Level> inline ComplexD traceIndex(const ComplexD arg) { return arg;}
|
||||||
template<int Level> inline RealF traceIndex(const RealF arg) { return arg;}
|
template<int Level> inline RealF traceIndex(const RealF arg) { return arg;}
|
||||||
template<int Level> inline RealD traceIndex(const RealD arg) { return arg;}
|
template<int Level> inline RealD traceIndex(const RealD arg) { return arg;}
|
||||||
*/
|
*/
|
||||||
template<int Level>
|
template<int Level>
|
||||||
class TensorIndexRecursion {
|
class TensorIndexRecursion {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
////////////////////////////////////////////////////
|
////////////////////////////////////////////////////
|
||||||
// Type Queries
|
// Type Queries
|
||||||
@ -76,15 +76,15 @@ class TensorIndexRecursion {
|
|||||||
ret._internal = TensorIndexRecursion<Level-1>::traceIndex(arg._internal);
|
ret._internal = TensorIndexRecursion<Level-1>::traceIndex(arg._internal);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
template<class vtype,int N>
|
template<class vtype,int N>
|
||||||
static auto traceIndex(const iVector<vtype,N> arg) -> iVector<decltype(TensorIndexRecursion<Level-1>::traceIndex(arg._internal[0])),N>
|
static auto traceIndex(const iVector<vtype,N> arg) -> iVector<decltype(TensorIndexRecursion<Level-1>::traceIndex(arg._internal[0])),N>
|
||||||
{
|
{
|
||||||
iVector<decltype(TensorIndexRecursion<Level-1>::traceIndex(arg._internal[0])),N> ret;
|
iVector<decltype(TensorIndexRecursion<Level-1>::traceIndex(arg._internal[0])),N> ret;
|
||||||
for(int i=0;i<N;i++){
|
for(int i=0;i<N;i++){
|
||||||
ret._internal[i] = TensorIndexRecursion<Level-1>::traceIndex(arg._internal[i]);
|
ret._internal[i] = TensorIndexRecursion<Level-1>::traceIndex(arg._internal[i]);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
template<class vtype,int N>
|
template<class vtype,int N>
|
||||||
static auto traceIndex(const iMatrix<vtype,N> arg) -> iMatrix<decltype(TensorIndexRecursion<Level-1>::traceIndex(arg._internal[0][0])),N>
|
static auto traceIndex(const iMatrix<vtype,N> arg) -> iMatrix<decltype(TensorIndexRecursion<Level-1>::traceIndex(arg._internal[0][0])),N>
|
||||||
{
|
{
|
||||||
@ -95,139 +95,139 @@ class TensorIndexRecursion {
|
|||||||
}}
|
}}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
////////////////////////////////////////////
|
////////////////////////////////////////////
|
||||||
// Recursion for peeking a specific index
|
// Recursion for peeking a specific index
|
||||||
////////////////////////////////////////////
|
////////////////////////////////////////////
|
||||||
template<class vtype>
|
template<class vtype>
|
||||||
static auto peekIndex(const iScalar<vtype> arg,int i) -> iScalar<decltype(TensorIndexRecursion<Level-1>::peekIndex(arg._internal,0))>
|
static auto peekIndex(const iScalar<vtype> arg,int i) -> iScalar<decltype(TensorIndexRecursion<Level-1>::peekIndex(arg._internal,0))>
|
||||||
{
|
{
|
||||||
iScalar<decltype(TensorIndexRecursion<Level-1>::peekIndex(arg._internal,0))> ret;
|
iScalar<decltype(TensorIndexRecursion<Level-1>::peekIndex(arg._internal,0))> ret;
|
||||||
ret._internal = TensorIndexRecursion<Level-1>::peekIndex(arg._internal,i);
|
ret._internal = TensorIndexRecursion<Level-1>::peekIndex(arg._internal,i);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
template<class vtype>
|
template<class vtype>
|
||||||
static auto peekIndex(const iScalar<vtype> arg,int i,int j) -> iScalar<decltype(TensorIndexRecursion<Level-1>::peekIndex(arg._internal,0,0))>
|
static auto peekIndex(const iScalar<vtype> arg,int i,int j) -> iScalar<decltype(TensorIndexRecursion<Level-1>::peekIndex(arg._internal,0,0))>
|
||||||
{
|
{
|
||||||
iScalar<decltype(TensorIndexRecursion<Level-1>::peekIndex(arg._internal,0,0))> ret;
|
iScalar<decltype(TensorIndexRecursion<Level-1>::peekIndex(arg._internal,0,0))> ret;
|
||||||
ret._internal = TensorIndexRecursion<Level-1>::peekIndex(arg._internal,i,j);
|
ret._internal = TensorIndexRecursion<Level-1>::peekIndex(arg._internal,i,j);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class vtype,int N>
|
template<class vtype,int N>
|
||||||
static auto peekIndex(const iVector<vtype,N> arg,int ii) -> iVector<decltype(TensorIndexRecursion<Level-1>::peekIndex(arg._internal[0],0)),N>
|
static auto peekIndex(const iVector<vtype,N> arg,int ii) -> iVector<decltype(TensorIndexRecursion<Level-1>::peekIndex(arg._internal[0],0)),N>
|
||||||
{
|
{
|
||||||
iVector<decltype(TensorIndexRecursion<Level-1>::peekIndex(arg._internal[0],0)),N> ret;
|
iVector<decltype(TensorIndexRecursion<Level-1>::peekIndex(arg._internal[0],0)),N> ret;
|
||||||
for(int i=0;i<N;i++){
|
for(int i=0;i<N;i++){
|
||||||
ret._internal[i] = TensorIndexRecursion<Level-1>::peekIndex(arg._internal[i],ii);
|
ret._internal[i] = TensorIndexRecursion<Level-1>::peekIndex(arg._internal[i],ii);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
template<class vtype,int N>
|
template<class vtype,int N>
|
||||||
static auto peekIndex(const iVector<vtype,N> arg,int ii,int jj) -> iVector<decltype(TensorIndexRecursion<Level-1>::peekIndex(arg._internal[0],0,0)),N>
|
static auto peekIndex(const iVector<vtype,N> arg,int ii,int jj) -> iVector<decltype(TensorIndexRecursion<Level-1>::peekIndex(arg._internal[0],0,0)),N>
|
||||||
{
|
{
|
||||||
iVector<decltype(TensorIndexRecursion<Level-1>::peekIndex(arg._internal[0],0,0)),N> ret;
|
iVector<decltype(TensorIndexRecursion<Level-1>::peekIndex(arg._internal[0],0,0)),N> ret;
|
||||||
for(int i=0;i<N;i++){
|
for(int i=0;i<N;i++){
|
||||||
ret._internal[i] = TensorIndexRecursion<Level-1>::peekIndex(arg._internal[i],ii,jj);
|
ret._internal[i] = TensorIndexRecursion<Level-1>::peekIndex(arg._internal[i],ii,jj);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class vtype,int N>
|
template<class vtype,int N>
|
||||||
static auto peekIndex(const iMatrix<vtype,N> arg,int ii) -> iMatrix<decltype(TensorIndexRecursion<Level-1>::peekIndex(arg._internal[0][0],0)),N>
|
static auto peekIndex(const iMatrix<vtype,N> arg,int ii) -> iMatrix<decltype(TensorIndexRecursion<Level-1>::peekIndex(arg._internal[0][0],0)),N>
|
||||||
{
|
{
|
||||||
iMatrix<decltype(TensorIndexRecursion<Level-1>::peekIndex(arg._internal[0][0],0)),N> ret;
|
iMatrix<decltype(TensorIndexRecursion<Level-1>::peekIndex(arg._internal[0][0],0)),N> ret;
|
||||||
for(int i=0;i<N;i++){
|
for(int i=0;i<N;i++){
|
||||||
for(int j=0;j<N;j++){
|
for(int j=0;j<N;j++){
|
||||||
ret._internal[i][j] = TensorIndexRecursion<Level-1>::peekIndex(arg._internal[i][j],ii);
|
ret._internal[i][j] = TensorIndexRecursion<Level-1>::peekIndex(arg._internal[i][j],ii);
|
||||||
}}
|
}}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
template<class vtype,int N>
|
template<class vtype,int N>
|
||||||
static auto peekIndex(const iMatrix<vtype,N> arg,int ii,int jj) -> iMatrix<decltype(TensorIndexRecursion<Level-1>::peekIndex(arg._internal[0][0],0,0)),N>
|
static auto peekIndex(const iMatrix<vtype,N> arg,int ii,int jj) -> iMatrix<decltype(TensorIndexRecursion<Level-1>::peekIndex(arg._internal[0][0],0,0)),N>
|
||||||
{
|
{
|
||||||
iMatrix<decltype(TensorIndexRecursion<Level-1>::peekIndex(arg._internal[0][0],0,0)),N> ret;
|
iMatrix<decltype(TensorIndexRecursion<Level-1>::peekIndex(arg._internal[0][0],0,0)),N> ret;
|
||||||
for(int i=0;i<N;i++){
|
for(int i=0;i<N;i++){
|
||||||
for(int j=0;j<N;j++){
|
for(int j=0;j<N;j++){
|
||||||
ret._internal[i][j] = TensorIndexRecursion<Level-1>::peekIndex(arg._internal[i][j],ii,jj);
|
ret._internal[i][j] = TensorIndexRecursion<Level-1>::peekIndex(arg._internal[i][j],ii,jj);
|
||||||
}}
|
}}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
////////////////////////////////////////////
|
////////////////////////////////////////////
|
||||||
// Recursion for poking a specific index
|
// Recursion for poking a specific index
|
||||||
////////////////////////////////////////////
|
////////////////////////////////////////////
|
||||||
|
|
||||||
template<class vtype> inline static
|
template<class vtype> inline static
|
||||||
void pokeIndex(iScalar<vtype> &ret, const iScalar<decltype(TensorIndexRecursion<Level-1>::peekIndex(ret._internal,0))> &arg, int i)
|
void pokeIndex(iScalar<vtype> &ret, const iScalar<decltype(TensorIndexRecursion<Level-1>::peekIndex(ret._internal,0))> &arg, int i)
|
||||||
{
|
{
|
||||||
TensorIndexRecursion<Level-1>::pokeIndex(ret._internal,arg._internal,i);
|
TensorIndexRecursion<Level-1>::pokeIndex(ret._internal,arg._internal,i);
|
||||||
}
|
}
|
||||||
template<class vtype> inline static
|
template<class vtype> inline static
|
||||||
void pokeIndex(iScalar<vtype> &ret, const iScalar<decltype(TensorIndexRecursion<Level-1>::peekIndex(ret._internal,0,0))> &arg, int i,int j)
|
void pokeIndex(iScalar<vtype> &ret, const iScalar<decltype(TensorIndexRecursion<Level-1>::peekIndex(ret._internal,0,0))> &arg, int i,int j)
|
||||||
{
|
{
|
||||||
TensorIndexRecursion<Level-1>::pokeIndex(ret._internal,arg._internal,i,j);
|
TensorIndexRecursion<Level-1>::pokeIndex(ret._internal,arg._internal,i,j);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class vtype,int N> inline static
|
template<class vtype,int N> inline static
|
||||||
void pokeIndex(iVector<vtype,N> &ret, const iVector<decltype(TensorIndexRecursion<Level-1>::peekIndex(ret._internal[0],0)),N> &arg, int i)
|
void pokeIndex(iVector<vtype,N> &ret, const iVector<decltype(TensorIndexRecursion<Level-1>::peekIndex(ret._internal[0],0)),N> &arg, int i)
|
||||||
{
|
{
|
||||||
for(int ii=0;ii<N;ii++){
|
for(int ii=0;ii<N;ii++){
|
||||||
TensorIndexRecursion<Level-1>::pokeIndex(ret._internal[ii],arg._internal[ii],i);
|
TensorIndexRecursion<Level-1>::pokeIndex(ret._internal[ii],arg._internal[ii],i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
template<class vtype,int N> inline static
|
template<class vtype,int N> inline static
|
||||||
void pokeIndex(iVector<vtype,N> &ret, const iVector<decltype(TensorIndexRecursion<Level-1>::peekIndex(ret._internal[0],0,0)),N> &arg, int i,int j)
|
void pokeIndex(iVector<vtype,N> &ret, const iVector<decltype(TensorIndexRecursion<Level-1>::peekIndex(ret._internal[0],0,0)),N> &arg, int i,int j)
|
||||||
{
|
{
|
||||||
for(int ii=0;ii<N;ii++){
|
for(int ii=0;ii<N;ii++){
|
||||||
TensorIndexRecursion<Level-1>::pokeIndex(ret._internal[ii],arg._internal[ii],i,j);
|
TensorIndexRecursion<Level-1>::pokeIndex(ret._internal[ii],arg._internal[ii],i,j);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class vtype,int N> inline static
|
template<class vtype,int N> inline static
|
||||||
void pokeIndex(iMatrix<vtype,N> &ret, const iMatrix<decltype(TensorIndexRecursion<Level-1>::peekIndex(ret._internal[0][0],0)),N> &arg, int i)
|
void pokeIndex(iMatrix<vtype,N> &ret, const iMatrix<decltype(TensorIndexRecursion<Level-1>::peekIndex(ret._internal[0][0],0)),N> &arg, int i)
|
||||||
{
|
{
|
||||||
for(int ii=0;ii<N;ii++){
|
for(int ii=0;ii<N;ii++){
|
||||||
for(int jj=0;jj<N;jj++){
|
for(int jj=0;jj<N;jj++){
|
||||||
TensorIndexRecursion<Level-1>::pokeIndex(ret._internal[ii][jj],arg._internal[ii][jj],i);
|
TensorIndexRecursion<Level-1>::pokeIndex(ret._internal[ii][jj],arg._internal[ii][jj],i);
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
template<class vtype,int N> inline static
|
template<class vtype,int N> inline static
|
||||||
void pokeIndex(iMatrix<vtype,N> &ret, const iMatrix<decltype(TensorIndexRecursion<Level-1>::peekIndex(ret._internal[0][0],0,0)),N> &arg, int i,int j)
|
void pokeIndex(iMatrix<vtype,N> &ret, const iMatrix<decltype(TensorIndexRecursion<Level-1>::peekIndex(ret._internal[0][0],0,0)),N> &arg, int i,int j)
|
||||||
{
|
{
|
||||||
for(int ii=0;ii<N;ii++){
|
for(int ii=0;ii<N;ii++){
|
||||||
for(int jj=0;jj<N;jj++){
|
for(int jj=0;jj<N;jj++){
|
||||||
TensorIndexRecursion<Level-1>::pokeIndex(ret._internal[ii][jj],arg._internal[ii][jj],i,j);
|
TensorIndexRecursion<Level-1>::pokeIndex(ret._internal[ii][jj],arg._internal[ii][jj],i,j);
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////
|
////////////////////////////////////////////
|
||||||
// Recursion for transposing a specific index
|
// Recursion for transposing a specific index
|
||||||
////////////////////////////////////////////
|
////////////////////////////////////////////
|
||||||
template<class vtype>
|
template<class vtype>
|
||||||
static auto transposeIndex(const iScalar<vtype> arg) -> iScalar<vtype>
|
static auto transposeIndex(const iScalar<vtype> arg) -> iScalar<vtype>
|
||||||
{
|
{
|
||||||
iScalar<vtype> ret;
|
iScalar<vtype> ret;
|
||||||
ret._internal = TensorIndexRecursion<Level-1>::transposeIndex(arg._internal);
|
ret._internal = TensorIndexRecursion<Level-1>::transposeIndex(arg._internal);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
template<class vtype,int N>
|
template<class vtype,int N>
|
||||||
static auto transposeIndex(const iVector<vtype,N> arg) -> iVector<vtype,N>
|
static auto transposeIndex(const iVector<vtype,N> arg) -> iVector<vtype,N>
|
||||||
{
|
{
|
||||||
iVector<vtype,N> ret;
|
iVector<vtype,N> ret;
|
||||||
for(int i=0;i<N;i++){
|
for(int i=0;i<N;i++){
|
||||||
ret._internal[i] = TensorIndexRecursion<Level-1>::transposeIndex(arg._internal[i]);
|
ret._internal[i] = TensorIndexRecursion<Level-1>::transposeIndex(arg._internal[i]);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
template<class vtype,int N>
|
template<class vtype,int N>
|
||||||
static auto transposeIndex(const iMatrix<vtype,N> arg) -> iMatrix<vtype,N>
|
static auto transposeIndex(const iMatrix<vtype,N> arg) -> iMatrix<vtype,N>
|
||||||
{
|
{
|
||||||
iMatrix<vtype,N> ret;
|
iMatrix<vtype,N> ret;
|
||||||
for(int i=0;i<N;i++){
|
for(int i=0;i<N;i++){
|
||||||
for(int j=0;j<N;j++){
|
for(int j=0;j<N;j++){
|
||||||
ret._internal[i][j] = TensorIndexRecursion<Level-1>::transposeIndex(arg._internal[i][j]);
|
ret._internal[i][j] = TensorIndexRecursion<Level-1>::transposeIndex(arg._internal[i][j]);
|
||||||
}}
|
}}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////
|
////////////////////////////
|
||||||
@ -236,7 +236,7 @@ class TensorIndexRecursion {
|
|||||||
#define RemoveCRV(a) typename std::remove_const<typename std::remove_reference<decltype(a)>::type>::type
|
#define RemoveCRV(a) typename std::remove_const<typename std::remove_reference<decltype(a)>::type>::type
|
||||||
template<>
|
template<>
|
||||||
class TensorIndexRecursion<0> {
|
class TensorIndexRecursion<0> {
|
||||||
public:
|
public:
|
||||||
////////////////////////////////////////////////////
|
////////////////////////////////////////////////////
|
||||||
// Type Queries
|
// Type Queries
|
||||||
////////////////////////////////////////////////////
|
////////////////////////////////////////////////////
|
||||||
@ -266,16 +266,16 @@ class TensorIndexRecursion<0> {
|
|||||||
ret._internal = arg._internal;
|
ret._internal = arg._internal;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
template<class vtype,int N>
|
template<class vtype,int N>
|
||||||
static auto traceIndex(const iVector<vtype,N> arg) -> iScalar<RemoveCRV(arg._internal[0])>
|
static auto traceIndex(const iVector<vtype,N> arg) -> iScalar<RemoveCRV(arg._internal[0])>
|
||||||
{
|
{
|
||||||
iScalar<RemoveCRV(arg._internal[0])> ret;
|
iScalar<RemoveCRV(arg._internal[0])> ret;
|
||||||
ret._internal=zero;
|
ret._internal=zero;
|
||||||
for(int i=0;i<N;i++){
|
for(int i=0;i<N;i++){
|
||||||
ret._internal = ret._internal+ arg._internal[i];
|
ret._internal = ret._internal+ arg._internal[i];
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
template<class vtype,int N>
|
template<class vtype,int N>
|
||||||
static auto traceIndex(const iMatrix<vtype,N> arg) -> iScalar<RemoveCRV(arg._internal[0][0])>
|
static auto traceIndex(const iMatrix<vtype,N> arg) -> iScalar<RemoveCRV(arg._internal[0][0])>
|
||||||
{
|
{
|
||||||
@ -286,19 +286,19 @@ class TensorIndexRecursion<0> {
|
|||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
/////////////////////////////////////////
|
/////////////////////////////////////////
|
||||||
// Ends recursion for transpose scalar/matrix ; no way to terminate on vector
|
// Ends recursion for transpose scalar/matrix ; no way to terminate on vector
|
||||||
/////////////////////////////////////////
|
/////////////////////////////////////////
|
||||||
template<class vtype>
|
template<class vtype>
|
||||||
static auto transposeIndex(const iScalar<vtype> arg) -> iScalar<vtype>
|
static auto transposeIndex(const iScalar<vtype> arg) -> iScalar<vtype>
|
||||||
{
|
{
|
||||||
iScalar<vtype> ret;
|
iScalar<vtype> ret;
|
||||||
ret._internal = arg._internal;
|
ret._internal = arg._internal;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
template<class vtype,int N>
|
template<class vtype,int N>
|
||||||
static auto transposeIndex(const iMatrix<vtype,N> arg) -> iMatrix<vtype,N>
|
static auto transposeIndex(const iMatrix<vtype,N> arg) -> iMatrix<vtype,N>
|
||||||
{
|
{
|
||||||
iMatrix<vtype,N> ret;
|
iMatrix<vtype,N> ret;
|
||||||
ret=zero;
|
ret=zero;
|
||||||
for(int i=0;i<N;i++){
|
for(int i=0;i<N;i++){
|
||||||
@ -306,36 +306,36 @@ class TensorIndexRecursion<0> {
|
|||||||
ret._internal[i][j] = ret._internal[i][j]+arg._internal[i][j];
|
ret._internal[i][j] = ret._internal[i][j]+arg._internal[i][j];
|
||||||
}}
|
}}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// End recursion for peeking a specific index; single index on vector, double index on matrix
|
// End recursion for peeking a specific index; single index on vector, double index on matrix
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
template<class vtype,int N>
|
template<class vtype,int N>
|
||||||
static auto peekIndex(const iVector<vtype,N> arg,int ii) -> iScalar<vtype>
|
static auto peekIndex(const iVector<vtype,N> arg,int ii) -> iScalar<vtype>
|
||||||
{
|
{
|
||||||
iScalar<vtype> ret;
|
iScalar<vtype> ret;
|
||||||
ret._internal = arg._internal[ii];
|
ret._internal = arg._internal[ii];
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
template<class vtype,int N>
|
template<class vtype,int N>
|
||||||
static auto peekIndex(const iMatrix<vtype,N> arg,int ii,int jj) -> iScalar<vtype>
|
static auto peekIndex(const iMatrix<vtype,N> arg,int ii,int jj) -> iScalar<vtype>
|
||||||
{
|
{
|
||||||
iScalar<vtype> ret;
|
iScalar<vtype> ret;
|
||||||
ret._internal = arg._internal[ii][jj];
|
ret._internal = arg._internal[ii][jj];
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
// Vector poke, one index
|
// Vector poke, one index
|
||||||
template<class vtype,int N> inline static
|
template<class vtype,int N> inline static
|
||||||
void pokeIndex(iVector<vtype,N> &ret, const iScalar<vtype> &arg,int i)
|
void pokeIndex(iVector<vtype,N> &ret, const iScalar<vtype> &arg,int i)
|
||||||
{
|
{
|
||||||
ret._internal[i] = arg._internal;
|
ret._internal[i] = arg._internal;
|
||||||
}
|
}
|
||||||
// Matrix poke two indices
|
// Matrix poke two indices
|
||||||
template<class vtype,int N> inline static
|
template<class vtype,int N> inline static
|
||||||
void pokeIndex(iMatrix<vtype,N> &ret, const iScalar<vtype> &arg,int i,int j)
|
void pokeIndex(iMatrix<vtype,N> &ret, const iScalar<vtype> &arg,int i,int j)
|
||||||
{
|
{
|
||||||
ret._internal[i][j] = arg._internal;
|
ret._internal[i][j] = arg._internal;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -404,5 +404,6 @@ void pokeIndex (vtype &ret,const decltype(TensorIndexRecursion<Level>::peekIndex
|
|||||||
|
|
||||||
#undef RemoveCRV
|
#undef RemoveCRV
|
||||||
|
|
||||||
}
|
NAMESPACE_END(Grid);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/*************************************************************************************
|
/*************************************************************************************
|
||||||
|
|
||||||
Grid physics library, www.github.com/paboyle/Grid
|
Grid physics library, www.github.com/paboyle/Grid
|
||||||
|
|
||||||
@ -24,24 +24,26 @@ Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
|||||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
See the full license in the file "LICENSE" in the top level distribution directory
|
See the full license in the file "LICENSE" in the top level distribution directory
|
||||||
*************************************************************************************/
|
*************************************************************************************/
|
||||||
/* END LEGAL */
|
/* END LEGAL */
|
||||||
#ifndef GRID_MATH_INNER_H
|
#ifndef GRID_MATH_INNER_H
|
||||||
#define GRID_MATH_INNER_H
|
#define GRID_MATH_INNER_H
|
||||||
namespace Grid {
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////
|
NAMESPACE_BEGIN(Grid);
|
||||||
// innerProduct Scalar x Scalar -> Scalar
|
|
||||||
// innerProduct Vector x Vector -> Scalar
|
///////////////////////////////////////////////////////////////////////////////////////
|
||||||
// innerProduct Matrix x Matrix -> Scalar
|
// innerProduct Scalar x Scalar -> Scalar
|
||||||
///////////////////////////////////////////////////////////////////////////////////////
|
// innerProduct Vector x Vector -> Scalar
|
||||||
template<class sobj> inline RealD norm2(const sobj &arg){
|
// innerProduct Matrix x Matrix -> Scalar
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
template<class sobj> inline RealD norm2(const sobj &arg){
|
||||||
auto nrm = innerProductD(arg,arg);
|
auto nrm = innerProductD(arg,arg);
|
||||||
RealD ret = real(nrm);
|
RealD ret = real(nrm);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
//////////////////////////////////////
|
//////////////////////////////////////
|
||||||
// If single promote to double and sum 2x
|
// If single promote to double and sum 2x
|
||||||
//////////////////////////////////////
|
//////////////////////////////////////
|
||||||
|
|
||||||
inline ComplexD innerProductD(const ComplexF &l,const ComplexF &r){ return innerProduct(l,r); }
|
inline ComplexD innerProductD(const ComplexF &l,const ComplexF &r){ return innerProduct(l,r); }
|
||||||
inline ComplexD innerProductD(const ComplexD &l,const ComplexD &r){ return innerProduct(l,r); }
|
inline ComplexD innerProductD(const ComplexD &l,const ComplexD &r){ return innerProduct(l,r); }
|
||||||
@ -65,9 +67,9 @@ inline vRealD innerProductD(const vRealF &l,const vRealF &r){
|
|||||||
return innerProduct(la,ra) + innerProduct(lb,rb);
|
return innerProduct(la,ra) + innerProduct(lb,rb);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class l,class r,int N> inline
|
template<class l,class r,int N> inline
|
||||||
auto innerProductD (const iVector<l,N>& lhs,const iVector<r,N>& rhs) -> iScalar<decltype(innerProductD(lhs._internal[0],rhs._internal[0]))>
|
auto innerProductD (const iVector<l,N>& lhs,const iVector<r,N>& rhs) -> iScalar<decltype(innerProductD(lhs._internal[0],rhs._internal[0]))>
|
||||||
{
|
{
|
||||||
typedef decltype(innerProductD(lhs._internal[0],rhs._internal[0])) ret_t;
|
typedef decltype(innerProductD(lhs._internal[0],rhs._internal[0])) ret_t;
|
||||||
iScalar<ret_t> ret;
|
iScalar<ret_t> ret;
|
||||||
ret=zero;
|
ret=zero;
|
||||||
@ -75,10 +77,10 @@ inline vRealD innerProductD(const vRealF &l,const vRealF &r){
|
|||||||
ret._internal += innerProductD(lhs._internal[c1],rhs._internal[c1]);
|
ret._internal += innerProductD(lhs._internal[c1],rhs._internal[c1]);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
template<class l,class r,int N> inline
|
template<class l,class r,int N> inline
|
||||||
auto innerProductD (const iMatrix<l,N>& lhs,const iMatrix<r,N>& rhs) -> iScalar<decltype(innerProductD(lhs._internal[0][0],rhs._internal[0][0]))>
|
auto innerProductD (const iMatrix<l,N>& lhs,const iMatrix<r,N>& rhs) -> iScalar<decltype(innerProductD(lhs._internal[0][0],rhs._internal[0][0]))>
|
||||||
{
|
{
|
||||||
typedef decltype(innerProductD(lhs._internal[0][0],rhs._internal[0][0])) ret_t;
|
typedef decltype(innerProductD(lhs._internal[0][0],rhs._internal[0][0])) ret_t;
|
||||||
iScalar<ret_t> ret;
|
iScalar<ret_t> ret;
|
||||||
iScalar<ret_t> tmp;
|
iScalar<ret_t> tmp;
|
||||||
@ -88,21 +90,21 @@ inline vRealD innerProductD(const vRealF &l,const vRealF &r){
|
|||||||
ret._internal+=innerProductD(lhs._internal[c1][c2],rhs._internal[c1][c2]);
|
ret._internal+=innerProductD(lhs._internal[c1][c2],rhs._internal[c1][c2]);
|
||||||
}}
|
}}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
template<class l,class r> inline
|
template<class l,class r> inline
|
||||||
auto innerProductD (const iScalar<l>& lhs,const iScalar<r>& rhs) -> iScalar<decltype(innerProductD(lhs._internal,rhs._internal))>
|
auto innerProductD (const iScalar<l>& lhs,const iScalar<r>& rhs) -> iScalar<decltype(innerProductD(lhs._internal,rhs._internal))>
|
||||||
{
|
{
|
||||||
typedef decltype(innerProductD(lhs._internal,rhs._internal)) ret_t;
|
typedef decltype(innerProductD(lhs._internal,rhs._internal)) ret_t;
|
||||||
iScalar<ret_t> ret;
|
iScalar<ret_t> ret;
|
||||||
ret._internal = innerProductD(lhs._internal,rhs._internal);
|
ret._internal = innerProductD(lhs._internal,rhs._internal);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
//////////////////////
|
//////////////////////
|
||||||
// Keep same precison
|
// Keep same precison
|
||||||
//////////////////////
|
//////////////////////
|
||||||
template<class l,class r,int N> inline
|
template<class l,class r,int N> inline
|
||||||
auto innerProduct (const iVector<l,N>& lhs,const iVector<r,N>& rhs) -> iScalar<decltype(innerProduct(lhs._internal[0],rhs._internal[0]))>
|
auto innerProduct (const iVector<l,N>& lhs,const iVector<r,N>& rhs) -> iScalar<decltype(innerProduct(lhs._internal[0],rhs._internal[0]))>
|
||||||
{
|
{
|
||||||
typedef decltype(innerProduct(lhs._internal[0],rhs._internal[0])) ret_t;
|
typedef decltype(innerProduct(lhs._internal[0],rhs._internal[0])) ret_t;
|
||||||
iScalar<ret_t> ret;
|
iScalar<ret_t> ret;
|
||||||
ret=zero;
|
ret=zero;
|
||||||
@ -110,10 +112,10 @@ inline vRealD innerProductD(const vRealF &l,const vRealF &r){
|
|||||||
ret._internal += innerProduct(lhs._internal[c1],rhs._internal[c1]);
|
ret._internal += innerProduct(lhs._internal[c1],rhs._internal[c1]);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
template<class l,class r,int N> inline
|
template<class l,class r,int N> inline
|
||||||
auto innerProduct (const iMatrix<l,N>& lhs,const iMatrix<r,N>& rhs) -> iScalar<decltype(innerProduct(lhs._internal[0][0],rhs._internal[0][0]))>
|
auto innerProduct (const iMatrix<l,N>& lhs,const iMatrix<r,N>& rhs) -> iScalar<decltype(innerProduct(lhs._internal[0][0],rhs._internal[0][0]))>
|
||||||
{
|
{
|
||||||
typedef decltype(innerProduct(lhs._internal[0][0],rhs._internal[0][0])) ret_t;
|
typedef decltype(innerProduct(lhs._internal[0][0],rhs._internal[0][0])) ret_t;
|
||||||
iScalar<ret_t> ret;
|
iScalar<ret_t> ret;
|
||||||
iScalar<ret_t> tmp;
|
iScalar<ret_t> tmp;
|
||||||
@ -123,15 +125,16 @@ inline vRealD innerProductD(const vRealF &l,const vRealF &r){
|
|||||||
ret._internal+=innerProduct(lhs._internal[c1][c2],rhs._internal[c1][c2]);
|
ret._internal+=innerProduct(lhs._internal[c1][c2],rhs._internal[c1][c2]);
|
||||||
}}
|
}}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
template<class l,class r> inline
|
template<class l,class r> inline
|
||||||
auto innerProduct (const iScalar<l>& lhs,const iScalar<r>& rhs) -> iScalar<decltype(innerProduct(lhs._internal,rhs._internal))>
|
auto innerProduct (const iScalar<l>& lhs,const iScalar<r>& rhs) -> iScalar<decltype(innerProduct(lhs._internal,rhs._internal))>
|
||||||
{
|
{
|
||||||
typedef decltype(innerProduct(lhs._internal,rhs._internal)) ret_t;
|
typedef decltype(innerProduct(lhs._internal,rhs._internal)) ret_t;
|
||||||
iScalar<ret_t> ret;
|
iScalar<ret_t> ret;
|
||||||
ret._internal = innerProduct(lhs._internal,rhs._internal);
|
ret._internal = innerProduct(lhs._internal,rhs._internal);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NAMESPACE_END(Grid);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/*************************************************************************************
|
/*************************************************************************************
|
||||||
|
|
||||||
Grid physics library, www.github.com/paboyle/Grid
|
Grid physics library, www.github.com/paboyle/Grid
|
||||||
|
|
||||||
@ -23,37 +23,38 @@ Author: Azusa Yamaguchi <ayamaguc@staffmail.ed.ac.uk>
|
|||||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
See the full license in the file "LICENSE" in the top level distribution directory
|
See the full license in the file "LICENSE" in the top level distribution directory
|
||||||
*************************************************************************************/
|
*************************************************************************************/
|
||||||
/* END LEGAL */
|
/* END LEGAL */
|
||||||
#ifndef GRID_TENSOR_LOGICAL_H
|
#ifndef GRID_TENSOR_LOGICAL_H
|
||||||
#define GRID_TENSOR_LOGICAL_H
|
#define GRID_TENSOR_LOGICAL_H
|
||||||
|
|
||||||
namespace Grid {
|
NAMESPACE_BEGIN(Grid);
|
||||||
|
|
||||||
#define LOGICAL_BINOP(Op)\
|
#define LOGICAL_BINOP(Op) \
|
||||||
template<class v> strong_inline iScalar<v> operator Op (const iScalar<v>& lhs,const iScalar<v>& rhs) \
|
template<class v> strong_inline iScalar<v> operator Op (const iScalar<v>& lhs,const iScalar<v>& rhs) \
|
||||||
{\
|
{ \
|
||||||
iScalar<v> ret;\
|
iScalar<v> ret; \
|
||||||
ret._internal = lhs._internal Op rhs._internal ;\
|
ret._internal = lhs._internal Op rhs._internal ; \
|
||||||
return ret;\
|
return ret; \
|
||||||
}\
|
} \
|
||||||
template<class l> strong_inline iScalar<l> operator Op (const iScalar<l>& lhs,Integer rhs) \
|
template<class l> strong_inline iScalar<l> operator Op (const iScalar<l>& lhs,Integer rhs) \
|
||||||
{\
|
{ \
|
||||||
typename iScalar<l>::scalar_type t; t=rhs;\
|
typename iScalar<l>::scalar_type t; t=rhs; \
|
||||||
typename iScalar<l>::tensor_reduced srhs; srhs=t;\
|
typename iScalar<l>::tensor_reduced srhs; srhs=t; \
|
||||||
return lhs Op srhs;\
|
return lhs Op srhs; \
|
||||||
}\
|
} \
|
||||||
template<class l> strong_inline iScalar<l> operator Op (Integer lhs,const iScalar<l>& rhs) \
|
template<class l> strong_inline iScalar<l> operator Op (Integer lhs,const iScalar<l>& rhs) \
|
||||||
{\
|
{ \
|
||||||
typename iScalar<l>::scalar_type t;t=lhs;\
|
typename iScalar<l>::scalar_type t;t=lhs; \
|
||||||
typename iScalar<l>::tensor_reduced slhs;slhs=t;\
|
typename iScalar<l>::tensor_reduced slhs;slhs=t; \
|
||||||
return slhs Op rhs;\
|
return slhs Op rhs; \
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGICAL_BINOP(|);
|
LOGICAL_BINOP(|);
|
||||||
LOGICAL_BINOP(&);
|
LOGICAL_BINOP(&);
|
||||||
LOGICAL_BINOP(||);
|
LOGICAL_BINOP(||);
|
||||||
LOGICAL_BINOP(&&);
|
LOGICAL_BINOP(&&);
|
||||||
|
|
||||||
}
|
NAMESPACE_END(Grid);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/*************************************************************************************
|
/*************************************************************************************
|
||||||
|
|
||||||
Grid physics library, www.github.com/paboyle/Grid
|
Grid physics library, www.github.com/paboyle/Grid
|
||||||
|
|
||||||
@ -23,15 +23,17 @@ Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
|||||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
See the full license in the file "LICENSE" in the top level distribution directory
|
See the full license in the file "LICENSE" in the top level distribution directory
|
||||||
*************************************************************************************/
|
*************************************************************************************/
|
||||||
/* END LEGAL */
|
/* END LEGAL */
|
||||||
#ifndef GRID_MATH_OUTER_H
|
#ifndef GRID_MATH_OUTER_H
|
||||||
#define GRID_MATH_OUTER_H
|
#define GRID_MATH_OUTER_H
|
||||||
namespace Grid {
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////
|
NAMESPACE_BEGIN(Grid);
|
||||||
// outerProduct Scalar x Scalar -> Scalar
|
|
||||||
// Vector x Vector -> Matrix
|
///////////////////////////////////////////////////////////////////////////////////////
|
||||||
///////////////////////////////////////////////////////////////////////////////////////
|
// outerProduct Scalar x Scalar -> Scalar
|
||||||
|
// Vector x Vector -> Matrix
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
template<class l,class r,int N> inline
|
template<class l,class r,int N> inline
|
||||||
auto outerProduct (const iVector<l,N>& lhs,const iVector<r,N>& rhs) -> iMatrix<decltype(outerProduct(lhs._internal[0],rhs._internal[0])),N>
|
auto outerProduct (const iVector<l,N>& lhs,const iVector<r,N>& rhs) -> iMatrix<decltype(outerProduct(lhs._internal[0],rhs._internal[0])),N>
|
||||||
@ -75,5 +77,6 @@ inline RealD outerProduct(const RealD &l, const RealD& r)
|
|||||||
return l*r;
|
return l*r;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
NAMESPACE_END(Grid);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/*************************************************************************************
|
/*************************************************************************************
|
||||||
|
|
||||||
Grid physics library, www.github.com/paboyle/Grid
|
Grid physics library, www.github.com/paboyle/Grid
|
||||||
|
|
||||||
@ -24,11 +24,12 @@ Author: neo <cossu@post.kek.jp>
|
|||||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
See the full license in the file "LICENSE" in the top level distribution directory
|
See the full license in the file "LICENSE" in the top level distribution directory
|
||||||
*************************************************************************************/
|
*************************************************************************************/
|
||||||
/* END LEGAL */
|
/* END LEGAL */
|
||||||
#ifndef GRID_MATH_REALITY_H
|
#ifndef GRID_MATH_REALITY_H
|
||||||
#define GRID_MATH_REALITY_H
|
#define GRID_MATH_REALITY_H
|
||||||
namespace Grid {
|
|
||||||
|
NAMESPACE_BEGIN(Grid);
|
||||||
|
|
||||||
///////////////////////////////////////////////
|
///////////////////////////////////////////////
|
||||||
// multiply by I; make recursive.
|
// multiply by I; make recursive.
|
||||||
@ -230,6 +231,6 @@ template<class itype,int N> inline auto imag(const iVector<itype,N> &z) -> iVect
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NAMESPACE_END(Grid);
|
||||||
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/*************************************************************************************
|
/*************************************************************************************
|
||||||
|
|
||||||
Grid physics library, www.github.com/paboyle/Grid
|
Grid physics library, www.github.com/paboyle/Grid
|
||||||
|
|
||||||
@ -24,11 +24,12 @@ Author: neo <cossu@post.kek.jp>
|
|||||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
See the full license in the file "LICENSE" in the top level distribution directory
|
See the full license in the file "LICENSE" in the top level distribution directory
|
||||||
*************************************************************************************/
|
*************************************************************************************/
|
||||||
/* END LEGAL */
|
/* END LEGAL */
|
||||||
#ifndef GRID_MATH_TRACE_H
|
#ifndef GRID_MATH_TRACE_H
|
||||||
#define GRID_MATH_TRACE_H
|
#define GRID_MATH_TRACE_H
|
||||||
namespace Grid {
|
|
||||||
|
NAMESPACE_BEGIN(Grid);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
// Traces: both all indices and a specific index. Indices must be
|
// Traces: both all indices and a specific index. Indices must be
|
||||||
@ -60,7 +61,7 @@ inline auto trace(const iScalar<vtype> &arg) -> iScalar<decltype(trace(arg._inte
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<class vtype,int N>
|
template<class vtype,int N>
|
||||||
inline auto trace(const iVector<vtype,N> &arg) -> iVector<decltype(trace(arg._internal[0])),N>
|
inline auto trace(const iVector<vtype,N> &arg) -> iVector<decltype(trace(arg._internal[0])),N>
|
||||||
{
|
{
|
||||||
iVector<decltype(trace(arg._internal[0])),N> ret;
|
iVector<decltype(trace(arg._internal[0])),N> ret;
|
||||||
for(int i=0;i<N;i++){
|
for(int i=0;i<N;i++){
|
||||||
@ -69,6 +70,6 @@ template<class vtype,int N>
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NAMESPACE_END(Grid);
|
||||||
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/*************************************************************************************
|
/*************************************************************************************
|
||||||
Grid physics library, www.github.com/paboyle/Grid
|
Grid physics library, www.github.com/paboyle/Grid
|
||||||
Source file: ./lib/tensors/Tensor_traits.h
|
Source file: ./lib/tensors/Tensor_traits.h
|
||||||
Copyright (C) 2015
|
Copyright (C) 2015
|
||||||
@ -17,14 +17,14 @@ Author: Christopher Kelly <ckelly@phys.columbia.edu>
|
|||||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
See the full license in the file "LICENSE" in the top level distribution directory
|
See the full license in the file "LICENSE" in the top level distribution directory
|
||||||
*************************************************************************************/
|
*************************************************************************************/
|
||||||
/* END LEGAL */
|
/* END LEGAL */
|
||||||
#ifndef GRID_MATH_TRAITS_H
|
#ifndef GRID_MATH_TRAITS_H
|
||||||
#define GRID_MATH_TRAITS_H
|
#define GRID_MATH_TRAITS_H
|
||||||
|
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
namespace Grid {
|
NAMESPACE_BEGIN(Grid);
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////
|
||||||
// Want to recurse: GridTypeMapper<Matrix<vComplexD> >::scalar_type == ComplexD.
|
// Want to recurse: GridTypeMapper<Matrix<vComplexD> >::scalar_type == ComplexD.
|
||||||
@ -41,8 +41,8 @@ namespace Grid {
|
|||||||
//
|
//
|
||||||
//////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
template <class T> class GridTypeMapper {
|
template <class T> class GridTypeMapper {
|
||||||
public:
|
public:
|
||||||
typedef typename T::scalar_type scalar_type;
|
typedef typename T::scalar_type scalar_type;
|
||||||
typedef typename T::vector_type vector_type;
|
typedef typename T::vector_type vector_type;
|
||||||
typedef typename T::vector_typeD vector_typeD;
|
typedef typename T::vector_typeD vector_typeD;
|
||||||
@ -52,13 +52,13 @@ namespace Grid {
|
|||||||
typedef typename T::Realified Realified;
|
typedef typename T::Realified Realified;
|
||||||
typedef typename T::DoublePrecision DoublePrecision;
|
typedef typename T::DoublePrecision DoublePrecision;
|
||||||
enum { TensorLevel = T::TensorLevel };
|
enum { TensorLevel = T::TensorLevel };
|
||||||
};
|
};
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////
|
||||||
// Recursion stops with these template specialisations
|
// Recursion stops with these template specialisations
|
||||||
//////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////
|
||||||
template<> class GridTypeMapper<RealF> {
|
template<> class GridTypeMapper<RealF> {
|
||||||
public:
|
public:
|
||||||
typedef RealF scalar_type;
|
typedef RealF scalar_type;
|
||||||
typedef RealF vector_type;
|
typedef RealF vector_type;
|
||||||
typedef RealD vector_typeD;
|
typedef RealD vector_typeD;
|
||||||
@ -68,9 +68,9 @@ namespace Grid {
|
|||||||
typedef RealF Realified;
|
typedef RealF Realified;
|
||||||
typedef RealD DoublePrecision;
|
typedef RealD DoublePrecision;
|
||||||
enum { TensorLevel = 0 };
|
enum { TensorLevel = 0 };
|
||||||
};
|
};
|
||||||
template<> class GridTypeMapper<RealD> {
|
template<> class GridTypeMapper<RealD> {
|
||||||
public:
|
public:
|
||||||
typedef RealD scalar_type;
|
typedef RealD scalar_type;
|
||||||
typedef RealD vector_type;
|
typedef RealD vector_type;
|
||||||
typedef RealD vector_typeD;
|
typedef RealD vector_typeD;
|
||||||
@ -80,9 +80,9 @@ namespace Grid {
|
|||||||
typedef RealD Realified;
|
typedef RealD Realified;
|
||||||
typedef RealD DoublePrecision;
|
typedef RealD DoublePrecision;
|
||||||
enum { TensorLevel = 0 };
|
enum { TensorLevel = 0 };
|
||||||
};
|
};
|
||||||
template<> class GridTypeMapper<ComplexF> {
|
template<> class GridTypeMapper<ComplexF> {
|
||||||
public:
|
public:
|
||||||
typedef ComplexF scalar_type;
|
typedef ComplexF scalar_type;
|
||||||
typedef ComplexF vector_type;
|
typedef ComplexF vector_type;
|
||||||
typedef ComplexD vector_typeD;
|
typedef ComplexD vector_typeD;
|
||||||
@ -92,9 +92,9 @@ namespace Grid {
|
|||||||
typedef RealF Realified;
|
typedef RealF Realified;
|
||||||
typedef ComplexD DoublePrecision;
|
typedef ComplexD DoublePrecision;
|
||||||
enum { TensorLevel = 0 };
|
enum { TensorLevel = 0 };
|
||||||
};
|
};
|
||||||
template<> class GridTypeMapper<ComplexD> {
|
template<> class GridTypeMapper<ComplexD> {
|
||||||
public:
|
public:
|
||||||
typedef ComplexD scalar_type;
|
typedef ComplexD scalar_type;
|
||||||
typedef ComplexD vector_type;
|
typedef ComplexD vector_type;
|
||||||
typedef ComplexD vector_typeD;
|
typedef ComplexD vector_typeD;
|
||||||
@ -104,9 +104,9 @@ namespace Grid {
|
|||||||
typedef RealD Realified;
|
typedef RealD Realified;
|
||||||
typedef ComplexD DoublePrecision;
|
typedef ComplexD DoublePrecision;
|
||||||
enum { TensorLevel = 0 };
|
enum { TensorLevel = 0 };
|
||||||
};
|
};
|
||||||
template<> class GridTypeMapper<Integer> {
|
template<> class GridTypeMapper<Integer> {
|
||||||
public:
|
public:
|
||||||
typedef Integer scalar_type;
|
typedef Integer scalar_type;
|
||||||
typedef Integer vector_type;
|
typedef Integer vector_type;
|
||||||
typedef Integer vector_typeD;
|
typedef Integer vector_typeD;
|
||||||
@ -116,10 +116,10 @@ namespace Grid {
|
|||||||
typedef void Realified;
|
typedef void Realified;
|
||||||
typedef void DoublePrecision;
|
typedef void DoublePrecision;
|
||||||
enum { TensorLevel = 0 };
|
enum { TensorLevel = 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
template<> class GridTypeMapper<vRealF> {
|
template<> class GridTypeMapper<vRealF> {
|
||||||
public:
|
public:
|
||||||
typedef RealF scalar_type;
|
typedef RealF scalar_type;
|
||||||
typedef vRealF vector_type;
|
typedef vRealF vector_type;
|
||||||
typedef vRealD vector_typeD;
|
typedef vRealD vector_typeD;
|
||||||
@ -129,9 +129,9 @@ namespace Grid {
|
|||||||
typedef vRealF Realified;
|
typedef vRealF Realified;
|
||||||
typedef vRealD DoublePrecision;
|
typedef vRealD DoublePrecision;
|
||||||
enum { TensorLevel = 0 };
|
enum { TensorLevel = 0 };
|
||||||
};
|
};
|
||||||
template<> class GridTypeMapper<vRealD> {
|
template<> class GridTypeMapper<vRealD> {
|
||||||
public:
|
public:
|
||||||
typedef RealD scalar_type;
|
typedef RealD scalar_type;
|
||||||
typedef vRealD vector_type;
|
typedef vRealD vector_type;
|
||||||
typedef vRealD vector_typeD;
|
typedef vRealD vector_typeD;
|
||||||
@ -141,9 +141,9 @@ namespace Grid {
|
|||||||
typedef vRealD Realified;
|
typedef vRealD Realified;
|
||||||
typedef vRealD DoublePrecision;
|
typedef vRealD DoublePrecision;
|
||||||
enum { TensorLevel = 0 };
|
enum { TensorLevel = 0 };
|
||||||
};
|
};
|
||||||
template<> class GridTypeMapper<vComplexH> {
|
template<> class GridTypeMapper<vComplexH> {
|
||||||
public:
|
public:
|
||||||
typedef ComplexF scalar_type;
|
typedef ComplexF scalar_type;
|
||||||
typedef vComplexH vector_type;
|
typedef vComplexH vector_type;
|
||||||
typedef vComplexD vector_typeD;
|
typedef vComplexD vector_typeD;
|
||||||
@ -153,9 +153,9 @@ namespace Grid {
|
|||||||
typedef vRealH Realified;
|
typedef vRealH Realified;
|
||||||
typedef vComplexD DoublePrecision;
|
typedef vComplexD DoublePrecision;
|
||||||
enum { TensorLevel = 0 };
|
enum { TensorLevel = 0 };
|
||||||
};
|
};
|
||||||
template<> class GridTypeMapper<vComplexF> {
|
template<> class GridTypeMapper<vComplexF> {
|
||||||
public:
|
public:
|
||||||
typedef ComplexF scalar_type;
|
typedef ComplexF scalar_type;
|
||||||
typedef vComplexF vector_type;
|
typedef vComplexF vector_type;
|
||||||
typedef vComplexD vector_typeD;
|
typedef vComplexD vector_typeD;
|
||||||
@ -165,9 +165,9 @@ namespace Grid {
|
|||||||
typedef vRealF Realified;
|
typedef vRealF Realified;
|
||||||
typedef vComplexD DoublePrecision;
|
typedef vComplexD DoublePrecision;
|
||||||
enum { TensorLevel = 0 };
|
enum { TensorLevel = 0 };
|
||||||
};
|
};
|
||||||
template<> class GridTypeMapper<vComplexD> {
|
template<> class GridTypeMapper<vComplexD> {
|
||||||
public:
|
public:
|
||||||
typedef ComplexD scalar_type;
|
typedef ComplexD scalar_type;
|
||||||
typedef vComplexD vector_type;
|
typedef vComplexD vector_type;
|
||||||
typedef vComplexD vector_typeD;
|
typedef vComplexD vector_typeD;
|
||||||
@ -177,9 +177,9 @@ namespace Grid {
|
|||||||
typedef vRealD Realified;
|
typedef vRealD Realified;
|
||||||
typedef vComplexD DoublePrecision;
|
typedef vComplexD DoublePrecision;
|
||||||
enum { TensorLevel = 0 };
|
enum { TensorLevel = 0 };
|
||||||
};
|
};
|
||||||
template<> class GridTypeMapper<vInteger> {
|
template<> class GridTypeMapper<vInteger> {
|
||||||
public:
|
public:
|
||||||
typedef Integer scalar_type;
|
typedef Integer scalar_type;
|
||||||
typedef vInteger vector_type;
|
typedef vInteger vector_type;
|
||||||
typedef vInteger vector_typeD;
|
typedef vInteger vector_typeD;
|
||||||
@ -189,83 +189,83 @@ namespace Grid {
|
|||||||
typedef void Realified;
|
typedef void Realified;
|
||||||
typedef void DoublePrecision;
|
typedef void DoublePrecision;
|
||||||
enum { TensorLevel = 0 };
|
enum { TensorLevel = 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
// First some of my own traits
|
// First some of my own traits
|
||||||
template<typename T> struct isGridTensor {
|
template<typename T> struct isGridTensor {
|
||||||
static const bool value = true;
|
static const bool value = true;
|
||||||
static const bool notvalue = false;
|
static const bool notvalue = false;
|
||||||
};
|
};
|
||||||
template<> struct isGridTensor<int > {
|
template<> struct isGridTensor<int > {
|
||||||
static const bool value = false;
|
static const bool value = false;
|
||||||
static const bool notvalue = true;
|
static const bool notvalue = true;
|
||||||
};
|
};
|
||||||
template<> struct isGridTensor<RealD > {
|
template<> struct isGridTensor<RealD > {
|
||||||
static const bool value = false;
|
static const bool value = false;
|
||||||
static const bool notvalue = true;
|
static const bool notvalue = true;
|
||||||
};
|
};
|
||||||
template<> struct isGridTensor<RealF > {
|
template<> struct isGridTensor<RealF > {
|
||||||
static const bool value = false;
|
static const bool value = false;
|
||||||
static const bool notvalue = true;
|
static const bool notvalue = true;
|
||||||
};
|
};
|
||||||
template<> struct isGridTensor<ComplexD > {
|
template<> struct isGridTensor<ComplexD > {
|
||||||
static const bool value = false;
|
static const bool value = false;
|
||||||
static const bool notvalue = true;
|
static const bool notvalue = true;
|
||||||
};
|
};
|
||||||
template<> struct isGridTensor<ComplexF > {
|
template<> struct isGridTensor<ComplexF > {
|
||||||
static const bool value = false;
|
static const bool value = false;
|
||||||
static const bool notvalue = true;
|
static const bool notvalue = true;
|
||||||
};
|
};
|
||||||
template<> struct isGridTensor<Integer > {
|
template<> struct isGridTensor<Integer > {
|
||||||
static const bool value = false;
|
static const bool value = false;
|
||||||
static const bool notvalue = true;
|
static const bool notvalue = true;
|
||||||
};
|
};
|
||||||
template<> struct isGridTensor<vRealD > {
|
template<> struct isGridTensor<vRealD > {
|
||||||
static const bool value = false;
|
static const bool value = false;
|
||||||
static const bool notvalue = true;
|
static const bool notvalue = true;
|
||||||
};
|
};
|
||||||
template<> struct isGridTensor<vRealF > {
|
template<> struct isGridTensor<vRealF > {
|
||||||
static const bool value = false;
|
static const bool value = false;
|
||||||
static const bool notvalue = true;
|
static const bool notvalue = true;
|
||||||
};
|
};
|
||||||
template<> struct isGridTensor<vComplexD > {
|
template<> struct isGridTensor<vComplexD > {
|
||||||
static const bool value = false;
|
static const bool value = false;
|
||||||
static const bool notvalue = true;
|
static const bool notvalue = true;
|
||||||
};
|
};
|
||||||
template<> struct isGridTensor<vComplexF > {
|
template<> struct isGridTensor<vComplexF > {
|
||||||
static const bool value = false;
|
static const bool value = false;
|
||||||
static const bool notvalue = true;
|
static const bool notvalue = true;
|
||||||
};
|
};
|
||||||
template<> struct isGridTensor<vInteger > {
|
template<> struct isGridTensor<vInteger > {
|
||||||
static const bool value = false;
|
static const bool value = false;
|
||||||
static const bool notvalue = true;
|
static const bool notvalue = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Match the index
|
// Match the index
|
||||||
template<typename T,int Level> struct matchGridTensorIndex {
|
template<typename T,int Level> struct matchGridTensorIndex {
|
||||||
static const bool value = (Level==T::TensorLevel);
|
static const bool value = (Level==T::TensorLevel);
|
||||||
static const bool notvalue = (Level!=T::TensorLevel);
|
static const bool notvalue = (Level!=T::TensorLevel);
|
||||||
};
|
};
|
||||||
// What is the vtype
|
// What is the vtype
|
||||||
template<typename T> struct isComplex {
|
template<typename T> struct isComplex {
|
||||||
static const bool value = false;
|
static const bool value = false;
|
||||||
};
|
};
|
||||||
template<> struct isComplex<ComplexF> {
|
template<> struct isComplex<ComplexF> {
|
||||||
static const bool value = true;
|
static const bool value = true;
|
||||||
};
|
};
|
||||||
template<> struct isComplex<ComplexD> {
|
template<> struct isComplex<ComplexD> {
|
||||||
static const bool value = true;
|
static const bool value = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
//Get the SIMD vector type from a Grid tensor or Lattice<Tensor>
|
//Get the SIMD vector type from a Grid tensor or Lattice<Tensor>
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct getVectorType{
|
struct getVectorType{
|
||||||
typedef T type;
|
typedef T type;
|
||||||
};
|
};
|
||||||
|
|
||||||
//Query if a tensor or Lattice<Tensor> is SIMD vector or scalar
|
//Query if a tensor or Lattice<Tensor> is SIMD vector or scalar
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class isSIMDvectorized{
|
class isSIMDvectorized{
|
||||||
template<typename U>
|
template<typename U>
|
||||||
static typename std::enable_if< !std::is_same< typename GridTypeMapper<typename getVectorType<U>::type>::scalar_type,
|
static typename std::enable_if< !std::is_same< typename GridTypeMapper<typename getVectorType<U>::type>::scalar_type,
|
||||||
typename GridTypeMapper<typename getVectorType<U>::type>::vector_type>::value, char>::type test(void *);
|
typename GridTypeMapper<typename getVectorType<U>::type>::vector_type>::value, char>::type test(void *);
|
||||||
@ -273,22 +273,24 @@ namespace Grid {
|
|||||||
template<typename U>
|
template<typename U>
|
||||||
static double test(...);
|
static double test(...);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum {value = sizeof(test<T>(0)) == sizeof(char) };
|
enum {value = sizeof(test<T>(0)) == sizeof(char) };
|
||||||
};
|
};
|
||||||
|
|
||||||
//Get the precision of a Lattice, tensor or scalar type in units of sizeof(float)
|
//Get the precision of a Lattice, tensor or scalar type in units of sizeof(float)
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class getPrecision{
|
class getPrecision{
|
||||||
public:
|
public:
|
||||||
//get the vector_obj (i.e. a grid Tensor) if its a Lattice<vobj>, do nothing otherwise (i.e. if fundamental or grid Tensor)
|
//get the vector_obj (i.e. a grid Tensor) if its a Lattice<vobj>, do nothing otherwise (i.e. if fundamental or grid Tensor)
|
||||||
typedef typename getVectorType<T>::type vector_obj;
|
typedef typename getVectorType<T>::type vector_obj;
|
||||||
typedef typename GridTypeMapper<vector_obj>::scalar_type scalar_type; //get the associated scalar type. Works on fundamental and tensor types
|
typedef typename GridTypeMapper<vector_obj>::scalar_type scalar_type; //get the associated scalar type. Works on fundamental and tensor types
|
||||||
typedef typename GridTypeMapper<scalar_type>::Realified real_scalar_type; //remove any std::complex wrapper, should get us to the fundamental type
|
typedef typename GridTypeMapper<scalar_type>::Realified real_scalar_type; //remove any std::complex wrapper, should get us to the fundamental type
|
||||||
|
|
||||||
enum { value = sizeof(real_scalar_type)/sizeof(float) };
|
enum { value = sizeof(real_scalar_type)/sizeof(float) };
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
NAMESPACE_END(Grid);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/*************************************************************************************
|
/*************************************************************************************
|
||||||
|
|
||||||
Grid physics library, www.github.com/paboyle/Grid
|
Grid physics library, www.github.com/paboyle/Grid
|
||||||
|
|
||||||
@ -23,13 +23,12 @@ Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
|||||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
See the full license in the file "LICENSE" in the top level distribution directory
|
See the full license in the file "LICENSE" in the top level distribution directory
|
||||||
*************************************************************************************/
|
*************************************************************************************/
|
||||||
/* END LEGAL */
|
/* END LEGAL */
|
||||||
#ifndef GRID_MATH_TRANSPOSE_H
|
#ifndef GRID_MATH_TRANSPOSE_H
|
||||||
#define GRID_MATH_TRANSPOSE_H
|
#define GRID_MATH_TRANSPOSE_H
|
||||||
namespace Grid {
|
|
||||||
|
|
||||||
|
|
||||||
|
NAMESPACE_BEGIN(Grid);
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////
|
||||||
// Transpose all indices
|
// Transpose all indices
|
||||||
@ -41,45 +40,45 @@ inline RealD transpose(RealD &rhs){ return rhs;}
|
|||||||
inline RealF transpose(RealF &rhs){ return rhs;}
|
inline RealF transpose(RealF &rhs){ return rhs;}
|
||||||
|
|
||||||
template<class vtype,int N>
|
template<class vtype,int N>
|
||||||
inline typename std::enable_if<isGridTensor<vtype>::value, iMatrix<vtype,N> >::type
|
inline typename std::enable_if<isGridTensor<vtype>::value, iMatrix<vtype,N> >::type
|
||||||
transpose(iMatrix<vtype,N> arg)
|
transpose(iMatrix<vtype,N> arg)
|
||||||
{
|
{
|
||||||
iMatrix<vtype,N> ret;
|
iMatrix<vtype,N> ret;
|
||||||
for(int i=0;i<N;i++){
|
for(int i=0;i<N;i++){
|
||||||
for(int j=0;j<N;j++){
|
for(int j=0;j<N;j++){
|
||||||
ret._internal[i][j] = transpose(arg._internal[j][i]); // NB recurses
|
ret._internal[i][j] = transpose(arg._internal[j][i]); // NB recurses
|
||||||
}}
|
}}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
template<class vtype,int N>
|
template<class vtype,int N>
|
||||||
inline typename std::enable_if<isGridTensor<vtype>::notvalue, iMatrix<vtype,N> >::type
|
inline typename std::enable_if<isGridTensor<vtype>::notvalue, iMatrix<vtype,N> >::type
|
||||||
transpose(iMatrix<vtype,N> arg)
|
transpose(iMatrix<vtype,N> arg)
|
||||||
{
|
{
|
||||||
iMatrix<vtype,N> ret;
|
iMatrix<vtype,N> ret;
|
||||||
for(int i=0;i<N;i++){
|
for(int i=0;i<N;i++){
|
||||||
for(int j=0;j<N;j++){
|
for(int j=0;j<N;j++){
|
||||||
ret._internal[i][j] = arg._internal[j][i]; // Stop recursion if not a tensor type
|
ret._internal[i][j] = arg._internal[j][i]; // Stop recursion if not a tensor type
|
||||||
}}
|
}}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class vtype>
|
template<class vtype>
|
||||||
inline typename std::enable_if<isGridTensor<vtype>::value, iScalar<vtype> >::type
|
inline typename std::enable_if<isGridTensor<vtype>::value, iScalar<vtype> >::type
|
||||||
transpose(iScalar<vtype> arg)
|
transpose(iScalar<vtype> arg)
|
||||||
{
|
{
|
||||||
iScalar<vtype> ret;
|
iScalar<vtype> ret;
|
||||||
ret._internal = transpose(arg._internal); // NB recurses
|
ret._internal = transpose(arg._internal); // NB recurses
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class vtype>
|
template<class vtype>
|
||||||
inline typename std::enable_if<isGridTensor<vtype>::notvalue, iScalar<vtype> >::type
|
inline typename std::enable_if<isGridTensor<vtype>::notvalue, iScalar<vtype> >::type
|
||||||
transpose(iScalar<vtype> arg)
|
transpose(iScalar<vtype> arg)
|
||||||
{
|
{
|
||||||
iScalar<vtype> ret;
|
iScalar<vtype> ret;
|
||||||
ret._internal = arg._internal; // NB recursion stops
|
ret._internal = arg._internal; // NB recursion stops
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -88,7 +87,7 @@ template<class vtype>
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
#if 0
|
#if 0
|
||||||
template<int Level,class vtype,int N> inline
|
template<int Level,class vtype,int N> inline
|
||||||
typename std::enable_if<matchGridTensorIndex<iMatrix<vtype,N>,Level>::value, iMatrix<vtype,N> >::type
|
typename std::enable_if<matchGridTensorIndex<iMatrix<vtype,N>,Level>::value, iMatrix<vtype,N> >::type
|
||||||
transposeIndex (const iMatrix<vtype,N> &arg)
|
transposeIndex (const iMatrix<vtype,N> &arg)
|
||||||
{
|
{
|
||||||
iMatrix<vtype,N> ret;
|
iMatrix<vtype,N> ret;
|
||||||
@ -126,5 +125,6 @@ transposeIndex (const iScalar<vtype> &arg)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
NAMESPACE_END(Grid);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/*************************************************************************************
|
/*************************************************************************************
|
||||||
|
|
||||||
Grid physics library, www.github.com/paboyle/Grid
|
Grid physics library, www.github.com/paboyle/Grid
|
||||||
|
|
||||||
@ -25,62 +25,63 @@ Author: paboyle <paboyle@ph.ed.ac.uk>
|
|||||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
See the full license in the file "LICENSE" in the top level distribution directory
|
See the full license in the file "LICENSE" in the top level distribution directory
|
||||||
*************************************************************************************/
|
*************************************************************************************/
|
||||||
/* END LEGAL */
|
/* END LEGAL */
|
||||||
#ifndef GRID_TENSOR_UNARY_H
|
#ifndef GRID_TENSOR_UNARY_H
|
||||||
#define GRID_TENSOR_UNARY_H
|
#define GRID_TENSOR_UNARY_H
|
||||||
namespace Grid {
|
|
||||||
|
|
||||||
#define UNARY(func)\
|
NAMESPACE_BEGIN(Grid);
|
||||||
template<class obj> inline auto func(const iScalar<obj> &z) -> iScalar<obj>\
|
|
||||||
{\
|
#define UNARY(func) \
|
||||||
iScalar<obj> ret;\
|
template<class obj> inline auto func(const iScalar<obj> &z) -> iScalar<obj> \
|
||||||
ret._internal = func( (z._internal));\
|
{ \
|
||||||
return ret;\
|
iScalar<obj> ret; \
|
||||||
}\
|
ret._internal = func( (z._internal)); \
|
||||||
template<class obj,int N> inline auto func(const iVector<obj,N> &z) -> iVector<obj,N>\
|
return ret; \
|
||||||
{\
|
} \
|
||||||
iVector<obj,N> ret;\
|
template<class obj,int N> inline auto func(const iVector<obj,N> &z) -> iVector<obj,N> \
|
||||||
for(int c1=0;c1<N;c1++){\
|
{ \
|
||||||
ret._internal[c1] = func( (z._internal[c1]));\
|
iVector<obj,N> ret; \
|
||||||
}\
|
for(int c1=0;c1<N;c1++){ \
|
||||||
return ret;\
|
ret._internal[c1] = func( (z._internal[c1])); \
|
||||||
}\
|
} \
|
||||||
template<class obj,int N> inline auto func(const iMatrix<obj,N> &z) -> iMatrix<obj,N>\
|
return ret; \
|
||||||
{\
|
} \
|
||||||
iMatrix<obj,N> ret;\
|
template<class obj,int N> inline auto func(const iMatrix<obj,N> &z) -> iMatrix<obj,N> \
|
||||||
for(int c1=0;c1<N;c1++){\
|
{ \
|
||||||
for(int c2=0;c2<N;c2++){\
|
iMatrix<obj,N> ret; \
|
||||||
ret._internal[c1][c2] = func( (z._internal[c1][c2]));\
|
for(int c1=0;c1<N;c1++){ \
|
||||||
}}\
|
for(int c2=0;c2<N;c2++){ \
|
||||||
return ret;\
|
ret._internal[c1][c2] = func( (z._internal[c1][c2])); \
|
||||||
}
|
}} \
|
||||||
|
return ret; \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#define BINARY_RSCALAR(func,scal) \
|
#define BINARY_RSCALAR(func,scal) \
|
||||||
template<class obj> inline iScalar<obj> func(const iScalar<obj> &z,scal y) \
|
template<class obj> inline iScalar<obj> func(const iScalar<obj> &z,scal y) \
|
||||||
{\
|
{ \
|
||||||
iScalar<obj> ret;\
|
iScalar<obj> ret; \
|
||||||
ret._internal = func(z._internal,y); \
|
ret._internal = func(z._internal,y); \
|
||||||
return ret;\
|
return ret; \
|
||||||
}\
|
} \
|
||||||
template<class obj,int N> inline iVector<obj,N> func(const iVector<obj,N> &z,scal y) \
|
template<class obj,int N> inline iVector<obj,N> func(const iVector<obj,N> &z,scal y) \
|
||||||
{\
|
{ \
|
||||||
iVector<obj,N> ret;\
|
iVector<obj,N> ret; \
|
||||||
for(int c1=0;c1<N;c1++){\
|
for(int c1=0;c1<N;c1++){ \
|
||||||
ret._internal[c1] = func(z._internal[c1],y); \
|
ret._internal[c1] = func(z._internal[c1],y); \
|
||||||
}\
|
} \
|
||||||
return ret;\
|
return ret; \
|
||||||
}\
|
} \
|
||||||
template<class obj,int N> inline iMatrix<obj,N> func(const iMatrix<obj,N> &z, scal y) \
|
template<class obj,int N> inline iMatrix<obj,N> func(const iMatrix<obj,N> &z, scal y) \
|
||||||
{\
|
{ \
|
||||||
iMatrix<obj,N> ret;\
|
iMatrix<obj,N> ret; \
|
||||||
for(int c1=0;c1<N;c1++){\
|
for(int c1=0;c1<N;c1++){ \
|
||||||
for(int c2=0;c2<N;c2++){\
|
for(int c2=0;c2<N;c2++){ \
|
||||||
ret._internal[c1][c2] = func(z._internal[c1][c2],y); \
|
ret._internal[c1][c2] = func(z._internal[c1][c2],y); \
|
||||||
}}\
|
}} \
|
||||||
return ret;\
|
return ret; \
|
||||||
}
|
}
|
||||||
|
|
||||||
UNARY(sqrt);
|
UNARY(sqrt);
|
||||||
UNARY(rsqrt);
|
UNARY(rsqrt);
|
||||||
@ -100,7 +101,7 @@ template<class obj> inline auto toReal(const iScalar<obj> &z) -> typename iScala
|
|||||||
ret._internal = toReal(z._internal);
|
ret._internal = toReal(z._internal);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
template<class obj,int N> inline auto toReal(const iVector<obj,N> &z) -> typename iVector<obj,N>::Realified
|
template<class obj,int N> inline auto toReal(const iVector<obj,N> &z) -> typename iVector<obj,N>::Realified
|
||||||
{
|
{
|
||||||
typename iVector<obj,N>::Realified ret;
|
typename iVector<obj,N>::Realified ret;
|
||||||
for(int c1=0;c1<N;c1++){
|
for(int c1=0;c1<N;c1++){
|
||||||
@ -124,7 +125,7 @@ template<class obj> inline auto toComplex(const iScalar<obj> &z) -> typename iSc
|
|||||||
ret._internal = toComplex(z._internal);
|
ret._internal = toComplex(z._internal);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
template<class obj,int N> inline auto toComplex(const iVector<obj,N> &z) -> typename iVector<obj,N>::Complexified
|
template<class obj,int N> inline auto toComplex(const iVector<obj,N> &z) -> typename iVector<obj,N>::Complexified
|
||||||
{
|
{
|
||||||
typename iVector<obj,N>::Complexified ret;
|
typename iVector<obj,N>::Complexified ret;
|
||||||
for(int c1=0;c1<N;c1++){
|
for(int c1=0;c1<N;c1++){
|
||||||
@ -149,6 +150,6 @@ BINARY_RSCALAR(pow,RealD);
|
|||||||
#undef UNARY
|
#undef UNARY
|
||||||
#undef BINARY_RSCALAR
|
#undef BINARY_RSCALAR
|
||||||
|
|
||||||
|
NAMESPACE_END(Grid);
|
||||||
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/*************************************************************************************
|
/*************************************************************************************
|
||||||
|
|
||||||
Grid physics library, www.github.com/paboyle/Grid
|
Grid physics library, www.github.com/paboyle/Grid
|
||||||
|
|
||||||
@ -25,8 +25,8 @@ Author: neo <cossu@post.kek.jp>
|
|||||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
See the full license in the file "LICENSE" in the top level distribution directory
|
See the full license in the file "LICENSE" in the top level distribution directory
|
||||||
*************************************************************************************/
|
*************************************************************************************/
|
||||||
/* END LEGAL */
|
/* END LEGAL */
|
||||||
#ifndef GRID_MATH_H
|
#ifndef GRID_MATH_H
|
||||||
#define GRID_MATH_H
|
#define GRID_MATH_H
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user