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

OneHotMatrix does not support map #958

Closed
maleadt opened this issue Dec 5, 2019 · 3 comments · Fixed by #1619
Closed

OneHotMatrix does not support map #958

maleadt opened this issue Dec 5, 2019 · 3 comments · Fixed by #1619

Comments

@maleadt
Copy link
Collaborator

maleadt commented Dec 5, 2019

Ran into this when changing a constructor in CuArrays.jl as part of JuliaGPU/CuArrays.jl#530:

-CuArray{T,N}(xs::AbstractArray{S,N}) where {T,N,S} = CuArray{T,N}((x -> T(x)).(xs))
+CuArray{T,N}(xs::AbstractArray{S,N}) where {T,N,S} = CuArray{T,N}(map(T, xs))
1395   Got exception outside of a @test
1396   scalar getindex is disallowed
1397   Stacktrace:
1398    [1] error(::String) at ./error.jl:33
1399    [2] assertscalar(::String) at /builds/JuliaGPU/CuArrays.jl/.julia/packages/GPUArrays/0lvhc/src/indexing.jl:14
1400    [3] getindex at /builds/JuliaGPU/CuArrays.jl/.julia/packages/GPUArrays/0lvhc/src/indexing.jl:54 [inlined]
1401    [4] getindex at /builds/JuliaGPU/CuArrays.jl/.julia/dev/Flux/src/onehot.jl:23 [inlined]
1402    [5] _getindex at ./abstractarray.jl:1021 [inlined]
1403    [6] getindex at ./abstractarray.jl:981 [inlined]
1404    [7] iterate at ./abstractarray.jl:914 [inlined]
1405    [8] iterate at ./abstractarray.jl:912 [inlined]
1406    [9] iterate at ./generator.jl:44 [inlined]
1407    [10] _collect(::Flux.OneHotMatrix{CuArray{Flux.OneHotVector,1,Nothing}}, ::Base.Generator{Flux.OneHotMatrix{CuArray{Flux.OneHotVector,1,Nothing}},Type{Float32}}, ::Base.EltypeUnknown, ::Base.HasShape{2}) at ./array.jl:619
1408    [11] map at ./array.jl:548 [inlined]
1409    [12] CuArray{Float32,2,P} where P(::Flux.OneHotMatrix{CuArray{Flux.OneHotVector,1,Nothing}}) at /builds/JuliaGPU/CuArrays.jl/src/array.jl:179
1410    [13] Type at /builds/JuliaGPU/CuArrays.jl/src/array.jl:182 [inlined]
1411    [14] (::Flux.RNNCell{typeof(tanh),CuArray{Float32,2,Nothing},CuArray{Float32,1,Nothing}})(::CuArray{Float32,1,Nothing}, ::Flux.OneHotMatrix{CuArray{Flux.OneHotVector,1,Nothing}}) at /builds/JuliaGPU/CuArrays.jl/.julia/dev/Flux/src/cuda/curnn.jl:45
1412    [15] (::Flux.Recur{Flux.RNNCell{typeof(tanh),CuArray{Float32,2,Nothing},CuArray{Float32,1,Nothing}}})(::Flux.OneHotMatrix{CuArray{Flux.OneHotVector,1,Nothing}}) at /builds/JuliaGPU/CuArrays.jl/.julia/dev/Flux/src/layers/recurrent.jl:36
1413    [16] top-level scope at /builds/JuliaGPU/CuArrays.jl/.julia/dev/Flux/test/cuda/curnn.jl:59
1414    [17] top-level scope at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.2/Test/src/Test.jl:1186
1415    [18] top-level scope at /builds/JuliaGPU/CuArrays.jl/.julia/dev/Flux/test/cuda/curnn.jl:14
1416    [19] top-level scope at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.2/Test/src/Test.jl:1113
1417    [20] top-level scope at /builds/JuliaGPU/CuArrays.jl/.julia/dev/Flux/test/cuda/curnn.jl:14

Or

julia> x = Flux.OneHotMatrix{CuVector{Flux.OneHotVector}}(1, CuVector([Flux.OneHotVector(1,1)]));

julia> map(identity, x)
ERROR: scalar getindex is disallowed
 [13] top-level scope at REPL[12]:1

julia> broadcast(identity, x)
1×1 CuArray{Bool,2,Nothing}:
 1
maleadt added a commit to JuliaGPU/CuArrays.jl that referenced this issue Dec 5, 2019
@MikeInnes
Copy link
Member

We specifically force OneHotMatrix{CuArray} to use the CuArrays broadcasting kernel; presumably we need an overload for map to do the same.

IIRC that line was also written that way because we couldn't use types as CUDA kernel arguments, but I guess that's fixed by now.

@ToucheSir
Copy link
Member

Now that the new OneHotArray implementation has landed, thoughts on how this should be handled? Could map forward to broadcast, or is there more subtlety involved?

@darsnack
Copy link
Member

I think that Base.map(f, x::OneHotLike) = broadcast(f, x) should work.

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 a pull request may close this issue.

4 participants