Skip to content

Commit

Permalink
Remove NTuple from unbroadcast (#661)
Browse files Browse the repository at this point in the history
* remove NTuple

* spaces

Co-authored-by: Frames Catherine White <[email protected]>

Co-authored-by: Frames Catherine White <[email protected]>
  • Loading branch information
mcabbott and oxinabox authored Aug 15, 2022
1 parent 63cc4e0 commit fef6aa8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
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 = "1.44.1"
version = "1.44.2"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
4 changes: 2 additions & 2 deletions src/rulesets/Base/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -328,13 +328,13 @@ end
unbroadcast(x::Base.AbstractArrayOrBroadcasted, dx::AbstractZero) = dx

function unbroadcast(x::T, dx) where {T<:Tuple{Vararg{Any,N}}} where {N}
val = if length(x) == length(dx)
val = if N == length(dx)
dx
else
sum(dx; dims=2:ndims(dx))
end
eltype(val) <: AbstractZero && return NoTangent()
return ProjectTo(x)(NTuple{length(x)}(val)) # Tangent
return ProjectTo(x)(Tuple{Vararg{Any,N}}(val)) # Tangent
end
unbroadcast(x::Tuple, dx::AbstractZero) = dx

Expand Down
4 changes: 4 additions & 0 deletions test/rulesets/Base/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,8 @@ BT1 = Broadcast.BroadcastStyle(Tuple)
test_rrule(copybroadcasted, complex, rand())
end
end

@testset "bugs" begin
@test ChainRules.unbroadcast((1, 2, [3]), [4, 5, [6]]) isa Tangent # earlier, NTuple demanded same type
end
end

2 comments on commit fef6aa8

@mcabbott
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/66289

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 v1.44.2 -m "<description of version>" fef6aa821e871db5df11061312ba02929b7fa16d
git push origin v1.44.2

Please sign in to comment.