Skip to content

Commit a260810

Browse files
authored
Fix serial SVD examples from README by update convert methods to (#60)
use recent Julia API. Add test.
1 parent 405b88b commit a260810

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

src/julia/generic.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,13 @@ function Base.convert(::Type{Matrix{T}}, A::Base.VecOrMat{T}) where {T}
122122
m, n = size(A, 1), size(A, 2)
123123
B = Matrix(T)
124124
resize!(B, m, n)
125-
Base.unsafe_copy!(pointer(B), pointer(A), m*n)
125+
Base.unsafe_copyto!(pointer(B), pointer(A), m*n)
126126
return B
127127
end
128128
function Base.convert(::Type{Base.Matrix{T}}, A::Matrix{T}) where {T}
129129
m, n = size(A)
130-
B = Base.Matrix{T}(m, n)
131-
Base.unsafe_copy!(pointer(B), pointer(A), m*n)
130+
B = Base.Matrix{T}(undef, m, n)
131+
Base.unsafe_copyto!(pointer(B), pointer(A), m*n)
132132
return B
133133
end
134134

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ using Test
33
function runtests_mpirun()
44
nprocs = min(4, Sys.CPU_THREADS)
55
testdir = dirname(@__FILE__)
6-
testfiles = ["lav.jl", "lavdense.jl", "matrix.jl", "distmatrix.jl", "props.jl", "generic.jl", "spectral.jl", "tsvd.jl"]
6+
testfiles = ["lav.jl", "lavdense.jl", "matrix.jl", "distmatrix.jl", "props.jl", "generic.jl", "spectral.jl", "tsvd.jl", "svd.jl"]
77
nfail = 0
88
@info "Running Elemental.jl tests"
99
for f in testfiles

test/svd.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using LinearAlgebra, Elemental, Test
2+
3+
m, n = 100, 80
4+
A = Elemental.Matrix(Float64)
5+
Elemental.gaussian!(A, m, n)
6+
U_Elemental, s_Elemental, V_Elemental = svd(A)
7+
U_LAPACK, s_LAPACK, V_LAPACK = svd(Matrix(A))
8+
@test abs.(Matrix(U_Elemental)'*U_LAPACK) Matrix(I, n, n)
9+
@test Matrix(s_Elemental) s_LAPACK
10+
@test abs.(Matrix(V_Elemental)'*V_LAPACK) Matrix(I, n, n)

0 commit comments

Comments
 (0)