Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
15 changes: 13 additions & 2 deletions src/rulesets/LinearAlgebra/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,21 @@ 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)
function pinv_pullback(Δy)
return full_pb(Δy)[1:2]
end

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am trying to remeber if there is a reason we don't do this:

Suggested change
function pinv_pullback(Δy)
return full_pb(Δy)[1:2]
end
pinv_pullback(Δy) = 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 +221,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
10 changes: 8 additions & 2 deletions src/rulesets/LinearAlgebra/factorization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,14 @@ end
#####
##### `cholesky`
#####

function rrule(::typeof(cholesky), A::Real, uplo::Symbol=:U)
function rrule(::typeof(cholesky), A::Real)
y, full_pb = rrule(cholesky, A, :U)
function cholesky_pullback(ΔC::Tangent)
return full_pb(ΔC)[1:2]
end
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