1
0
mirror of https://github.com/paboyle/Grid.git synced 2024-09-20 17:25:37 +01:00
Grid/lib/tensors/Tensor_arith_scalar.h

261 lines
11 KiB
C
Raw Normal View History

2015-04-18 18:54:30 +01:00
#ifndef GRID_MATH_ARITH_SCALAR_H
#define GRID_MATH_ARITH_SCALAR_H
namespace Grid {
//////////////////////////////////////////////////////////////////////////////////////////
// Must support native C++ types Integer, Complex, Real
//////////////////////////////////////////////////////////////////////////////////////////
// multiplication by fundamental scalar type
2015-05-15 11:40:59 +01:00
template<class l,int N> strong_inline iScalar<l> operator * (const iScalar<l>& lhs,const typename iScalar<l>::scalar_type rhs)
2015-04-18 18:54:30 +01:00
{
typename iScalar<l>::tensor_reduced srhs; srhs=rhs;
2015-04-18 18:54:30 +01:00
return lhs*srhs;
}
2015-05-15 11:40:59 +01:00
template<class l,int N> strong_inline iScalar<l> operator * (const typename iScalar<l>::scalar_type lhs,const iScalar<l>& rhs) { return rhs*lhs; }
2015-04-18 18:54:30 +01:00
2015-05-15 11:40:59 +01:00
template<class l,int N> strong_inline iVector<l,N> operator * (const iVector<l,N>& lhs,const typename iScalar<l>::scalar_type rhs)
2015-04-18 18:54:30 +01:00
{
typename iVector<l,N>::tensor_reduced srhs; srhs=rhs;
2015-04-18 18:54:30 +01:00
return lhs*srhs;
}
2015-05-15 11:40:59 +01:00
template<class l,int N> strong_inline iVector<l,N> operator * (const typename iScalar<l>::scalar_type lhs,const iVector<l,N>& rhs) { return rhs*lhs; }
2015-04-18 18:54:30 +01:00
2015-05-15 11:40:59 +01:00
template<class l,int N> strong_inline iMatrix<l,N> operator * (const iMatrix<l,N>& lhs,const typename iScalar<l>::scalar_type &rhs)
2015-04-18 18:54:30 +01:00
{
typename iMatrix<l,N>::tensor_reduced srhs; srhs=rhs;
2015-04-18 18:54:30 +01:00
return lhs*srhs;
}
2015-05-15 11:40:59 +01:00
template<class l,int N> strong_inline iMatrix<l,N> operator * (const typename iScalar<l>::scalar_type & lhs,const iMatrix<l,N>& rhs) { return rhs*lhs; }
2015-04-18 18:54:30 +01:00
////////////////////////////////////////////////////////////////////
// Double support; cast to "scalar_type" through constructor
////////////////////////////////////////////////////////////////////
2015-05-15 11:40:59 +01:00
template<class l> strong_inline iScalar<l> operator * (const iScalar<l>& lhs,double rhs)
2015-04-18 18:54:30 +01:00
{
typename iScalar<l>::scalar_type t; t=rhs;
typename iScalar<l>::tensor_reduced srhs;srhs=t;
2015-04-18 18:54:30 +01:00
return lhs*srhs;
}
2015-05-15 11:40:59 +01:00
template<class l> strong_inline iScalar<l> operator * (double lhs,const iScalar<l>& rhs) { return rhs*lhs; }
2015-04-18 18:54:30 +01:00
2015-05-15 11:40:59 +01:00
template<class l,int N> strong_inline iVector<l,N> operator * (const iVector<l,N>& lhs,double rhs)
2015-04-18 18:54:30 +01:00
{
typename iScalar<l>::scalar_type t;t=rhs;
typename iScalar<l>::tensor_reduced srhs;srhs=t;
2015-04-18 18:54:30 +01:00
return lhs*srhs;
}
2015-05-15 11:40:59 +01:00
template<class l,int N> strong_inline iVector<l,N> operator * (double lhs,const iVector<l,N>& rhs) { return rhs*lhs; }
2015-04-18 18:54:30 +01:00
2015-05-15 11:40:59 +01:00
template<class l,int N> strong_inline iMatrix<l,N> operator * (const iMatrix<l,N>& lhs,double rhs)
2015-04-18 18:54:30 +01:00
{
typename iScalar<l>::scalar_type t;t=rhs;
typename iScalar<l>::tensor_reduced srhs;srhs=t;
2015-04-18 18:54:30 +01:00
return lhs*srhs;
}
2015-05-15 11:40:59 +01:00
template<class l,int N> strong_inline iMatrix<l,N> operator * (double lhs,const iMatrix<l,N>& rhs) { return rhs*lhs; }
2015-04-18 18:54:30 +01:00
////////////////////////////////////////////////////////////////////
// Complex support; cast to "scalar_type" through constructor
////////////////////////////////////////////////////////////////////
2015-05-15 11:40:59 +01:00
template<class l> strong_inline iScalar<l> operator * (const iScalar<l>& lhs,ComplexD rhs)
2015-04-18 18:54:30 +01:00
{
typename iScalar<l>::scalar_type t;t=rhs;
typename iScalar<l>::tensor_reduced srhs;srhs=t;
2015-04-18 18:54:30 +01:00
return lhs*srhs;
}
2015-05-15 11:40:59 +01:00
template<class l> strong_inline iScalar<l> operator * (ComplexD lhs,const iScalar<l>& rhs) { return rhs*lhs; }
2015-04-18 18:54:30 +01:00
2015-05-15 11:40:59 +01:00
template<class l,int N> strong_inline iVector<l,N> operator * (const iVector<l,N>& lhs,ComplexD rhs)
2015-04-18 18:54:30 +01:00
{
typename iScalar<l>::scalar_type t;t=rhs;
typename iScalar<l>::tensor_reduced srhs;srhs=t;
2015-04-18 18:54:30 +01:00
return lhs*srhs;
}
2015-05-15 11:40:59 +01:00
template<class l,int N> strong_inline iVector<l,N> operator * (ComplexD lhs,const iVector<l,N>& rhs) { return rhs*lhs; }
2015-04-18 18:54:30 +01:00
2015-05-15 11:40:59 +01:00
template<class l,int N> strong_inline iMatrix<l,N> operator * (const iMatrix<l,N>& lhs,ComplexD rhs)
2015-04-18 18:54:30 +01:00
{
typename iScalar<l>::scalar_type t;t=rhs;
typename iScalar<l>::tensor_reduced srhs;srhs=t;
2015-04-18 18:54:30 +01:00
return lhs*srhs;
}
2015-05-15 11:40:59 +01:00
template<class l,int N> strong_inline iMatrix<l,N> operator * (ComplexD lhs,const iMatrix<l,N>& rhs) { return rhs*lhs; }
2015-04-18 18:54:30 +01:00
////////////////////////////////////////////////////////////////////
// Integer support; cast to "scalar_type" through constructor
////////////////////////////////////////////////////////////////////
2015-05-15 11:40:59 +01:00
template<class l> strong_inline iScalar<l> operator * (const iScalar<l>& lhs,Integer rhs)
2015-04-18 18:54:30 +01:00
{
typename iScalar<l>::scalar_type t; t=rhs;
typename iScalar<l>::tensor_reduced srhs; srhs=t;
2015-04-18 18:54:30 +01:00
return lhs*srhs;
}
2015-05-15 11:40:59 +01:00
template<class l> strong_inline iScalar<l> operator * (Integer lhs,const iScalar<l>& rhs) { return rhs*lhs; }
2015-04-18 18:54:30 +01:00
2015-05-15 11:40:59 +01:00
template<class l,int N> strong_inline iVector<l,N> operator * (const iVector<l,N>& lhs,Integer rhs)
2015-04-18 18:54:30 +01:00
{
typename iScalar<l>::scalar_type t;t=rhs;
typename iScalar<l>::tensor_reduced srhs;srhs=t;
2015-04-18 18:54:30 +01:00
return lhs*srhs;
}
2015-05-15 11:40:59 +01:00
template<class l,int N> strong_inline iVector<l,N> operator * (Integer lhs,const iVector<l,N>& rhs) { return rhs*lhs; }
2015-04-18 18:54:30 +01:00
2015-05-15 11:40:59 +01:00
template<class l,int N> strong_inline iMatrix<l,N> operator * (const iMatrix<l,N>& lhs,Integer rhs)
2015-04-18 18:54:30 +01:00
{
typename iScalar<l>::scalar_type t;t=rhs;
typename iScalar<l>::tensor_reduced srhs;srhs=t;
2015-04-18 18:54:30 +01:00
return lhs*srhs;
}
2015-05-15 11:40:59 +01:00
template<class l,int N> strong_inline iMatrix<l,N> operator * (Integer lhs,const iMatrix<l,N>& rhs) { return rhs*lhs; }
2015-04-18 18:54:30 +01:00
///////////////////////////////////////////////////////////////////////////////////////////////
// addition by fundamental scalar type applies to matrix(down diag) and scalar
///////////////////////////////////////////////////////////////////////////////////////////////
2015-05-15 11:40:59 +01:00
template<class l,int N> strong_inline iScalar<l> operator + (const iScalar<l>& lhs,const typename iScalar<l>::scalar_type rhs)
2015-04-18 18:54:30 +01:00
{
typename iScalar<l>::tensor_reduced srhs; srhs=rhs;
2015-04-18 18:54:30 +01:00
return lhs+srhs;
}
2015-05-15 11:40:59 +01:00
template<class l,int N> strong_inline iScalar<l> operator + (const typename iScalar<l>::scalar_type lhs,const iScalar<l>& rhs) { return rhs+lhs; }
2015-04-18 18:54:30 +01:00
2015-05-15 11:40:59 +01:00
template<class l,int N> strong_inline iMatrix<l,N> operator + (const iMatrix<l,N>& lhs,const typename iScalar<l>::scalar_type rhs)
2015-04-18 18:54:30 +01:00
{
typename iMatrix<l,N>::tensor_reduced srhs; srhs=rhs;
2015-04-18 18:54:30 +01:00
return lhs+srhs;
}
2015-05-15 11:40:59 +01:00
template<class l,int N> strong_inline iMatrix<l,N> operator + (const typename iScalar<l>::scalar_type lhs,const iMatrix<l,N>& rhs) { return rhs+lhs; }
2015-04-18 18:54:30 +01:00
////////////////////////////////////////////////////////////////////
// Double support; cast to "scalar_type" through constructor
////////////////////////////////////////////////////////////////////
2015-05-15 11:40:59 +01:00
template<class l> strong_inline iScalar<l> operator + (const iScalar<l>& lhs,double rhs)
2015-04-18 18:54:30 +01:00
{
typename iScalar<l>::scalar_type t; t=rhs;
typename iScalar<l>::tensor_reduced srhs; srhs=t;
2015-04-18 18:54:30 +01:00
return lhs+srhs;
}
2015-05-15 11:40:59 +01:00
template<class l> strong_inline iScalar<l> operator + (double lhs,const iScalar<l>& rhs) { return rhs+lhs; }
2015-04-18 18:54:30 +01:00
2015-05-15 11:40:59 +01:00
template<class l,int N> strong_inline iMatrix<l,N> operator + (const iMatrix<l,N>& lhs,double rhs)
2015-04-18 18:54:30 +01:00
{
typename iScalar<l>::scalar_type t;t=rhs;
typename iScalar<l>::tensor_reduced srhs;srhs=t;
2015-04-18 18:54:30 +01:00
return lhs+srhs;
}
2015-05-15 11:40:59 +01:00
template<class l,int N> strong_inline iMatrix<l,N> operator + (double lhs,const iMatrix<l,N>& rhs) { return rhs+lhs; }
2015-04-18 18:54:30 +01:00
// Integer support cast to scalar type through constructor
2015-05-15 11:40:59 +01:00
template<class l> strong_inline iScalar<l> operator + (const iScalar<l>& lhs,Integer rhs)
2015-04-18 18:54:30 +01:00
{
typename iScalar<l>::scalar_type t; t=rhs;
typename iScalar<l>::tensor_reduced srhs; srhs=t;
2015-04-18 18:54:30 +01:00
return lhs+srhs;
}
2015-05-15 11:40:59 +01:00
template<class l> strong_inline iScalar<l> operator + (Integer lhs,const iScalar<l>& rhs) { return rhs+lhs; }
2015-04-18 18:54:30 +01:00
2015-05-15 11:40:59 +01:00
template<class l,int N> strong_inline iMatrix<l,N> operator + (const iMatrix<l,N>& lhs,Integer rhs)
2015-04-18 18:54:30 +01:00
{
typename iScalar<l>::scalar_type t;t=rhs;
typename iScalar<l>::tensor_reduced srhs;srhs=t;
2015-04-18 18:54:30 +01:00
return lhs+srhs;
}
2015-05-15 11:40:59 +01:00
template<class l,int N> strong_inline iMatrix<l,N> operator + (Integer lhs,const iMatrix<l,N>& rhs) { return rhs+lhs; }
2015-04-18 18:54:30 +01:00
///////////////////////////////////////////////////////////////////////////////////////////////
// subtraction of fundamental scalar type applies to matrix(down diag) and scalar
///////////////////////////////////////////////////////////////////////////////////////////////
2015-05-15 11:40:59 +01:00
template<class l,int N> strong_inline iScalar<l> operator - (const iScalar<l>& lhs,const typename iScalar<l>::scalar_type rhs)
2015-04-18 18:54:30 +01:00
{
typename iScalar<l>::tensor_reduced srhs; srhs=rhs;
2015-04-18 18:54:30 +01:00
return lhs-srhs;
}
2015-05-15 11:40:59 +01:00
template<class l,int N> strong_inline iScalar<l> operator - (const typename iScalar<l>::scalar_type lhs,const iScalar<l>& rhs)
2015-04-18 18:54:30 +01:00
{
typename iScalar<l>::tensor_reduced slhs;slhs=lhs;
2015-04-18 18:54:30 +01:00
return slhs-rhs;
}
2015-05-15 11:40:59 +01:00
template<class l,int N> strong_inline iMatrix<l,N> operator - (const iMatrix<l,N>& lhs,const typename iScalar<l>::scalar_type rhs)
2015-04-18 18:54:30 +01:00
{
typename iScalar<l>::tensor_reduced srhs; srhs=rhs;
2015-04-18 18:54:30 +01:00
return lhs-srhs;
}
2015-05-15 11:40:59 +01:00
template<class l,int N> strong_inline iMatrix<l,N> operator - (const typename iScalar<l>::scalar_type lhs,const iMatrix<l,N>& rhs)
2015-04-18 18:54:30 +01:00
{
typename iScalar<l>::tensor_reduced slhs;slhs=lhs;
2015-04-18 18:54:30 +01:00
return slhs-rhs;
}
////////////////////////////////////////////////////////////////////
// Double support; cast to "scalar_type" through constructor
////////////////////////////////////////////////////////////////////
2015-05-15 11:40:59 +01:00
template<class l> strong_inline iScalar<l> operator - (const iScalar<l>& lhs,double rhs)
2015-04-18 18:54:30 +01:00
{
typename iScalar<l>::scalar_type t; t=rhs;
typename iScalar<l>::tensor_reduced srhs; srhs=t;
2015-04-18 18:54:30 +01:00
return lhs-srhs;
}
2015-05-15 11:40:59 +01:00
template<class l> strong_inline iScalar<l> operator - (double lhs,const iScalar<l>& rhs)
2015-04-18 18:54:30 +01:00
{
typename iScalar<l>::scalar_type t(lhs);
typename iScalar<l>::tensor_reduced slhs;slhs=t;
2015-04-18 18:54:30 +01:00
return slhs-rhs;
}
2015-05-15 11:40:59 +01:00
template<class l,int N> strong_inline iMatrix<l,N> operator - (const iMatrix<l,N>& lhs,double rhs)
2015-04-18 18:54:30 +01:00
{
typename iScalar<l>::scalar_type t;t=rhs;
typename iScalar<l>::tensor_reduced srhs;srhs=t;
2015-04-18 18:54:30 +01:00
return lhs-srhs;
}
2015-05-15 11:40:59 +01:00
template<class l,int N> strong_inline iMatrix<l,N> operator - (double lhs,const iMatrix<l,N>& rhs)
2015-04-18 18:54:30 +01:00
{
typename iScalar<l>::scalar_type t(lhs);
typename iScalar<l>::tensor_reduced slhs;slhs=t;
2015-04-18 18:54:30 +01:00
return slhs-rhs;
}
////////////////////////////////////////////////////////////////////
// Integer support; cast to "scalar_type" through constructor
////////////////////////////////////////////////////////////////////
2015-05-15 11:40:59 +01:00
template<class l> strong_inline iScalar<l> operator - (const iScalar<l>& lhs,Integer rhs)
2015-04-18 18:54:30 +01:00
{
typename iScalar<l>::scalar_type t; t=rhs;
typename iScalar<l>::tensor_reduced srhs; srhs=t;
2015-04-18 18:54:30 +01:00
return lhs-srhs;
}
2015-05-15 11:40:59 +01:00
template<class l> strong_inline iScalar<l> operator - (Integer lhs,const iScalar<l>& rhs)
2015-04-18 18:54:30 +01:00
{
typename iScalar<l>::scalar_type t;t=lhs;
typename iScalar<l>::tensor_reduced slhs;slhs=t;
2015-04-18 18:54:30 +01:00
return slhs-rhs;
}
2015-05-15 11:40:59 +01:00
template<class l,int N> strong_inline iMatrix<l,N> operator - (const iMatrix<l,N>& lhs,Integer rhs)
2015-04-18 18:54:30 +01:00
{
typename iScalar<l>::scalar_type t;t=rhs;
typename iScalar<l>::tensor_reduced srhs;srhs=t;
2015-04-18 18:54:30 +01:00
return lhs-srhs;
}
2015-05-15 11:40:59 +01:00
template<class l,int N> strong_inline iMatrix<l,N> operator - (Integer lhs,const iMatrix<l,N>& rhs)
2015-04-18 18:54:30 +01:00
{
typename iScalar<l>::scalar_type t;t=lhs;
typename iScalar<l>::tensor_reduced slhs;slhs=t;
2015-04-18 18:54:30 +01:00
return slhs-rhs;
}
}
#endif