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

Add hcat() for tracked arrays #194

Closed
wants to merge 1 commit into from

Conversation

staticfloat
Copy link
Contributor

No description provided.

@staticfloat
Copy link
Contributor Author

@MikeInnes Hmmm, I just added a failing test case. It looks like @back() isn't working like I expect here:

  Expression: gradtest(hcat, rand(5), rand(5), rand(5, 2))
  DimensionMismatch("cannot broadcast array to have fewer dimensions")
  Stacktrace:
   [1] check_broadcast_shape(::Tuple{Base.OneTo{Int64}}, ::Tuple{Base.OneTo{Int64},Base.OneTo{Int64}}) at ./broadcast.jl:84
   [2] broadcast_c! at ./broadcast.jl:210 [inlined]
   [3] broadcast! at ./broadcast.jl:206 [inlined]
   [4] accum!(::Array{Float64,1}, ::Array{Float64,2}) at /home/sabae/.julia/v0.6/Flux/src/tracker/back.jl:29
   [5] back(::Flux.Tracker.Tracked{Array{Float64,1}}, ::Array{Float64,2}) at /home/sabae/.julia/v0.6/Flux/src/tracker/back.jl:32
   [6] back(::TrackedArray{…,Array{Float64,1}}, ::Array{Float64,2}) at /home/sabae/.julia/v0.6/Flux/src/tracker/back.jl:43
   [7] macro expansion at /home/sabae/.julia/v0.6/Flux/src/tracker/back.jl:49 [inlined]
   [8] back(::Base.#hcat, ::Array{Float64,2}, ::TrackedArray{…,Array{Float64,1}}, ::TrackedArray{…,Array{Float64,1}}, ::TrackedArray{…,Array{Float64,2}}) at /home/sabae/.julia/v0.6/Flux/src/tracker/array.jl:127
   [9] back_(::Flux.Tracker.Call{Base.#hcat,Tuple{TrackedArray{…,Array{Float64,1}},TrackedArray{…,Array{Float64,1}},TrackedArray{…,Array{Float64,2}}}}, ::Array{Float64,2}, ::Array{Float64,2}) at /home/sabae/.julia/v0.6/Flux/src/tracker/back.jl:25
   [10] back(::Flux.Tracker.Tracked{Array{Float64,2}}, ::Array{Float64,2}) at /home/sabae/.julia/v0.6/Flux/src/tracker/back.jl:38
   [11] macro expansion at /home/sabae/.julia/v0.6/Flux/src/tracker/back.jl:49 [inlined]
   [12] (::Flux.Tracker.##48#50)(::TrackedArray{…,Array{Float64,2}}, ::Array{Float64,2}) at /home/sabae/.julia/v0.6/Flux/src/tracker/array.jl:325
   [13] foreach(::Function, ::Tuple{TrackedArray{…,Array{Float64,2}}}, ::Tuple{Array{Float64,2}}, ::Vararg{Tuple{Array{Float64,2}},N} where N) at ./abstractarray.jl:1734
   [14] back_(::Flux.Tracker.Call{Flux.Tracker.Broadcasted{Base.#sin,Array{ForwardDiff.Dual{Void,Float64,1},2}},Tuple{TrackedArray{…,Array{Float64,2}}}}, ::Array{Float64,2}, ::Array{Float64,2}) at /home/sabae/.julia/v0.6/Flux/src/tracker/back.jl:25r
   [15] back(::Flux.Tracker.Tracked{Array{Float64,2}}, ::Array{Float64,2}) at /home/sabae/.julia/v0.6/Flux/src/tracker/back.jl:38
   [16] back(::Base.#sum, ::Float64, ::TrackedArray{…,Array{Float64,2}}) at /home/sabae/.julia/v0.6/Flux/src/tracker/array.jl:164
   [17] back_(::Flux.Tracker.Call{Base.#sum,Tuple{TrackedArray{…,Array{Float64,2}}}}, ::Float64, ::Float64) at /home/sabae/.julia/v0.6/Flux/src/tracker/back.jl:25
   [18] back(::Flux.Tracker.Tracked{Float64}, ::Int64) at /home/sabae/.julia/v0.6/Flux/src/tracker/back.jl:36
   [19] back!(::Flux.Tracker.TrackedReal{Float64}) at /home/sabae/.julia/v0.6/Flux/src/tracker/scalar.jl:11
   [20] gradient(::Function, ::Array{Float64,1}, ::Vararg{AbstractArray,N} where N) at /home/sabae/.julia/v0.6/Flux/src/tracker/numeric.jl:3
   [21] gradcheck(::Function, ::Array{Float64,1}, ::Vararg{Any,N} where N) at /home/sabae/.julia/v0.6/Flux/src/tracker/numeric.jl:22
   [22] macro expansion at /home/sabae/.julia/v0.6/Flux/test/tracker.jl:33 [inlined]
   [23] macro expansion at ./test.jl:860 [inlined]
   [24] anonymous at ./<missing>:?

@staticfloat
Copy link
Contributor Author

@MikeInnes I fixed this; just needed some index fiddling to get x .+= Δ to work when the operation had expanded the number of dimensions of Δ.

@MikeInnes MikeInnes force-pushed the master branch 4 times, most recently from 027a922 to 5cc6813 Compare April 15, 2018 14:07
@MikeInnes MikeInnes mentioned this pull request May 1, 2018
gustafsson added a commit to gustafsson/Flux.jl that referenced this pull request May 2, 2018
Co-authored-by: Elliot Saba <staticfloat@gmail.com>
gustafsson added a commit to gustafsson/Flux.jl that referenced this pull request May 2, 2018
Co-authored-by: Elliot Saba <staticfloat@gmail.com>
@MikeInnes
Copy link
Member

Merged with #243 -- thanks 👍

@MikeInnes MikeInnes closed this May 7, 2018
MikeInnes pushed a commit that referenced this pull request Jun 20, 2018
Co-authored-by: Elliot Saba <staticfloat@gmail.com>
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