diff --git a/lib/tensors/Tensor_class.h b/lib/tensors/Tensor_class.h index 019e6fb1..7962517c 100644 --- a/lib/tensors/Tensor_class.h +++ b/lib/tensors/Tensor_class.h @@ -23,13 +23,17 @@ template class iScalar public: vtype _internal; - typedef typename GridTypeMapper::scalar_type scalar_type; + typedef typename GridTypeMapper::scalar_type scalar_type; typedef typename GridTypeMapper::vector_type vector_type; typedef typename GridTypeMapper::tensor_reduced tensor_reduced_v; typedef iScalar tensor_reduced; typedef typename GridTypeMapper::scalar_object recurse_scalar_object; typedef iScalar scalar_object; + // substitutes a real or complex version with same tensor structure + typedef iScalar::Complexified > Complexified; + typedef iScalar::Realified > Realified; + enum { TensorLevel = GridTypeMapper::TensorLevel + 1}; // Scalar no action @@ -86,9 +90,19 @@ public: strong_inline const vtype & operator ()(void) const { return _internal; } - - operator ComplexD () const { return(TensorRemove(_internal)); }; - operator RealD () const { return(real(TensorRemove(_internal))); } + + // Type casts meta programmed + template = 0,IfNotSimd = 0> + operator ComplexF () const { return(TensorRemove(_internal)); }; + template = 0,IfNotSimd = 0> + operator ComplexD () const { return(TensorRemove(_internal)); }; + template = 0,IfNotSimd = 0> + operator RealD () const { return(real(TensorRemove(_internal))); } + template = 0,IfNotSimd = 0> + operator RealD () const { return TensorRemove(_internal); } + template = 0,IfNotSimd = 0> + operator Integer () const { return Integer(TensorRemove(_internal)); } + // convert from a something to a scalar via constructor of something arg template::value, T>::type* = nullptr > strong_inline iScalar operator = (T arg) @@ -123,6 +137,10 @@ public: typedef iScalar tensor_reduced; typedef iVector scalar_object; + // substitutes a real or complex version with same tensor structure + typedef iVector::Complexified,N > Complexified; + typedef iVector::Realified,N > Realified; + template::value, T>::type* = nullptr > strong_inline auto operator = (T arg) -> iVector { zeroit(*this); @@ -211,6 +229,12 @@ public: typedef typename GridTypeMapper::vector_type vector_type; typedef typename GridTypeMapper::tensor_reduced tensor_reduced_v; typedef typename GridTypeMapper::scalar_object recurse_scalar_object; + + // substitutes a real or complex version with same tensor structure + typedef iMatrix::Complexified,N > Complexified; + typedef iMatrix::Realified,N > Realified; + + // Tensure removal typedef iScalar tensor_reduced; typedef iMatrix scalar_object;