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
2 changes: 2 additions & 0 deletions src/tensors/sectorvector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ Base.similar(v::SectorVector, ::Type{T}, V::ElementarySpace) where {T} = SectorV

Base.copy(v::SectorVector) = SectorVector(copy(v.data), v.structure)

Adapt.adapt_structure(to, v::SectorVector) = SectorVector(Adapt.adapt(to, parent(v)), v.structure)

# AbstractDict interface
# ----------------------
Base.keytype(v::SectorVector) = keytype(typeof(v))
Expand Down
17 changes: 17 additions & 0 deletions test/amd/tensors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,23 @@ for V in spacelist
@test domain(t2) == one(W)
end
end
@timedtestset "Adapt SectorVector" begin
for T in (Float32, ComplexF64)
v = TensorKit.SectorVector{T}(undef, V1)
rand!(parent(v))
v_gpu = @constinferred adapt(ROCArray, v)
@test v_gpu isa TensorKit.SectorVector{T, I, <:ROCArray{T}}
@test v_gpu.structure == v.structure
v_cpu = @constinferred adapt(Array, v_gpu)
@test v_cpu isa TensorKit.SectorVector{T, I, Vector{T}}
@test parent(v_cpu) == parent(v)
t = AMDGPU.randn(T, V1 ⊗ V2 ← V3)
s = svd_vals(t)
s_cpu = adapt(Array, s)
@test parent(s_cpu) == collect(parent(s))
@test all(c -> block(s_cpu, c) == collect(block(s, c)), blocksectors(s))
end
end
@timedtestset "Tensor Dict conversion" begin
W = V1 ⊗ V2 ← (V3 ⊗ V4 ⊗ V5)'
for T in (Int, Float32, ComplexF64)
Expand Down
17 changes: 17 additions & 0 deletions test/cuda/tensors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,23 @@ for V in spacelist
@test storagetype(t_cpu) <: Array{T}
end
end
@timedtestset "Adapt SectorVector" begin
for T in (Float32, ComplexF64)
v = TensorKit.SectorVector{T}(undef, V1)
rand!(parent(v))
v_gpu = @constinferred adapt(CuArray, v)
@test v_gpu isa TensorKit.SectorVector{T, I, <:CuArray{T}}
@test v_gpu.structure == v.structure
v_cpu = @constinferred adapt(Array, v_gpu)
@test v_cpu isa TensorKit.SectorVector{T, I, Vector{T}}
@test parent(v_cpu) == parent(v)
t = CUDA.randn(T, V1 ⊗ V2 ← V3)
s = svd_vals(t)
s_cpu = adapt(Array, s)
@test parent(s_cpu) == collect(parent(s))
@test all(c -> block(s_cpu, c) == collect(block(s, c)), blocksectors(s))
end
end
@timedtestset "Tensor Dict conversion" begin
W = V1 ⊗ V2 ← (V3 ⊗ V4 ⊗ V5)'
for T in (Int, Float32, ComplexF64)
Expand Down
14 changes: 14 additions & 0 deletions test/tensors/sectorvector.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Test, TestExtras
using TensorKit
using TensorKit: SectorVector, diagonalblockstructure
using Adapt: adapt

spacelist = (
(ℂ^4)',
Expand Down Expand Up @@ -29,6 +30,19 @@ spacelist = (
@test length(v3) == reduceddim(V)
end

@timedtestset "Adapt ($T)" begin
v = SectorVector{T}(undef, V)
rand!(parent(v))
w = @testinferred adapt(Array, v)
@test w isa SectorVector{T, I, Vector{T}}
@test parent(w) == parent(v)
@test w.structure == v.structure
T′ = T <: Complex ? ComplexF64 : Float64
w′ = @testinferred adapt(Array{T′}, v)
@test w′ isa SectorVector{T′, I, Vector{T′}}
@test parent(w′) ≈ parent(v)
end

@timedtestset "AbstractVector interface ($T)" begin
v = SectorVector{T}(undef, V)
rand!(parent(v))
Expand Down
Loading