Skip to content

Commit 620587d

Browse files
committed
define real and imag
1 parent 3e9ee17 commit 620587d

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/fusiontensor/base_interface.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,20 @@ function Base.getindex(ft::FusionTensor, f1::SectorFusionTree, f2::SectorFusionT
7373
return reshape(charge_matrix, charge_block_size(ft, f1, f2))
7474
end
7575

76+
Base.imag(ft::FusionTensor{<:Real}) = ft # same object
77+
Base.imag(ft::FusionTensor) = set_data_matrix(ft, imag(data_matrix(ft)))
78+
79+
Base.permutedims(ft::FusionTensor, args...) = fusiontensor_permutedims(ft, args...)
80+
81+
Base.real(ft::FusionTensor{<:Real}) = ft # same object
82+
Base.real(ft::FusionTensor) = set_data_matrix(ft, real(data_matrix(ft)))
83+
7684
function Base.setindex!(
7785
ft::FusionTensor, a::AbstractArray, f1::SectorFusionTree, f2::SectorFusionTree
7886
)
7987
return view(ft, f1, f2) .= a
8088
end
8189

82-
Base.permutedims(ft::FusionTensor, args...) = fusiontensor_permutedims(ft, args...)
83-
8490
function Base.similar(ft::FusionTensor, T::Type)
8591
# reuse trees_block_mapping
8692

test/test_basics.jl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,16 +238,24 @@ end
238238
@test isnothing(check_sanity(ft4))
239239
@test eltype(ft4) == Float64
240240

241-
ft5 = 2.0im * ft3
241+
ft5 = (1.0 + 2.0im) * ft3
242242
@test codomain_axes(ft5) === codomain_axes(ft3)
243243
@test domain_axes(ft5) === domain_axes(ft3)
244244
@test space_isequal(codomain_axis(ft5), codomain_axis(ft3))
245245
@test space_isequal(domain_axis(ft5), domain_axis(ft3))
246246
@test isnothing(check_sanity(ft4))
247247
@test eltype(ft5) == ComplexF64
248248

249-
ft4 = conj(ft3)
250-
@test ft4 === ft3 # same object
249+
@test conj(ft3) === ft3 # same object
250+
@test real(ft3) === ft3
251+
@test norm(imag(ft3)) == 0.0
252+
253+
@test conj(ft5) isa FusionTensor{ComplexF64,4}
254+
@test real(ft5) isa FusionTensor{Float64,4}
255+
@test imag(ft3) isa FusionTensor{Float64,4}
256+
@test conj(ft5) (1.0 - 2.0im) * ft3
257+
@test real(ft5) ft3
258+
@test imag(ft3) 2ft3
251259

252260
ft6 = conj(ft5)
253261
@test ft6 !== ft5 # different object

0 commit comments

Comments
 (0)