Skip to content

Commit

Permalink
fix tensoralloc to support other allocators
Browse files Browse the repository at this point in the history
  • Loading branch information
Jutho committed Nov 1, 2024
1 parent 2abebc6 commit c2a44bd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
3 changes: 2 additions & 1 deletion src/tensors/tensoroperations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ function TO.tensoralloc(::Type{TT},
A = storagetype(TT)
dim = fusionblockstructure(structure).totaldim
data = TO.tensoralloc(A, dim, istemp, allocator)
return TT(data, structure)
# return TT(data, structure)
return TensorMap{T}(data, structure)
end

function TO.tensorfree!(t::TensorMap, allocator=TO.DefaultAllocator())
Expand Down
42 changes: 25 additions & 17 deletions test/planar.jl
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,14 @@ end
GL′ = force_planar(GL)
GR′ = force_planar(GR)

@tensor y[-1 -2; -3] := GL[-1 2; 1] * x[1 3; 4] * O[2 -2; 3 5] * GR[4 5; -3]
@planar y′[-1 -2; -3] := GL′[-1 2; 1] * x′[1 3; 4] * O′[2 -2; 3 5] * GR′[4 5; -3]
@test force_planar(y) y′
for alloc in
(TensorOperations.DefaultAllocator(), TensorOperations.ManualAllocator())
@tensor allocator = alloc y[-1 -2; -3] := GL[-1 2; 1] * x[1 3; 4] *
O[2 -2; 3 5] * GR[4 5; -3]
@planar allocator = alloc y′[-1 -2; -3] := GL′[-1 2; 1] * x′[1 3; 4] *
O′[2 -2; 3 5] * GR′[4 5; -3]
@test force_planar(y) y′
end

# ∂AC2
# -------
Expand Down Expand Up @@ -193,21 +198,24 @@ end
ρ′ = force_planar(ρ)
h′ = force_planar(h)

@tensor begin
C = (((((((h[9 3 4; 5 1 2] * u[1 2; 7 12]) * conj(u[3 4; 11 13])) *
(u[8 5; 15 6] * w[6 7; 19])) *
(conj(u[8 9; 17 10]) * conj(w[10 11; 22]))) *
((w[12 14; 20] * conj(w[13 14; 23])) * ρ[18 19 20; 21 22 23])) *
w[16 15; 18]) * conj(w[16 17; 21]))
end
@planar begin
C′ = (((((((h′[9 3 4; 5 1 2] * u′[1 2; 7 12]) * conj(u′[3 4; 11 13])) *
(u′[8 5; 15 6] * w′[6 7; 19])) *
(conj(u′[8 9; 17 10]) * conj(w′[10 11; 22]))) *
((w′[12 14; 20] * conj(w′[13 14; 23])) * ρ′[18 19 20; 21 22 23])) *
w′[16 15; 18]) * conj(w′[16 17; 21]))
for alloc in
(TensorOperations.DefaultAllocator(), TensorOperations.ManualAllocator())
@tensor allocator = alloc begin
C = (((((((h[9 3 4; 5 1 2] * u[1 2; 7 12]) * conj(u[3 4; 11 13])) *
(u[8 5; 15 6] * w[6 7; 19])) *
(conj(u[8 9; 17 10]) * conj(w[10 11; 22]))) *
((w[12 14; 20] * conj(w[13 14; 23])) * ρ[18 19 20; 21 22 23])) *
w[16 15; 18]) * conj(w[16 17; 21]))
end
@planar allocator = alloc begin
C′ = (((((((h′[9 3 4; 5 1 2] * u′[1 2; 7 12]) * conj(u′[3 4; 11 13])) *
(u′[8 5; 15 6] * w′[6 7; 19])) *
(conj(u′[8 9; 17 10]) * conj(w′[10 11; 22]))) *
((w′[12 14; 20] * conj(w′[13 14; 23])) * ρ′[18 19 20; 21 22 23])) *
w′[16 15; 18]) * conj(w′[16 17; 21]))
end
@test C C′
end
@test C C′
end

@testset "Issue 93" begin
Expand Down

0 comments on commit c2a44bd

Please sign in to comment.