Skip to content

Commit 86cbb7e

Browse files
authored
Add generic implementation of axpby and axpy (#394)
1 parent 6e47ff5 commit 86cbb7e

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/host/linalg.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,3 +293,11 @@ function Base.similar(A::Hermitian{<:Any,<:AbstractGPUArray}, ::Type{T}) where T
293293
fill!(view(B, diagind(B)), 0)
294294
return Hermitian(B, ifelse(A.uplo == 'U', :U, :L))
295295
end
296+
297+
298+
## axp{b}y
299+
300+
LinearAlgebra.axpby!(alpha::Number, x::AbstractGPUArray,
301+
beta::Number, y::AbstractGPUArray) = y .= x.*alpha .+ y.*beta
302+
303+
LinearAlgebra.axpy!(alpha::Number, x::AbstractGPUArray, y::AbstractGPUArray) = y .+= x.*alpha

test/testsuite/linalg.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,14 @@
186186
@test compare(rmul!, AT, rand(T, a), Ref(rand(T)))
187187
@test compare(lmul!, AT, Ref(rand(T)), rand(T, b))
188188
end
189+
190+
@testset "axp{b}y" for T in eltypes
191+
alpha, beta = 0.5, 2.0
192+
x = T.([2,4,6])
193+
y = T.([3,4,5])
194+
@test axpby!(alpha,x,beta,y) T.([7,10,13])
195+
@test axpy!(alpha,x,y) T.([8,12,16])
196+
end
189197
end
190198

191199
@testsuite "linalg/mul!/vector-matrix" (AT, eltypes)->begin

0 commit comments

Comments
 (0)