Skip to content

Add correct storage_type for lazy wrapped GPU arrays (adjoint, transpose, Diagonal) #365

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 5 commits into from
Apr 9, 2025
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
5 changes: 5 additions & 0 deletions src/abstract.jl
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ storage_type(op::AbstractLinearOperator) = error("please implement storage_type
storage_type(op::LinearOperator) = typeof(op.Mv5)
storage_type(M::AbstractMatrix{T}) where {T} = Vector{T}

# Lazy wrappers
storage_type(op::Adjoint) = storage_type(parent(op))
storage_type(op::Transpose) = storage_type(parent(op))
storage_type(op::Diagonal) = typeof(parent(op))

"""
reset!(op)

Expand Down
5 changes: 5 additions & 0 deletions test/gpu/amdgpu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,10 @@ using LinearOperators, AMDGPU
y = M * v
@test y isa ROCArray{Float32}

@test LinearOperators.storage_type(A) == LinearOperators.storage_type(adjoint(A))
@test LinearOperators.storage_type(A) == LinearOperators.storage_type(transpose(A))
@test LinearOperators.storage_type(A) == LinearOperators.storage_type(adjoint(A))
@test LinearOperators.storage_type(Diagonal(v)) == typeof(v)

@testset "AMDGPU S kwarg" test_S_kwarg(arrayType = ROCArray)
end
6 changes: 6 additions & 0 deletions test/gpu/nvidia.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,11 @@ using LinearOperators, CUDA, CUDA.CUSPARSE, CUDA.CUSOLVER
v = CUDA.rand(35)
y = M * v
@test y isa CuVector{Float32}

@test LinearOperators.storage_type(A) == LinearOperators.storage_type(adjoint(A))
@test LinearOperators.storage_type(A) == LinearOperators.storage_type(transpose(A))
@test LinearOperators.storage_type(A) == LinearOperators.storage_type(adjoint(A))
@test LinearOperators.storage_type(Diagonal(v)) == typeof(v)

@testset "Nvidia S kwarg" test_S_kwarg(arrayType = CuArray)
end
Loading