Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for julia 1.9 #718

Merged
merged 4 commits into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/rulesets/Base/arraymath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -342,20 +342,24 @@ function rrule(::typeof(\), A::AbstractVecOrMat{<:Real}, B::AbstractVecOrMat{<:R
project_B = ProjectTo(B)

Y = A \ B
# Ever since https://github.com/JuliaLang/julia/pull/44358
# we need to use `pinv` rather than `/` to support both the cases of Y being scalar and array
# See also https://github.com/JuliaLang/julia/issues/28827 which would improve this
function backslash_pullback(ȳ)
Ȳ = unthunk(ȳ)
Ati = pinv(A')
∂A = @thunk begin
B̄ = A' \ Ȳ

B̄ = Ati * Ȳ
Ā = -B̄ * Y'
Ā = add!!(Ā, (B - A * Y) * B̄' / A')
Ā = add!!(Ā, A' \ Y * (Ȳ' - B̄'A))
Ā = add!!(Ā, ((B - A * Y) * B̄') * Ati)
Ā = add!!(Ā, Ati * Y * (Ȳ' - B̄'A))
project_A(Ā)
end
∂B = @thunk project_B(A' \ Ȳ)
∂B = @thunk project_B(Ati * Ȳ)
oxinabox marked this conversation as resolved.
Show resolved Hide resolved
return NoTangent(), ∂A, ∂B
end
return Y, backslash_pullback

end

#####
Expand Down
2 changes: 1 addition & 1 deletion test/rulesets/Base/arraymath.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@testset "arraymath.jl" begin
@testset "inv(::Matrix{$T})" for T in (Float64, ComplexF64)
B = generate_well_conditioned_matrix(T, 3)
if VERSION >= v"1.7"
if v"1.7" <= VERSION < v"1.9"
@gpu test_frule(inv, B)
@gpu test_rrule(inv, B)
else
Expand Down