From e936f5b80b901478d8723ebb25ed4177761e5df0 Mon Sep 17 00:00:00 2001 From: Peter Boyle Date: Fri, 13 Oct 2023 17:56:47 +0300 Subject: [PATCH] IfGridTensor shorthand --- Grid/tensors/Tensor_trace.h | 29 +++++++++++++++++++++++++++++ Grid/tensors/Tensor_traits.h | 9 ++++++--- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/Grid/tensors/Tensor_trace.h b/Grid/tensors/Tensor_trace.h index 6aa398f9..c73d0949 100644 --- a/Grid/tensors/Tensor_trace.h +++ b/Grid/tensors/Tensor_trace.h @@ -69,6 +69,35 @@ accelerator_inline auto trace(const iVector &arg) -> iVector = 0, IfNotGridTensor = 0> +accelerator_inline auto traceProduct( const S1 &arg1,const S2 &arg2) + -> decltype(arg1*arg2) +{ + return arg1*arg2; +} + +template +accelerator_inline auto traceProduct(const iMatrix &arg1,const iMatrix &arg2) -> iScalar +{ + iScalar ret; + zeroit(ret._internal); + for(int i=0;i +accelerator_inline auto traceProduct(const iScalar &arg1,const iScalar &arg2) -> iScalar +{ + iScalar ret; + ret._internal=traceProduct(arg1._internal,arg2._internal); + return ret; +} NAMESPACE_END(Grid); diff --git a/Grid/tensors/Tensor_traits.h b/Grid/tensors/Tensor_traits.h index 58fdc6ce..98bc3986 100644 --- a/Grid/tensors/Tensor_traits.h +++ b/Grid/tensors/Tensor_traits.h @@ -34,9 +34,12 @@ NAMESPACE_BEGIN(Grid); // These are the Grid tensors template struct isGridTensor : public std::false_type { static constexpr bool notvalue = true; }; - template struct isGridTensor> : public std::true_type { static constexpr bool notvalue = false; }; - template struct isGridTensor> : public std::true_type { static constexpr bool notvalue = false; }; - template struct isGridTensor> : public std::true_type { static constexpr bool notvalue = false; }; + template struct isGridTensor > : public std::true_type { static constexpr bool notvalue = false; }; + template struct isGridTensor >: public std::true_type { static constexpr bool notvalue = false; }; + template struct isGridTensor >: public std::true_type { static constexpr bool notvalue = false; }; + + template using IfGridTensor = Invoke::value, int> >; + template using IfNotGridTensor = Invoke::value, int> >; // Traits to identify scalars template struct isGridScalar : public std::false_type { static constexpr bool notvalue = true; };