Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/tensors/linalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,23 @@ function exp!(t::TensorMap)
domain(t) == codomain(t) ||
error("Exponential of a tensor only exist when domain == codomain.")
for (c, b) in blocks(t)
copy!(b, LinearAlgebra.exp!(b))
MatrixAlgebraKit.exponential!(b, b)
end
return t
end

function exp!((τ, t)::Tuple{Number, TensorMap})
domain(t) == codomain(t) ||
error("Exponential of a tensor only exist when domain == codomain.")
if eltype(t) <: Real && eltype(τ) <: Complex
t_complex = complex(t)
for ((cr, br), (cc, bc)) in zip(blocks(t), blocks(t_complex))
MatrixAlgebraKit.exponential!((τ, br), bc)
end
return t_complex
end
for (c, b) in blocks(t)
MatrixAlgebraKit.exponential!((τ, b), b)
end
return t
end
Expand Down
25 changes: 25 additions & 0 deletions test/tensors/exponential.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Test, TestExtras
using TensorKit
using Random

spaces = [ℂ^4, Vect[U1Irrep](0 => 1, 1 => 2), Vect[SU2Irrep](0 => 1, 1 // 2 => 1)]
scalartypes = [Float64, ComplexF64]

@timedtestset "exp!(τ,A) for $space, scalartype(A) = $st1, scalartype(τ) = $st2" for space in spaces, st1 in scalartypes, st2 in scalartypes
A = randn(st1, space, space)
τ = rand(st2)

@test exp!(copy(A)) == exp!((1.0, copy(A)))

A2 = exp!((τ, A))
if st1 <: Real && st2 <: Complex
@test objectid(A2) != objectid(A)
else
@test objectid(A2) == objectid(A)
end

expτA = exp!((τ, copy(A)))
expminτA = exp!((-τ, copy(A)))
@test expτA * expminτA ≈ id(scalartype(expτA), space)
@test expτA ≈ inv(expminτA)
end
Loading