Skip to content

Commit

Permalink
Merge pull request #109 from glennmoy/gm/chainrules-bugfic
Browse files Browse the repository at this point in the history
Fix ChainRules Ambiguity Error
  • Loading branch information
mcabbott authored May 25, 2022
2 parents f172d7a + 3e7bcf5 commit 94dcb6d
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "AxisKeys"
uuid = "94b1ba4f-4ee9-5380-92f1-94cde586c3c5"
license = "MIT"
version = "0.2.2"
version = "0.2.3"

[deps]
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"
Expand Down
1 change: 1 addition & 0 deletions src/chainrules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ function ChainRulesCore.ProjectTo(x::KeyedArray)
end

(project::ProjectTo{KeyedArray})(dx) = wrapdims(project.data(parent(dx)), project.keys...)
(project::ProjectTo{KeyedArray})(dx::AbstractZero) = dx

_KeyedArray_pullback(ȳ, project) = (NoTangent(), project(ȳ))
_KeyedArray_pullback(ȳ::Tangent, project) = _KeyedArray_pullback(ȳ.data, project)
Expand Down
4 changes: 4 additions & 0 deletions test/_chainrules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@
p = ProjectTo(ka)
@test p(data) == ka

@test p(NoTangent()) == NoTangent()

data = rand(3, 4)
ka = wrapdims(data, a=1:3, b='a':'d')
p = ProjectTo(ka)
@test p(data) == ka

@test p(NoTangent()) == NoTangent()
end

@testset "KeyedVector" begin
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Test, AxisKeys, NamedDims
using Statistics, OffsetArrays, Tables, UniqueVectors, LazyStack
using ChainRulesCore: ProjectTo
using ChainRulesCore: ProjectTo, NoTangent
using ChainRulesTestUtils: test_rrule
using FiniteDifferences

Expand Down

2 comments on commit 94dcb6d

@mcabbott
Copy link
Owner 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/61039

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.2.3 -m "<description of version>" 94dcb6d3f7b8f7a16a10bfb8c6e5f3162b93b310
git push origin v0.2.3

Please sign in to comment.