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

fix prod with tuple arg #523

Merged
merged 2 commits into from
Feb 27, 2020
Merged

fix prod with tuple arg #523

merged 2 commits into from
Feb 27, 2020

Conversation

CarloLucibello
Copy link
Member

This fixes the following problem caused by a relaxation of the signature in #112

julia> gradient(x -> prod((1,2,3)), 1)
ERROR: MethodError: no method matching prod(::Tuple{Int64,Int64,Int64}; dims=Colon())
Closest candidates are:
  prod(::Tuple{Any,Vararg{Any,N} where N}) at tuple.jl:385 got unsupported keyword argument "dims"
  prod(::Any) at reduce.jl:448 got unsupported keyword argument "dims"
  prod(::Any, ::StaticArrays.StaticArray{#s160,T,N} where N where #s160<:Tuple; dims) where T at /home/carlo/.julia/packages/StaticArrays/1g9bq/src/mapreduce.jl:234
  ...
Stacktrace:
 [1] #adjoint#3920 at /home/carlo/.julia/packages/Zygote/XCgv1/src/lib/array.jl:220 [inlined]
 [2] adjoint at ./none:0 [inlined]
 [3] _pullback at /home/carlo/.julia/packages/ZygoteRules/6nssF/src/adjoint.jl:47 [inlined]
 [4] #17 at ./REPL[18]:1 [inlined]
 [5] _pullback(::Zygote.Context, ::var"#17#18", ::Int64) at /home/carlo/.julia/packages/Zygote/XCgv1/src/compiler/interface2.jl:?
 [6] _pullback(::Function, ::Int64) at /home/carlo/.julia/packages/Zygote/XCgv1/src/compiler/interface.jl:31
 [7] pullback(::Function, ::Int64) at /home/carlo/.julia/packages/Zygote/XCgv1/src/compiler/interface.jl:37
 [8] gradient(::Function, ::Int64, ::Vararg{Int64,N} where N) at /home/carlo/.julia/packages/Zygote/XCgv1/src/compiler/interface.jl:46
 [9] top-level scope at REPL[18]:1

@@ -83,6 +83,7 @@ end

@test gradtest(x -> prod(x, dims = (2, 3)), (3,4,5))
@test gradtest(x -> prod(x), (3,4))
@test gradient(x -> prod((1,2,3)), 1)[1] === nothing
Copy link
Member

Choose a reason for hiding this comment

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

The test should check for a valid gradient result

Suggested change
@test gradient(x -> prod((1,2,3)), 1)[1] === nothing
x = (1,2,3)
@test gradient(x -> prod(x), x)[1] == (6,3,2)

@CarloLucibello
Copy link
Member Author

bors r+

@bors
Copy link
Contributor

bors bot commented Feb 27, 2020

Build succeeded

@bors bors bot merged commit aaa5b01 into FluxML:master Feb 27, 2020
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.

2 participants