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

Member access fails when SparseVector is used #69

Closed
marekdedic opened this issue Sep 25, 2017 · 3 comments
Closed

Member access fails when SparseVector is used #69

marekdedic opened this issue Sep 25, 2017 · 3 comments

Comments

@marekdedic
Copy link
Contributor

Hi, I got this error while trying to use sparse matrices and vectors with Flux.

julia> a = TrackedArray(sparse([1, 2, 3]))
Tracked 3-element SparseVector{Int64,Int64}:
 1
 2
 3

julia> a[2]
ERROR: MethodError: no method matching spzeros(::Type{Int64})
Closest candidates are:
  spzeros(::Type{T}, ::Integer) where T at sparse/sparsevector.jl:47
  spzeros(::Type{Tv}, ::Integer, ::Integer) where Tv at sparse/sparsematrix.jl:1375
  spzeros(::Type{Tv}, ::Type{Ti<:Integer}, ::Integer) where {Tv, Ti<:Integer} at sparse/sparsevector.jl:48
  ...
Stacktrace:
 [1] getindex(::TrackedArray{…,SparseVector{Int64,Int64}}, ::Int64) at /home/user/.julia/v0.6/Flux/src/tracker/lib.jl:9

From what I know, the problem is a call to similar with empty tuple as last parameter (in function toarray) - In Julia, there isn't such a thing as a 0-dimensional sparse array AFAIK.

Thank you

@marekdedic marekdedic changed the title Member Access fails when SparseVector is used Member access fails when SparseVector is used Sep 25, 2017
@MikeInnes
Copy link
Member

Yup, it fails for anything other than 1 or 2D:

x = sparse([1,2,3])
similar(x, ())

This seems like a Base bug to me -- similar should just return an Array if it can't do anything else.

You could solve it by monkey-patching similar(::SparseVector, ::Tuple{}).

@marekdedic
Copy link
Contributor Author

Agreed, opened JuliaLang/julia#23905.

@marekdedic
Copy link
Contributor Author

The issue JuliaLang/julia#23905 has been successfully resolved.

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

No branches or pull requests

2 participants