Skip to content

Commit f2b0733

Browse files
authored
Add a generic fallback for rotate! and reflect! (#430)
1 parent 0a42771 commit f2b0733

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/host/linalg.jl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,34 @@ function Base.similar(A::Hermitian{<:Any,<:AbstractGPUArray}, ::Type{T}) where T
441441
return Hermitian(B, ifelse(A.uplo == 'U', :U, :L))
442442
end
443443

444+
## rotate
445+
446+
function LinearAlgebra.rotate!(x::AbstractGPUArray, y::AbstractGPUArray, c::Number, s::Number)
447+
gpu_call(x, y, c, s; name="rotate!") do ctx, x, y, c, s
448+
i = @linearidx x
449+
@inbounds xi = x[i]
450+
@inbounds yi = y[i]
451+
@inbounds x[i] = c * xi + s * yi
452+
@inbounds y[i] = -conj(s) * xi + c * yi
453+
return
454+
end
455+
return x, y
456+
end
457+
458+
## reflect
459+
460+
function LinearAlgebra.reflect!(x::AbstractGPUArray, y::AbstractGPUArray, c::Number, s::Number)
461+
gpu_call(x, y, c, s; name="reflect!") do ctx, x, y, c, s
462+
i = @linearidx x
463+
@inbounds xi = x[i]
464+
@inbounds yi = y[i]
465+
@inbounds x[i] = c * xi + s * yi
466+
@inbounds y[i] = conj(s) * xi - c * yi
467+
return
468+
end
469+
return x, y
470+
end
471+
444472
## dot
445473

446474
LinearAlgebra.dot(x::AbstractGPUArray, y::AbstractGPUArray) = mapreduce(dot, +, x, y)

test/testsuite/linalg.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,14 @@
230230
@test compare(dot, AT, rand(T,5), rand(T, 5))
231231
end
232232

233+
@testset "rotate!" for T in eltypes
234+
@test compare(rotate!, AT, rand(T,5), rand(T,5), Ref(rand(real(T))), Ref(rand(T)))
235+
end
236+
237+
@testset "reflect!" for T in eltypes
238+
@test compare(reflect!, AT, rand(T,5), rand(T,5), Ref(rand(real(T))), Ref(rand(T)))
239+
end
240+
233241
@testset "iszero and isone" for T in eltypes
234242
A = one(AT(rand(T, 2, 2)))
235243
@test isone(A)

0 commit comments

Comments
 (0)