Skip to content

Commit 405b88b

Browse files
authored
Fix TSVD example from README and test it (#59)
1 parent ab96acb commit 405b88b

File tree

6 files changed

+25
-12
lines changed

6 files changed

+25
-12
lines changed

Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1313
DistributedArrays = "0.5, 0.6"
1414
MPI = "0.11"
1515
MPIClusterManagers = "0.1"
16+
TSVD = "0.4"
1617
julia = "1"
1718

1819
[extras]
1920
MPI = "da04e1cc-30fd-572f-bb4f-1f8673147195"
2021
MPIClusterManagers = "e7922434-ae4b-11e9-05c5-9780451d2c66"
2122
Primes = "27ebfcd6-29c5-5fa9-bf4b-fb8fc14df3ae"
2223
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
24+
TSVD = "9449cd9e-2762-5aa3-a617-5413e99d722e"
2325

2426
[targets]
25-
test = ["Test", "MPI", "MPIClusterManagers", "Primes"]
27+
test = ["Test", "MPI", "MPIClusterManagers", "Primes", "TSVD"]

README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,7 @@ julia> man = MPIManager(np = 4);
9393

9494
julia> addprocs(man);
9595

96-
julia> using Elemental
97-
98-
julia> Pkg.clone("TSVD")
99-
100-
julia> @everywhere using TSVD
96+
julia> @mpi_do man using Elemental, TSVD
10197

10298
julia> @mpi_do man A = Elemental.DistMatrix(Float64);
10399

src/blas_like/level1.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ for (elty, relty, ext) in ((:Float32, :Float32, :s),
5454
return rval[]
5555
end
5656

57-
function scale!(x::$mat{$elty}, val::Number)
57+
function LinearAlgebra.rmul!(x::$mat{$elty}, val::Number)
5858
ElError(ccall(($(string("ElScale", sym, ext)), libEl), Cuint,
5959
(Ptr{Cvoid}, $elty),
6060
x.obj, $elty(val)))

src/julia/generic.jl

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ LinearAlgebra.svdvals(A::ElementalMatrix, ctrl::SVDCtrl) = svdvals!(copy(A), ctr
8888
# return dest
8989
# end
9090

91-
function Base.copy!(dest::DistMatrix{T}, src::Base.AbstractVecOrMat) where {T}
91+
function Base.copyto!(dest::DistMatrix{T}, src::Base.AbstractVecOrMat) where {T}
9292
m, n = size(src, 1), size(src, 2)
9393
zeros!(dest, m, n)
9494
if MPI.commRank(comm(dest)) == 0
@@ -102,9 +102,9 @@ function Base.copy!(dest::DistMatrix{T}, src::Base.AbstractVecOrMat) where {T}
102102
return dest
103103
end
104104

105-
Base.copy!(dest::DistMatrix, src::ElementalMatrix) = _copy!(src, dest)
105+
Base.copyto!(dest::DistMatrix, src::ElementalMatrix) = _copy!(src, dest)
106106

107-
function Base.copy!(dest::Base.VecOrMat, src::DistMatrix{T}) where {T}
107+
function Base.copyto!(dest::Base.VecOrMat, src::DistMatrix{T}) where {T}
108108
m, n = size(src, 1), size(src, 2)
109109
if MPI.commRank(comm(src)) == 0
110110
for j = 1:n
@@ -177,7 +177,7 @@ function Base.convert(::Type{DistMatrix{T}}, A::DistMultiVec{T}) where {T}
177177
end
178178

179179
Base.convert(::Type{Array}, xd::DistMatrix{T}) where {T} =
180-
Base.copy!(Base.zeros(T, size(xd)), xd)
180+
Base.copyto!(Base.zeros(T, size(xd)), xd)
181181

182182
Base.Array(xd::DistMatrix) = convert(Array, xd)
183183

@@ -194,3 +194,11 @@ LinearAlgebra.cholesky!(A::Hermitian{<:Union{Real,Complex},<:ElementalMatrix}) =
194194
LinearAlgebra.cholesky(A::Hermitian{<:Union{Real,Complex},<:ElementalMatrix}) = cholesky!(copy(A))
195195

196196
LinearAlgebra.lu(A::ElementalMatrix) = _lu!(copy(A))
197+
198+
# Mixed multiplication with Julia Arrays
199+
(*)(A::DistMatrix{T}, B::StridedVecOrMat{T}) where {T} = A*convert(DistMatrix{T}, B)
200+
(*)(A::DistMultiVec{T}, B::StridedVecOrMat{T}) where {T} = convert(DistMatrix{T}, A)*convert(DistMatrix{T}, B)
201+
(*)(A::DistSparseMatrix{T}, B::StridedVecOrMat{T}) where {T} = A*convert(DistMultiVec{T}, B)
202+
(*)(A::Adjoint{T,DistMatrix{T}}, B::StridedVecOrMat{T}) where {T} = A*convert(DistMatrix{T}, B)
203+
(*)(A::Adjoint{T,DistMultiVec{T}}, B::Base.VecOrMat{T}) where {T} = convert(DistMatrix{T}, parent(A))'*convert(DistMatrix{T}, B)
204+
(*)(A::Adjoint{T,DistSparseMatrix{T}}, B::Base.VecOrMat{T}) where {T} = A*convert(DistMultiVec{T}, B)

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"]
6+
testfiles = ["lav.jl", "lavdense.jl", "matrix.jl", "distmatrix.jl", "props.jl", "generic.jl", "spectral.jl", "tsvd.jl"]
77
nfail = 0
88
@info "Running Elemental.jl tests"
99
for f in testfiles

test/tsvd.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
using Elemental, TSVD, LinearAlgebra
2+
3+
A = Elemental.DistMatrix(Float64)
4+
Elemental.gaussian!(A, 500, 200)
5+
vals_Elemental = tsvd(A, 5)[2]
6+
vals_LAPACK = svdvals(convert(Array, A))[1:5]
7+
@test vals_Elemental vals_LAPACK

0 commit comments

Comments
 (0)