Skip to content

fix FillArrays 0.10 compat #157

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

Merged
merged 4 commits into from
Nov 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ julia = "1"

[extras]
DiffTests = "de460e47-3fe3-5279-bb4a-814414816d5d"
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["DiffTests", "Test"]
test = ["DiffTests", "FillArrays", "Test"]
6 changes: 3 additions & 3 deletions src/derivatives/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,17 @@ function get_implementation(bc, f, T, args)
end
function Base.copy(_bc::Broadcasted{TrackedStyle})
bc = remove_not_tracked(_bc)
flattened_bc = Broadcast.flatten(bc)
flattened_bc = Base.Broadcast.flatten(bc)
untracked_bc = broadcast_rebuild(bc)
flattened_untracked_bc = Broadcast.flatten(untracked_bc)
T = Core.Compiler.return_type(copy, Tuple{typeof(untracked_bc)})
f, args = flattened_untracked_bc.f, flattened_bc.args
f, args = flattened_bc.f, flattened_bc.args
implementation = get_implementation(_bc, f, T, args)
if implementation isa Val{:reversediff}
return ∇broadcast(f, args...)
elseif implementation isa Val{:tracker}
return tracker_∇broadcast(f, args...)
else
flattened_untracked_bc = Base.Broadcast.flatten(untracked_bc)
style, axes = getstyle(flattened_untracked_bc), flattened_bc.axes
return copy(Broadcasted{style, typeof(axes), typeof(f), typeof(args)}(f, args, axes))
end
Expand Down
13 changes: 13 additions & 0 deletions test/compat/CompatTests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module CompatTests

using FillArrays, ReverseDiff, Test

@test ReverseDiff.gradient(fill(2.0, 3)) do x
sum(abs2.(x .- Zeros(3)))
end == fill(4.0, 3)

@test ReverseDiff.gradient(fill(2.0, 3)) do x
sum(abs2.(x .- (1:3)))
end == [2, 0, -2]

end
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@ println("done (took $t seconds).")
println("running ConfigTests...")
t = @elapsed include(joinpath(TESTDIR, "api/ConfigTests.jl"))
println("done (took $t seconds).")

println("running CompatTests...")
t = @elapsed include(joinpath(TESTDIR, "compat/CompatTests.jl"))
println("done (took $t seconds).")