Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "ChainRules"
uuid = "082447d4-558c-5d27-93f4-14fc19e9eca2"
version = "0.8.1"
version = "0.8.2"

[deps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Expand Down
13 changes: 11 additions & 2 deletions src/rulesets/LinearAlgebra/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,19 @@ function frule((_, ΔA), ::typeof(pinv), A::AbstractMatrix{T}; kwargs...) where
return Y, ∂Y
end

function rrule(
::typeof(pinv),
x::Union{AbstractVector{T}, LinearAlgebra.AdjOrTransAbsVec{T}},
) where {T<:Union{Real,Complex}}
y, full_pb = rrule(pinv, x, 0)
pinv_pullback(Δy) = return full_pb(Δy)[1:2]
return y, pinv_pullback
end

function rrule(
::typeof(pinv),
x::AbstractVector{T},
tol::Real = 0,
tol::Real,
) where {T<:Union{Real,Complex}}
y = pinv(x, tol)
function pinv_pullback(Δy)
Expand All @@ -210,7 +219,7 @@ end
function rrule(
::typeof(pinv),
x::LinearAlgebra.AdjOrTransAbsVec{T},
tol::Real = 0,
tol::Real,
) where {T<:Union{Real,Complex}}
y = pinv(x, tol)
function pinv_pullback(Δy)
Expand Down
8 changes: 6 additions & 2 deletions src/rulesets/LinearAlgebra/factorization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,12 @@ end
#####
##### `cholesky`
#####

function rrule(::typeof(cholesky), A::Real, uplo::Symbol=:U)
function rrule(::typeof(cholesky), A::Real)
C, full_pb = rrule(cholesky, A, :U)
cholesky_pullback(ΔC::Tangent) = return full_pb(ΔC)[1:2]
return C, cholesky_pullback
end
function rrule(::typeof(cholesky), A::Real, uplo::Symbol)
C = cholesky(A, uplo)
function cholesky_pullback(ΔC::Tangent)
return NoTangent(), ΔC.factors[1, 1] / (2 * C.U[1, 1]), NoTangent()
Expand Down
3 changes: 2 additions & 1 deletion test/rulesets/LinearAlgebra/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@

@testset "$F{Vector{$T}}" for T in (Float64, ComplexF64), F in (Transpose, Adjoint)
test_frule(pinv, F(randn(T, 3)) ⊢ F(randn(T, 3)))
test_rrule(pinv, F(randn(T, 3)))
check_inferred = VERSION ≥ v"1.5"
test_rrule(pinv, F(randn(T, 3)); check_inferred=check_inferred)

# Check types.
# TODO: Do we need this still?
Expand Down
3 changes: 2 additions & 1 deletion test/rulesets/LinearAlgebra/factorization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,8 @@ end
# also we might be missing some overloads for different tangent-types in the rules
@testset "cholesky" begin
@testset "Real" begin
test_rrule(cholesky, 0.8)
check_inferred = VERSION ≥ v"1.5"
test_rrule(cholesky, 0.8; check_inferred=check_inferred)
end
@testset "Diagonal{<:Real}" begin
D = Diagonal(rand(5) .+ 0.1)
Expand Down