Skip to content

Commit

Permalink
Add rrules for triu/tril (#201)
Browse files Browse the repository at this point in the history
* Add rrules for triu/tril

* Add terminal newline

* Increment version number
  • Loading branch information
sethaxen authored May 25, 2020
1 parent 1e7063d commit 3a969a2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
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.6.2"
version = "0.6.3"

[deps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Expand Down
26 changes: 26 additions & 0 deletions src/rulesets/LinearAlgebra/structured.jl
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,29 @@ function rrule(::Type{<:LowerTriangular}, A::AbstractMatrix)
end
return LowerTriangular(A), LowerTriangular_pullback
end

function rrule(::typeof(triu), A::AbstractMatrix, k::Integer)
function triu_pullback(ȳ)
return (NO_FIELDS, @thunk(triu(ȳ, k)), DoesNotExist())
end
return triu(A, k), triu_pullback
end
function rrule(::typeof(triu), A::AbstractMatrix)
function triu_pullback(ȳ)
return (NO_FIELDS, @thunk triu(ȳ))
end
return triu(A), triu_pullback
end

function rrule(::typeof(tril), A::AbstractMatrix, k::Integer)
function tril_pullback(ȳ)
return (NO_FIELDS, @thunk(tril(ȳ, k)), DoesNotExist())
end
return tril(A, k), tril_pullback
end
function rrule(::typeof(tril), A::AbstractMatrix)
function tril_pullback(ȳ)
return (NO_FIELDS, @thunk tril(ȳ))
end
return tril(A), tril_pullback
end
7 changes: 7 additions & 0 deletions test/rulesets/LinearAlgebra/structured.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,11 @@
n = 5
rrule_test(T, T(randn(n, n)), (randn(n, n), randn(n, n)))
end
@testset "$Op" for Op in (triu, tril)
n = 7
rrule_test(Op, randn(n, n), (randn(n, n), randn(n, n)))
@testset "k=$k" for k in -2:2
rrule_test(Op, randn(n, n), (randn(n, n), randn(n, n)), (k, nothing))
end
end
end

4 comments on commit 3a969a2

@sethaxen
Copy link
Member Author

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/15386

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.6.3 -m "<description of version>" 3a969a2319a07f21ce29334659ef5609684562ce
git push origin v0.6.3

Also, note the warning: Version 0.6.3 skips over 0.6.2
This can be safely ignored. However, if you want to fix this you can do so. Call register() again after making the fix. This will update the Pull request.

@sethaxen
Copy link
Member Author

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request updated: JuliaRegistries/General/15386

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.6.3 -m "<description of version>" 3a969a2319a07f21ce29334659ef5609684562ce
git push origin v0.6.3

Please sign in to comment.