mirror of
https://github.com/paboyle/Grid.git
synced 2025-08-03 13:17:06 +01:00
Tensor reformatted with NAMESPACE too
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/*************************************************************************************
|
||||
/*************************************************************************************
|
||||
|
||||
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.
|
||||
|
||||
See the full license in the file "LICENSE" in the top level distribution directory
|
||||
*************************************************************************************/
|
||||
/* END LEGAL */
|
||||
*************************************************************************************/
|
||||
/* END LEGAL */
|
||||
#ifndef GRID_TENSOR_UNARY_H
|
||||
#define GRID_TENSOR_UNARY_H
|
||||
namespace Grid {
|
||||
|
||||
#define UNARY(func)\
|
||||
template<class obj> inline auto func(const iScalar<obj> &z) -> iScalar<obj>\
|
||||
{\
|
||||
iScalar<obj> ret;\
|
||||
ret._internal = func( (z._internal));\
|
||||
return ret;\
|
||||
}\
|
||||
template<class obj,int N> inline auto func(const iVector<obj,N> &z) -> iVector<obj,N>\
|
||||
{\
|
||||
iVector<obj,N> ret;\
|
||||
for(int c1=0;c1<N;c1++){\
|
||||
ret._internal[c1] = func( (z._internal[c1]));\
|
||||
}\
|
||||
return ret;\
|
||||
}\
|
||||
template<class obj,int N> inline auto func(const iMatrix<obj,N> &z) -> iMatrix<obj,N>\
|
||||
{\
|
||||
iMatrix<obj,N> ret;\
|
||||
for(int c1=0;c1<N;c1++){\
|
||||
for(int c2=0;c2<N;c2++){\
|
||||
ret._internal[c1][c2] = func( (z._internal[c1][c2]));\
|
||||
}}\
|
||||
return ret;\
|
||||
}
|
||||
NAMESPACE_BEGIN(Grid);
|
||||
|
||||
#define UNARY(func) \
|
||||
template<class obj> inline auto func(const iScalar<obj> &z) -> iScalar<obj> \
|
||||
{ \
|
||||
iScalar<obj> ret; \
|
||||
ret._internal = func( (z._internal)); \
|
||||
return ret; \
|
||||
} \
|
||||
template<class obj,int N> inline auto func(const iVector<obj,N> &z) -> iVector<obj,N> \
|
||||
{ \
|
||||
iVector<obj,N> ret; \
|
||||
for(int c1=0;c1<N;c1++){ \
|
||||
ret._internal[c1] = func( (z._internal[c1])); \
|
||||
} \
|
||||
return ret; \
|
||||
} \
|
||||
template<class obj,int N> inline auto func(const iMatrix<obj,N> &z) -> iMatrix<obj,N> \
|
||||
{ \
|
||||
iMatrix<obj,N> ret; \
|
||||
for(int c1=0;c1<N;c1++){ \
|
||||
for(int c2=0;c2<N;c2++){ \
|
||||
ret._internal[c1][c2] = func( (z._internal[c1][c2])); \
|
||||
}} \
|
||||
return ret; \
|
||||
}
|
||||
|
||||
|
||||
#define BINARY_RSCALAR(func,scal) \
|
||||
template<class obj> inline iScalar<obj> func(const iScalar<obj> &z,scal y) \
|
||||
{\
|
||||
iScalar<obj> ret;\
|
||||
ret._internal = func(z._internal,y); \
|
||||
return ret;\
|
||||
}\
|
||||
template<class obj,int N> inline iVector<obj,N> func(const iVector<obj,N> &z,scal y) \
|
||||
{\
|
||||
iVector<obj,N> ret;\
|
||||
for(int c1=0;c1<N;c1++){\
|
||||
ret._internal[c1] = func(z._internal[c1],y); \
|
||||
}\
|
||||
return ret;\
|
||||
}\
|
||||
template<class obj,int N> inline iMatrix<obj,N> func(const iMatrix<obj,N> &z, scal y) \
|
||||
{\
|
||||
iMatrix<obj,N> ret;\
|
||||
for(int c1=0;c1<N;c1++){\
|
||||
for(int c2=0;c2<N;c2++){\
|
||||
ret._internal[c1][c2] = func(z._internal[c1][c2],y); \
|
||||
}}\
|
||||
return ret;\
|
||||
}
|
||||
template<class obj> inline iScalar<obj> func(const iScalar<obj> &z,scal y) \
|
||||
{ \
|
||||
iScalar<obj> ret; \
|
||||
ret._internal = func(z._internal,y); \
|
||||
return ret; \
|
||||
} \
|
||||
template<class obj,int N> inline iVector<obj,N> func(const iVector<obj,N> &z,scal y) \
|
||||
{ \
|
||||
iVector<obj,N> ret; \
|
||||
for(int c1=0;c1<N;c1++){ \
|
||||
ret._internal[c1] = func(z._internal[c1],y); \
|
||||
} \
|
||||
return ret; \
|
||||
} \
|
||||
template<class obj,int N> inline iMatrix<obj,N> func(const iMatrix<obj,N> &z, scal y) \
|
||||
{ \
|
||||
iMatrix<obj,N> ret; \
|
||||
for(int c1=0;c1<N;c1++){ \
|
||||
for(int c2=0;c2<N;c2++){ \
|
||||
ret._internal[c1][c2] = func(z._internal[c1][c2],y); \
|
||||
}} \
|
||||
return ret; \
|
||||
}
|
||||
|
||||
UNARY(sqrt);
|
||||
UNARY(rsqrt);
|
||||
@@ -100,7 +101,7 @@ template<class obj> inline auto toReal(const iScalar<obj> &z) -> typename iScala
|
||||
ret._internal = toReal(z._internal);
|
||||
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;
|
||||
for(int c1=0;c1<N;c1++){
|
||||
@@ -112,9 +113,9 @@ template<class obj,int N> inline auto toReal(const iMatrix<obj,N> &z) -> typenam
|
||||
{
|
||||
typename iMatrix<obj,N>::Realified ret;
|
||||
for(int c1=0;c1<N;c1++){
|
||||
for(int c2=0;c2<N;c2++){
|
||||
ret._internal[c1][c2] = toReal(z._internal[c1][c2]);
|
||||
}}
|
||||
for(int c2=0;c2<N;c2++){
|
||||
ret._internal[c1][c2] = toReal(z._internal[c1][c2]);
|
||||
}}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -124,7 +125,7 @@ template<class obj> inline auto toComplex(const iScalar<obj> &z) -> typename iSc
|
||||
ret._internal = toComplex(z._internal);
|
||||
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;
|
||||
for(int c1=0;c1<N;c1++){
|
||||
@@ -136,9 +137,9 @@ template<class obj,int N> inline auto toComplex(const iMatrix<obj,N> &z) -> type
|
||||
{
|
||||
typename iMatrix<obj,N>::Complexified ret;
|
||||
for(int c1=0;c1<N;c1++){
|
||||
for(int c2=0;c2<N;c2++){
|
||||
ret._internal[c1][c2] = toComplex(z._internal[c1][c2]);
|
||||
}}
|
||||
for(int c2=0;c2<N;c2++){
|
||||
ret._internal[c1][c2] = toComplex(z._internal[c1][c2]);
|
||||
}}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -149,6 +150,6 @@ BINARY_RSCALAR(pow,RealD);
|
||||
#undef UNARY
|
||||
#undef BINARY_RSCALAR
|
||||
|
||||
NAMESPACE_END(Grid);
|
||||
|
||||
}
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user