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

Add rules for all Symmetric/Hermitian constructors #182

Merged
merged 24 commits into from
Jul 6, 2020

Conversation

sethaxen
Copy link
Member

@sethaxen sethaxen commented May 1, 2020

Fixes #178 by porting the rules from Zygote, along with the Hermitian rules (see https://github.com/FluxML/Zygote.jl/blob/0b3e32d5c0f8e5ef3b061a6f84ed5505f5a202a0/src/lib/array.jl#L454-L491).

Tests currently do not pass I think because ChainRulesTestUtils seems to interpret the :U variable as a variable of name U, which does not exist. We may also need FiniteDifference v0.10.0 for the complex tests.

@sethaxen
Copy link
Member Author

sethaxen commented May 2, 2020

I left out the Symmetric -> Matrix and Matrix -> Symmetric conversions at https://github.com/FluxML/Zygote.jl/blob/0b3e32d5c0f8e5ef3b061a6f84ed5505f5a202a0/src/lib/array.jl#L493-L496 but could add those as well. Has there been discussion on a generic rrule for such conversions? There were some in various Zygote issues but they didn't get very far.

@oxinabox
Copy link
Member

oxinabox commented May 4, 2020

Has there been discussion on a generic rrule for such conversions?

I don't think so, unless it is covered by #153, or #154
open an issue?

@sethaxen sethaxen closed this May 16, 2020
@sethaxen sethaxen reopened this May 16, 2020
@sethaxen sethaxen closed this May 16, 2020
@sethaxen sethaxen reopened this May 16, 2020
@sethaxen sethaxen closed this May 25, 2020
@sethaxen sethaxen reopened this May 25, 2020
@sethaxen
Copy link
Member Author

Blocked by #198

@sethaxen
Copy link
Member Author

Okay, this is ready for review. I also unified the constructors and also added frules and rules for conversion to a Matrix.

Since between this and #193 there's a disproportionately large amount of Symmetric and Hermitian code in structured.jl, I wonder if it's worth splitting that into its own symmetric.jl file, which would also mirror the file structure in LinearAlgebra.

@willtebbutt
Copy link
Member

I'll be reviewing tomorrow morning, please don't merge before then.

Copy link
Member

@willtebbutt willtebbutt left a comment

Choose a reason for hiding this comment

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

Broadly LGTM. A couple of suggestions, but I'm not going to hold up merging over them (but I would appreciate the line-length stuff in the tests being dealt with).

src/rulesets/LinearAlgebra/structured.jl Outdated Show resolved Hide resolved
src/rulesets/LinearAlgebra/utils.jl Outdated Show resolved Hide resolved
test/rulesets/LinearAlgebra/structured.jl Outdated Show resolved Hide resolved
test/rulesets/LinearAlgebra/structured.jl Outdated Show resolved Hide resolved
function rrule(T::Type{<:LinearAlgebra.HermOrSym}, A::AbstractMatrix, uplo)
Ω = T(A, uplo)
function HermOrSym_pullback(ΔΩ)
return (NO_FIELDS, @thunk(_symherm_back(T, ΔΩ, Ω.uplo)), DoesNotExist())
Copy link
Member

Choose a reason for hiding this comment

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

Do we need a thunk here? The cotangent w.r.t. A is the only meaningful, so I would imagine that it would always get used somewhere, but my intuition for this isn't great, perhaps yours is better.

Copy link
Member Author

Choose a reason for hiding this comment

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

Probably not? I had thought that the convention was to always thunk in reverse unless 1) there's only one cotangent (not counting the NO_FIELDS) or 2) sometimes for scalar functions (e.g. those made with @scalar_rule). I personally think modifying (1) to be "there's only one cotangent that a user could reasonably want" makes perfect sense.

Copy link
Member

Choose a reason for hiding this comment

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

@oxinabox do you agree? If so I'll open a PR to the docs to update guidance.

@willtebbutt
Copy link
Member

@sethaxen please feel free to merge this whenever. It's good to go IMO.

@sethaxen sethaxen changed the title Support uplo argument for Symmetric/ add rrule for Hermitian Add rules for all Symmetric/Hermitian constructors Jul 6, 2020
@sethaxen sethaxen merged commit eabdd74 into JuliaDiff:master Jul 6, 2020
@sethaxen sethaxen deleted the symherm branch July 6, 2020 00:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

handle uplo argument for Symmetric
4 participants