Skip to content
Merged
Changes from 1 commit
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
28 changes: 0 additions & 28 deletions src/lib/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -337,34 +337,6 @@ end
# LinearAlgebra
# =============

@adjoint function transpose(x)
back(Δ) = (transpose(Δ),)
back(Δ::NamedTuple{(:parent,)}) = (Δ.parent,)
return transpose(x), back
end

@adjoint function LinearAlgebra.Transpose(x)
back(Δ) = (LinearAlgebra.Transpose(Δ),)
back(Δ::NamedTuple{(:parent,)}) = (Δ.parent,)
return LinearAlgebra.Transpose(x), back
end


@adjoint function Base.adjoint(x)
back(Δ) = (Δ',)
back(Δ::NamedTuple{(:parent,)}) = (Δ.parent,)
return x', back
end

@adjoint function LinearAlgebra.Adjoint(x)
back(Δ) = (LinearAlgebra.Adjoint(Δ),)
back(Δ::NamedTuple{(:parent,)}) = (Δ.parent,)
return LinearAlgebra.Adjoint(x), back
end

@adjoint parent(x::LinearAlgebra.Adjoint) = parent(x), ȳ -> (LinearAlgebra.Adjoint(ȳ),)
@adjoint parent(x::LinearAlgebra.Transpose) = parent(x), ȳ -> (LinearAlgebra.Transpose(ȳ),)
Comment on lines 365 to 366
Copy link
Member Author

Choose a reason for hiding this comment

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

I forgot that JuliaDiff/ChainRulesCore.jl#446 isn't merged, so removing these lines probably isn't a good idea.

Before:

julia> gradient(x -> first(parent(x)), [1,2,3]')[1]
1×3 adjoint(::Vector{Float64}) with eltype Float64:
 1.0  0.0  0.0

This PR, with tagged CRC:

julia> gradient(x -> first(parent(x)), [1,2,3]')[1]
(parent = [1.0, 0.0, 0.0],)

Copy link
Member

Choose a reason for hiding this comment

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

One alternative idea is to desguar the @adjoint and overload _pullback directly. That'll have the benefit of removing some unnecessary layers, while making it easier to do stuff like FluxML/ZygoteRules.jl#22.

Copy link
Member Author

Choose a reason for hiding this comment

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

Glad to see there were tests for this, at least: fails on isapprox(::NamedTuple{(:parent,), ...}, ::Matrix{Float64}).


function _kron(mat1::AbstractMatrix,mat2::AbstractMatrix)
m1, n1 = size(mat1)
mat1_rsh = reshape(mat1,(1,m1,1,n1))
Expand Down