Skip to content

Commit

Permalink
Add vector_to_matrix function
Browse files Browse the repository at this point in the history
  • Loading branch information
amontoison committed Sep 23, 2022
1 parent 212a266 commit 611b3c2
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 2 deletions.
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

0 comments on commit 611b3c2

Please sign in to comment.