Skip to content
Merged
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
7 changes: 6 additions & 1 deletion src/tensors/diagonal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,12 @@ function TO.tensoralloc(
V = only(domain(structure))
dim = reduceddim(V)
data = TO.tensoralloc(M, dim, istemp, allocator)
return DiagonalTensorMap{T, S, M}(data, V)
return DiagonalTensorMap{T, S, typeof(data)}(data, V)
end

function TO.tensorfree!(t::DiagonalTensorMap, allocator = TO.DefaultAllocator())
TO.tensorfree!(t.data, allocator)
return nothing
end

# Linear Algebra and factorizations
Expand Down
18 changes: 18 additions & 0 deletions test/tensors/diagonal.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Test, TestExtras
using TensorKit
using TensorOperations

diagspacelist = (
(ℂ^4)',
Expand Down Expand Up @@ -254,3 +255,20 @@ diagspacelist = (
end
TensorKit.empty_globalcaches!()
end

@testset "DiagonalTensor temporaries with $(nameof(typeof(allocator)))" for allocator in
(TensorOperations.DefaultAllocator(), TensorOperations.ManualAllocator(), TensorOperations.BufferAllocator())
for V in diagspacelist, T in (Float64, ComplexF64)
BraidingStyle(sectortype(V)) isa SymmetricBraiding || continue
d = tensoralloc(DiagonalTensorMap{T, spacetype(V), Vector{T}}, V ← V, Val(true), allocator)
@test d isa DiagonalTensorMap{T}
@test space(d) == (V ← V)
tensorfree!(d, allocator)

D1, D2, D3 = DiagonalTensorMap(rand(T, reduceddim(V)), V),
DiagonalTensorMap(rand(T, reduceddim(V)), V), DiagonalTensorMap(rand(T, reduceddim(V)), V)
@tensor C[a; b] := D1[a; c] * D2[c; d] * D3[d; b]
@tensor allocator = allocator C′[a; b] := D1[a; c] * D2[c; d] * D3[d; b]
@test C′ ≈ C
end
end
Loading