Skip to content
Merged
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
46 changes: 10 additions & 36 deletions test/amd/tensors.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Adapt, AMDGPU
using Test, TestExtras
using TensorKit, TensorKitSectors, Combinatorics
using TensorKit, Combinatorics
ad = adapt(Array)
const AMDGPUExt = Base.get_extension(TensorKit, :TensorKitAMDGPUExt)
@assert !isnothing(AMDGPUExt)
Expand Down Expand Up @@ -97,7 +97,7 @@ for V in spacelist
for T in (Int, Float32, ComplexF64)
t = @constinferred AMDGPU.rand(T, W)
d = convert(Dict, t)
@test adapt(Array, t) == convert(TensorMap, d)
@test convert(Dict, adapt(Array, t)) == d
Comment thread
lkdvos marked this conversation as resolved.
end
end
symmetricbraiding && @timedtestset "Basic linear algebra" begin
Expand Down Expand Up @@ -221,14 +221,14 @@ for V in spacelist
end
end
end
@timedtestset "Tensor conversion" begin # TODO adjoint conversion methods don't work yet
@timedtestset "Tensor conversion" begin
W = V1 ⊗ V2
t = @constinferred AMDGPU.randn(W ← W)
#@test typeof(convert(TensorMap, t')) == typeof(t) # TODO Adjoint not supported yet
@test typeof(convert(TensorMap, t')) == typeof(t)
tc = complex(t)
@test convert(typeof(tc), t) == tc
@test typeof(convert(typeof(tc), t)) == typeof(tc)
# @test typeof(convert(typeof(tc), t')) == typeof(tc) # TODO Adjoint not supported yet
@test typeof(convert(typeof(tc), t')) == typeof(tc)
@test Base.promote_typeof(t, tc) == typeof(tc)
@test Base.promote_typeof(tc, t) == typeof(tc + t)
end
Expand All @@ -241,33 +241,7 @@ for V in spacelist
@test LinearAlgebra.isdiag(D)
@test LinearAlgebra.diag(D) == d
end=#
symmetricbraiding && @timedtestset "Permutations: test via inner product invariance" begin
W = V1 ⊗ V2 ⊗ V3 ⊗ V4 ⊗ V5
t = AMDGPU.rand(ComplexF64, W)
t′ = AMDGPU.randn!(similar(t))
for k in 0:5
for p in permutations(1:5)
p1 = ntuple(n -> p[n], k)
p2 = ntuple(n -> p[k + n], 5 - k)
AMDGPU.@allowscalar begin
t2 = @constinferred permute(t, (p1, p2))
t2 = permute(t, (p1, p2))
@test norm(t2) ≈ norm(t)
t2′ = permute(t′, (p1, p2))
@test dot(t2′, t2) ≈ dot(t′, t) ≈ dot(transpose(t2′), transpose(t2))
end
end

AMDGPU.@allowscalar begin
t3 = @constinferred repartition(t, $k)
@test norm(t3) ≈ norm(t)
t3′ = @constinferred repartition!(similar(t3), t′)
@test norm(t3′) ≈ norm(t′)
@test dot(t′, t) ≈ dot(t3′, t3)
end
end
end
symmetricbraiding && @timedtestset "Permutations: test via CPU" begin
#=symmetricbraiding && @timedtestset "Permutations: test via CPU" begin
W = V1 ⊗ V2 ⊗ V3 ⊗ V4 ⊗ V5
t = AMDGPU.rand(ComplexF64, W)
for k in 0:5
Expand All @@ -276,12 +250,12 @@ for V in spacelist
p2 = ntuple(n -> p[k + n], 5 - k)
dt2 = AMDGPU.@allowscalar permute(t, (p1, p2))
ht2 = permute(adapt(Array, t), (p1, p2))
@test ht2 == adapt(Array, dt2)
@test ht2 adapt(Array, dt2)
end

dt3 = AMDGPU.@allowscalar repartition(t, k)
ht3 = repartition(adapt(Array, t), k)
@test ht3 == adapt(Array, dt3)
@test ht3 adapt(Array, dt3)
end
end
symmetricbraiding && @timedtestset "Full trace: test self-consistency" begin
Expand All @@ -303,7 +277,7 @@ for V in spacelist
end
@test ss ≈ s2
@test ss ≈ s3
end
end=# # TODO read only memory errors
#=symmetricbraiding && @timedtestset "Partial trace: test self-consistency" begin
t = AMDGPU.rand(ComplexF64, V1 ⊗ V2' ⊗ V3 ⊗ V2 ⊗ V1' ⊗ V3')
@tensor t2[a, b] := t[c, d, b, d, c, a]
Expand Down Expand Up @@ -397,7 +371,7 @@ for V in spacelist
end
@timedtestset "Multiplication and inverse: test compatibility" begin
W1 = V1 ⊗ V2 ⊗ V3
W2 = V4 ⊗ V5
W2 = (V4 ⊗ V5)'
for T in (Float64, ComplexF64)
t1 = AMDGPU.rand(T, W1, W1)
t2 = AMDGPU.rand(T, W2, W2)
Expand Down
Loading