Skip to content

Commit 01b6cf5

Browse files
authored
Merge pull request #104 from JuliaParallel/vc/scale
add scale! for Vector and DMatrix
2 parents d68911b + 716a062 commit 01b6cf5

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/linalg.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,23 @@ function Ac_mul_B!(α::Number, A::DMatrix, x::AbstractVector, β::Number, y::DVe
165165
return y
166166
end
167167

168+
function Base.LinAlg.scale!(b::AbstractVector, DA::DMatrix)
169+
s = verified_destination_serializer(procs(DA), size(DA.indexes)) do pididx
170+
b[DA.indexes[pididx][1]]
171+
end
172+
map_localparts!(DA) do lDA
173+
scale!(localpart(s), lDA)
174+
end
175+
end
176+
177+
function Base.LinAlg.scale!(DA::DMatrix, b::AbstractVector)
178+
s = verified_destination_serializer(procs(DA), size(DA.indexes)) do pididx
179+
b[DA.indexes[pididx][2]]
180+
end
181+
map_localparts!(DA) do lDA
182+
scale!(lDA, localpart(s))
183+
end
184+
end
168185

169186
# Level 3
170187
function _matmatmul!::Number, A::DMatrix, B::AbstractMatrix, β::Number, C::DMatrix, tA)

test/darray.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,21 @@ end
198198

199199
check_leaks()
200200

201+
@testset "test scale!(b, A)" begin
202+
A = randn(100, 100)
203+
b = randn(100)
204+
DA = distribute(A)
205+
@test scale!(b, A) == scale!(b, DA)
206+
close(DA)
207+
A = randn(100, 100)
208+
b = randn(100)
209+
DA = distribute(A)
210+
@test scale!(A, b) == scale!(DA, b)
211+
close(DA)
212+
end
213+
214+
check_leaks()
215+
201216
@testset "test mapreduce on DArrays" begin
202217
for _ = 1:25, f = [x -> Int128(2x), x -> Int128(x^2), x -> Int128(x^2 + 2x - 1)], opt = [+, *]
203218
A = rand(1:5, rand(2:30))

0 commit comments

Comments
 (0)