JuliaArrays / FillArrays.jl

Julia package for lazily representing matrices filled with a single entry
https://juliaarrays.github.io/FillArrays.jl/
MIT License
181 stars 38 forks source link

Plots.jl somehow breaks FillArrays #13

Closed cstjean closed 6 years ago

cstjean commented 6 years ago

On 0.6,

julia> using Plots, FillArrays

julia> Zeros(3)
3-element FillArrays.Zeros{Float64,1}:
Error showing value of type FillArrays.Zeros{Float64,1}:
ERROR: MethodError: getindex(::FillArrays.Zeros{Float64,1}, ::Int64) is ambiguous. Candidates:
  getindex(F::FillArrays.AbstractFill{T,N}, kj::Vararg{Int64,N}) where {T, N} in FillArrays at /home/cst-jean/.julia/v0.6/FillArrays/src/FillArrays.jl:15
  getindex(F::FillArrays.AbstractFill, k::Int64) in FillArrays at /home/cst-jean/.julia/v0.6/FillArrays/src/FillArrays.jl:10
Possible fix, define
  getindex(::FillArrays.AbstractFill{T,1}, ::Int64)
Stacktrace:
 [1] _getindex at ./abstractarray.jl:907 [inlined]
 [2] getindex(::FillArrays.Zeros{Float64,1}, ::Int64, ::Int64) at ./abstractarray.jl:883
 [3] isassigned(::FillArrays.Zeros{Float64,1}, ::Int64, ::Int64, ::Vararg{Int64,N} where N) at ./abstractarray.jl:222
 [4] alignment(::IOContext{Base.Terminals.TTYTerminal}, ::FillArrays.Zeros{Float64,1}, ::Base.OneTo{Int64}, ::Base.OneTo{Int64}, ::Int64, ::Int64, ::Int64) at ./show.jl:1353
 [5] print_matrix(::IOContext{Base.Terminals.TTYTerminal}, ::FillArrays.Zeros{Float64,1}, ::String, ::String, ::String, ::String, ::String, ::String, ::Int64, ::Int64) at ./show.jl:1482
 [6] print_matrix(::IOContext{Base.Terminals.TTYTerminal}, ::FillArrays.Zeros{Float64,1}, ::String, ::String, ::String) at ./show.jl:1455
 [7] #showarray#263(::Bool, ::Function, ::IOContext{Base.Terminals.TTYTerminal}, ::FillArrays.Zeros{Float64,1}, ::Bool) at ./show.jl:1704
 [8] display(::Base.REPL.REPLDisplay{Base.REPL.LineEditREPL}, ::MIME{Symbol("text/plain")}, ::FillArrays.Zeros{Float64,1}) at ./REPL.jl:122
 [9] display(::Base.REPL.REPLDisplay{Base.REPL.LineEditREPL}, ::FillArrays.Zeros{Float64,1}) at ./REPL.jl:125
 [10] display(::FillArrays.Zeros{Float64,1}) at ./multimedia.jl:218
 [11] eval(::Module, ::Any) at ./boot.jl:235
 [12] print_response(::Base.Terminals.TTYTerminal, ::Any, ::Void, ::Bool, ::Bool, ::Void) at ./REPL.jl:144
 [13] print_response(::Base.REPL.LineEditREPL, ::Any, ::Void, ::Bool, ::Bool) at ./REPL.jl:129
 [14] (::Base.REPL.#do_respond#16{Bool,Base.REPL.##26#36{Base.REPL.LineEditREPL,Base.REPL.REPLHistoryProvider},Base.REPL.LineEditREPL,Base.LineEdit.Prompt})(::Base.LineEdit.MIState, ::Base.AbstractIOBuffer{Array{UInt8,1}}, ::Bool) at ./REPL.jl:646

I don't quite understand how Plots can introduce an ambiguity between two FillArrays methods...

cstjean commented 6 years ago

Simpler MWE:

julia> Zeros(3)[1]
ERROR: MethodError: getindex(::FillArrays.Zeros{Float64,1}, ::Int64) is ambiguous. Candidates:
  getindex(F::FillArrays.AbstractFill{T,N}, kj::Vararg{Int64,N}) where {T, N} in FillArrays at /home/cst-jean/.julia/v0.6/FillArrays/src/FillArrays.jl:15
  getindex(F::FillArrays.AbstractFill, k::Int64) in FillArrays at /home/cst-jean/.julia/v0.6/FillArrays/src/FillArrays.jl:10
Possible fix, define
  getindex(::FillArrays.AbstractFill{T,1}, ::Int64)

EDIT: furthermore, importing FillArrays first (using FillArrays, Plots) does not hit the ambiguity warning.

dlfivefifty commented 6 years ago

I'm not able to replicate this, has it been fixed?

cstjean commented 6 years ago

I can't replicate either. Maybe something was wrong with my system at the time. Thank you for checking.

tkf commented 6 years ago

I can actually reproduce this.

$ julia --color=yes --print 'using Plots; using FillArrays; Zeros(3)[1]'
ERROR: MethodError: getindex(::FillArrays.Zeros{Float64,1}, ::Int64) is ambiguous. Candidates:
  getindex(F::FillArrays.AbstractFill{T,N}, kj::Vararg{Int64,N}) where {T, N} in FillArrays at /home/takafumi/.julia/v0.6/FillArrays/src/FillArrays.jl:15
  getindex(F::FillArrays.AbstractFill, k::Int64) in FillArrays at /home/takafumi/.julia/v0.6/FillArrays/src/FillArrays.jl:10
Possible fix, define
  getindex(::FillArrays.AbstractFill{T,1}, ::Int64)
julia --color=yes --print 'using Plots; using FillArrays; Zeros(3)[1]'

$ julia --color=yes --print 'using FillArrays; Zeros(3)[1]'
0.0

$ julia
   _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation: https://docs.julialang.org
   _ _   _| |_  __ _   |  Type "?help" for help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.6.2 (2017-12-13 18:08 UTC)
 _/ |\__'_|_|_|\__'_|  |  Official http://julialang.org/ release
|__/                   |  x86_64-pc-linux-gnu

julia> versioninfo()
Julia Version 0.6.2
Commit d386e40c17 (2017-12-13 18:08 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i7-4500U CPU @ 1.80GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.9.1 (ORCJIT, haswell)

julia> Pkg.installed("Plots")
v"0.17.0"

julia> Pkg.installed("FillArrays")
v"0.0.1"
tkf commented 6 years ago

More info:

julia> import Plots

julia> import FillArrays

julia> for name in names(Main)
           if getfield(Main, name) isa Module
               version = try
                   Pkg.installed(string(name))
               catch
                   continue
               end
               println(name, " => ", version)
           end
       end
ColorTypes => 0.6.7
Colors => 0.8.2
Compat => 0.64.0
DataStructures => 0.8.2
FileIO => 0.7.0
FillArrays => 0.0.1
FixedPointNumbers => 0.4.6
JSON => 0.17.2
Measures => 0.2.0
Missings => 0.2.9
NaNMath => 0.3.1
Nullables => 0.0.5
PlotThemes => 0.2.0
PlotUtils => 0.4.4
Plots => 0.17.0
RecipesBase => 0.3.1
Reexport => 0.1.0
Requires => 0.4.3
Showoff => 0.1.1
SortingAlgorithms => 0.2.1
StaticArrays => 0.7.0+
StatsBase => 0.22.0
tkf commented 6 years ago

So it looks like a minimal module for getting the error is StaticArrays:

julia --color=yes --print 'import StaticArrays; import FillArrays; FillArrays.Zeros(3)[1]'

The StaticArrays version I was using above was 2a74b049b52bcf85032db43d85de91bf44a821f4 but I could actually reproduce the errror with StaticArrays v0.7.0.

Now, when I get the error, I have only those in Main:

Compat => 0.64.0
FillArrays => 0.0.1
StaticArrays => 0.7.0
dlfivefifty commented 6 years ago

Can you try adding the suggested function getindex(::AbstractFill{T,1}, k::Int) to see if that resolves it?

tkf commented 6 years ago

Yes, it solves the issue:

julia> import StaticArrays

julia> import FillArrays

julia> FillArrays.getindex(F::FillArrays.AbstractFill{T, 1}, ::Int) where T =
           FillArrays.getindex_value(F)

julia> FillArrays.Zeros(3)[1]
0.0
dlfivefifty commented 6 years ago

Mind making a PR?

tkf commented 6 years ago

Oops it was already fixed by d7ba08f749eb5216892b664ca8977b3493499f73. I was using FillArrays 0.0.1. Please close this issue.

dlfivefifty commented 6 years ago

I'll tag a new release now.

cstjean commented 6 years ago

I see you've tagged a release, but Pkg.update didn't update FillArrays, and I can't find the PR on METADATA. Did attobot have a hiccup?

dlfivefifty commented 6 years ago

Ahh, this is due to https://github.com/JuliaArrays/BlockArrays.jl/issues/46

I'll have to do a manual PR when I get the chance.

dlfivefifty commented 6 years ago

I deleted the tag that didn't work

dlfivefifty commented 6 years ago

https://github.com/JuliaLang/METADATA.jl/pull/14870