Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add vector_to_matrix function #637

Merged
merged 3 commits into from
Sep 23, 2022
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: 1 addition & 1 deletion .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ steps:
agents:
queue: "juliagpu"
rocm: "*"
rocmgpu: "gfx908"
rocmgpu: "*"
env:
JULIA_AMDGPU_CORE_MUST_LOAD: "1"
JULIA_AMDGPU_HIP_MUST_LOAD: "1"
Expand Down
1 change: 1 addition & 0 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,5 @@ Krylov.vec2str
Krylov.ktypeof
Krylov.kzeros
Krylov.kones
Krylov.vector_to_matrix
```
18 changes: 18 additions & 0 deletions src/krylov_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,24 @@ function ktypeof(v::S) where S <: SubArray
return ktypeof(v.parent)
end

"""
M = vector_to_matrix(S)

Return the dense matrix storage type `M` related to the dense vector storage type `S`.
"""
function vector_to_matrix(::Type{S}) where S <: DenseVector
V = hasproperty(S, :body) ? S.body : S
par = V.parameters
npar = length(par)
(2 ≤ npar ≤ 3) || error("Type $S is not supported.")
if npar == 2
M = V.name.wrapper{par[1], 2}
else
M = V.name.wrapper{par[1], 2, par[3]}
end
return M
end

"""
v = kzeros(S, n)

Expand Down
6 changes: 6 additions & 0 deletions test/gpu/amd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ include("../test_utils.jl")
# Krylov.@kref!(n, x, y, c, s)
# end

@testset "vector_to_matrix" begin
S = ROCVector{FC}
M = Krylov.vector_to_matrix(S)
@test M == ROCMatrix{FC}
end

ε = eps(T)
atol = √ε
rtol = √ε
Expand Down
6 changes: 6 additions & 0 deletions test/gpu/intel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ end
# Krylov.@kref!(n, x, y, c, s)
# end

@testset "vector_to_matrix" begin
S = oneVector{FC}
M = Krylov.vector_to_matrix(S)
@test M == oneMatrix{FC}
end

ε = eps(T)
atol = √ε
rtol = √ε
Expand Down
6 changes: 6 additions & 0 deletions test/gpu/metal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ end
# Krylov.@kref!(n, x, y, c, s)
# end

@testset "vector_to_matrix" begin
S = MtlVector{FC}
M = Krylov.vector_to_matrix(S)
@test M == MtlMatrix{FC}
end

ε = eps(T)
atol = √ε
rtol = √ε
Expand Down
8 changes: 6 additions & 2 deletions test/gpu/nvidia.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ using LinearOperators, Krylov, CUDA, CUDA.CUSPARSE, CUDA.CUSOLVER

include("../test_utils.jl")

include("../test_utils.jl")

@testset "Nvidia -- CUDA.jl" begin

@test CUDA.functional()
Expand Down Expand Up @@ -146,6 +144,12 @@ include("../test_utils.jl")
Krylov.@kref!(n, x, y, c, s)
end

@testset "vector_to_matrix" begin
S = CuVector{FC}
M = Krylov.vector_to_matrix(S)
@test M == CuMatrix{FC}
end

ε = eps(T)
atol = √ε
rtol = √ε
Expand Down
9 changes: 9 additions & 0 deletions test/test_aux.jl
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,15 @@
@test Krylov.ktypeof(b) == Vector{Float64}
end

@testset "vector_to_matrix" begin
# test vector_to_matrix
for FC in (Float32, Float64, ComplexF32, ComplexF64)
S = Vector{FC}
M = Krylov.vector_to_matrix(S)
@test M == Matrix{FC}
end
end

@testset "macros" begin
# test macros
for FC ∈ (Float16, Float32, Float64, ComplexF16, ComplexF32, ComplexF64)
Expand Down