Skip to content

Commit b761b26

Browse files
authored
Merge pull request #144 from JuliaParallel/anj/axpy
Make axpy! work for arrays of arbitrary dimensionality
2 parents 3352d04 + 4a73cd0 commit b761b26

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

src/linalg.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,15 @@ const DMatrix{T,A} = DArray{T,2,A}
1919

2020
# Level 1
2121

22-
function axpy!(α, x::DVector, y::DVector)
22+
function axpy!(α, x::DArray, y::DArray)
2323
if length(x) != length(y)
2424
throw(DimensionMismatch("vectors must have same length"))
2525
end
26-
@sync for p in procs(y)
27-
@async remotecall_fetch(() -> (Base.axpy!(α, localpart(x), localpart(y)); nothing), p)
26+
asyncmap(procs(y)) do p
27+
@async remotecall_fetch(p) do
28+
Base.axpy!(α, localpart(x), localpart(y))
29+
return nothing
30+
end
2831
end
2932
return y
3033
end

test/darray.jl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -824,13 +824,15 @@ end
824824
check_leaks()
825825

826826
@testset "test axpy!" begin
827-
x = drandn(20)
828-
y = drandn(20)
827+
for (x, y) in ((drandn(20), drandn(20)),
828+
(drandn(20, 2), drandn(20, 2)))
829+
830+
@test Array(LinAlg.axpy!(2.0, x, copy(y))) LinAlg.axpy!(2.0, Array(x), Array(y))
831+
@test_throws DimensionMismatch LinAlg.axpy!(2.0, x, zeros(length(x) + 1))
832+
close(x)
833+
close(y)
834+
end
829835

830-
@test norm(convert(Array, LinAlg.axpy!(2.0, x, copy(y))) - LinAlg.axpy!(2.0, convert(Array, x), convert(Array, y))) < sqrt(eps())
831-
@test_throws DimensionMismatch LinAlg.axpy!(2.0, x, zeros(length(x) + 1))
832-
close(x)
833-
close(y)
834836
d_closeall() # close the temporaries created above
835837
end
836838

0 commit comments

Comments
 (0)