mirror of
https://github.com/paboyle/Grid.git
synced 2024-11-10 07:55:35 +00:00
a5c3edaca9
compile it again.
37 lines
1.1 KiB
C++
37 lines
1.1 KiB
C++
#ifndef GRID_MATH_TRACE_H
|
|
#define GRID_MATH_TRACE_H
|
|
namespace Grid {
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
// Traces: both all indices and a specific index. Indices must be
|
|
// either scalar or matrix
|
|
/////////////////////////////////////////////////////////////////
|
|
|
|
inline ComplexF trace( const ComplexF &arg){ return arg;}
|
|
inline ComplexD trace( const ComplexD &arg){ return arg;}
|
|
inline RealF trace( const RealF &arg){ return arg;}
|
|
inline RealD trace( const RealD &arg){ return arg;}
|
|
|
|
template<class vtype,int N>
|
|
inline auto trace(const iMatrix<vtype,N> &arg) -> iScalar<decltype(trace(arg._internal[0][0]))>
|
|
{
|
|
iScalar<decltype( trace(arg._internal[0][0] )) > ret;
|
|
zeroit(ret._internal);
|
|
for(int i=0;i<N;i++){
|
|
ret._internal=ret._internal+trace(arg._internal[i][i]);
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
template<class vtype>
|
|
inline auto trace(const iScalar<vtype> &arg) -> iScalar<decltype(trace(arg._internal))>
|
|
{
|
|
iScalar<decltype(trace(arg._internal))> ret;
|
|
ret._internal=trace(arg._internal);
|
|
return ret;
|
|
}
|
|
|
|
|
|
}
|
|
#endif
|