File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed
Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -392,6 +392,9 @@ function Base.complex(t::AbstractTensorMap)
392392 return copy! (similar (t, complex (scalartype (t))), t)
393393 end
394394end
395+ function Base. complex (r:: AbstractTensorMap{<:Real} , i:: AbstractTensorMap{<:Real} )
396+ return add (r, i, im * one (scalartype (i)))
397+ end
395398
396399# Conversion between TensorMap and Dict, for read and write purpose
397400# ------------------------------------------------------------------
Original file line number Diff line number Diff line change @@ -185,8 +185,21 @@ for V in spacelist
185185 W = V1 ⊗ V2
186186 for T in (Float64, ComplexF64, ComplexF32)
187187 t = @constinferred randn (T, W, W)
188- @test real (convert (Array, t)) == convert (Array, @constinferred real (t))
189- @test imag (convert (Array, t)) == convert (Array, @constinferred imag (t))
188+
189+ tr = @constinferred real (t)
190+ @test scalartype (tr) <: Real
191+ @test real (convert (Array, t)) == convert (Array, tr)
192+
193+ ti = @constinferred imag (t)
194+ @test scalartype (ti) <: Real
195+ @test imag (convert (Array, t)) == convert (Array, ti)
196+
197+ tc = @inferred complex (t)
198+ @test scalartype (tc) <: Complex
199+ @test complex (convert (Array, t)) == convert (Array, tc)
200+
201+ tc2 = @inferred complex (tr, ti)
202+ @test tc2 ≈ tc
190203 end
191204 end
192205 end
You can’t perform that action at this time.
0 commit comments