@@ -27,6 +27,10 @@ struct TensorMap{T,S<:IndexSpace,N₁,N₂,A<:DenseVector{T}} <: AbstractTensorM
2727 N₁,N₂,
2828 A<: DenseVector{T} }
2929 T ⊆ field (S) || @warn (" scalartype(data) = $T ⊈ $(field (S)) )" , maxlog = 1 )
30+ I = sectortype (S)
31+ T <: Real && ! (sectorscalartype (I) <: Real ) &&
32+ @warn (" Tensors with real data might be incompatible with sector type $I " ,
33+ maxlog = 1 )
3034 return new {T,S,N₁,N₂,A} (data, space)
3135 end
3236end
385389# -----------------------------
386390Base. copy (t:: TensorMap ) = typeof (t)(copy (t. data), t. space)
387391
388- function Base. complex (t:: AbstractTensorMap )
389- if scalartype (t) <: Complex
390- return t
391- else
392- return copy! (similar (t, complex (scalartype (t))), t)
393- end
394- end
395- function Base. complex (r:: AbstractTensorMap{<:Real} , i:: AbstractTensorMap{<:Real} )
396- return add (r, i, im * one (scalartype (i)))
397- end
398-
399392# Conversion between TensorMap and Dict, for read and write purpose
400393# ------------------------------------------------------------------
401394function Base. convert (:: Type{Dict} , t:: AbstractTensorMap )
@@ -578,29 +571,13 @@ function Base.show(io::IO, t::TensorMap)
578571 end
579572end
580573
581- # Real and imaginary parts
582- # ---------------------------
583- function Base. real (t:: AbstractTensorMap )
584- # `isreal` for a `Sector` returns true iff the F and R symbols are real. This guarantees
585- # that the real/imaginary part of a tensor `t` can be obtained by just taking
586- # real/imaginary part of the degeneracy data.
587- if isreal (sectortype (t))
588- return TensorMap (real (t. data), codomain (t), domain (t))
589- else
590- msg = " `real` has not been implemented for `$(typeof (t)) `."
591- throw (ArgumentError (msg))
592- end
593- end
594-
595- function Base. imag (t:: AbstractTensorMap )
596- # `isreal` for a `Sector` returns true iff the F and R symbols are real. This guarantees
597- # that the real/imaginary part of a tensor `t` can be obtained by just taking
598- # real/imaginary part of the degeneracy data.
599- if isreal (sectortype (t))
600- return TensorMap (imag (t. data), codomain (t), domain (t))
601- else
602- msg = " `imag` has not been implemented for `$(typeof (t)) `."
603- throw (ArgumentError (msg))
574+ # Complex, real and imaginary parts
575+ # -----------------------------------
576+ for f in (:real , :imag , :complex )
577+ @eval begin
578+ function Base. $f (t:: TensorMap )
579+ return TensorMap ($ f (t. data), space (t))
580+ end
604581 end
605582end
606583
0 commit comments