Overload what to fix "Julia Client - Internal Error" with subtype of AbstractArray?

43 views
Skip to first unread message

Chris Stook

unread,
Sep 29, 2016, 8:44:52 AM9/29/16
to julia-users

I have defined a simple subtype of AbstractArray which keeps track if an array has been modified by the user.  Base.show, Base.showcompact, and Base.display are overloaded.  This works in the REPL, but with Atom I receive the following error.

Julia Client - Internal Error

MethodError: no method matching print_matrix(::IOContext{Base.AbstractIOBuffer{Array{UInt8,1}}}, ::LTspice.IsModifiedArray{Float64,1}, ::String, ::String, ::String)
Closest candidates are:
  print_matrix(::IO, !Matched::Union{AbstractArray{T,1},AbstractArray{T,2}}, ::AbstractString, ::AbstractString, ::AbstractString) at show.jl:1379
  print_matrix(::IO, !Matched::Union{AbstractArray{T,1},AbstractArray{T,2}}, ::AbstractString, ::AbstractString, ::AbstractString, !Matched::AbstractString) at show.jl:1379
  print_matrix(::IO, !Matched::Union{AbstractArray{T,1},AbstractArray{T,2}}, ::AbstractString, ::AbstractString, ::AbstractString, !Matched::AbstractString, !Matched::AbstractString) at show.jl:1379
  ...
 in #showarray#330(::Bool, ::Function, ::IOContext{Base.AbstractIOBuffer{Array{UInt8,1}}}, ::LTspice.IsModifiedArray{Float64,1}, ::Bool) at .\show.jl:1618
 in verbose_show(::Base.AbstractIOBuffer{Array{UInt8,1}}, ::MIME{Symbol("text/plain")}, ::LTspice.IsModifiedArray{Float64,1}) at .\multimedia.jl:50
 in #sprint#304(::Void, ::Function, ::Int64, ::Function, ::MIME{Symbol("text/plain")}, ::Vararg{Any,N}) at .\strings\io.jl:37
 in Type at C:\Users\Chris\.julia\v0.5\Juno\src\types.jl:48 [inlined]
 in Type at C:\Users\Chris\.julia\v0.5\Juno\src\types.jl:49 [inlined]
 in render(::Juno.Editor, ::LTspice.IsModifiedArray{Float64,1}) at C:\Users\Chris\.julia\v0.5\Juno\src\types.jl:12
 in (::Atom.##81#84)(::Dict{String,Any}) at C:\Users\Chris\.julia\v0.5\Atom\src\eval.jl:64
 in handlemsg(::Dict{String,Any}, ::Dict{String,Any}, ::Vararg{Dict{String,Any},N}) at C:\Users\Chris\.julia\v0.5\Atom\src\comm.jl:148
 in (::Atom.##7#10)() at .\event.jl:68


What do I need to overload to fix this?

Code below:

abstract SpecialArray <: AbstractArray

Base.size(a::SpecialArray) = size(a.values)
Base.linearindexing{T<:SpecialArray}(::Type{T}) = Base.LinearFast()
Base.getindex(a::SpecialArray, i::Int) = a.values[i]
Base.ndims(a::SpecialArray) = ndims(a.values)
Base.show(io::IO, a::SpecialArray) = show(io,a.values)
Base.showcompact(io::IO, a::SpecialArray) = showcompact(io,a.values)
Base.display(a::SpecialArray) = display(a.values)
"""
Same as Array, but tracks is user has modified values.
"""
type IsModifiedArray{T,S} <: SpecialArray
  values :: Array{T,S}
  ismodified :: Bool
end

function Base.setindex!(a::IsModifiedArray, v, i::Int)
  a.ismodified = true
  a.values[i] = v
end

a =  IsModifiedArray{Float64,1}([1.0,2.0,3.0],false) # error here

randm...@gmail.com

unread,
Sep 29, 2016, 10:07:40 AM9/29/16
to julia-users
That error happens because your subtyping isn't entirely correct:

IsModifiedArray{Float64, 1} <: AbstractArray{Float64, 1} == false

with your definition. If you do

abstract SpecialArray{T,S} <: AbstractArray{T,S}
type IsModifiedArray{T,S} <: SpecialArray{T,S}

  values :: Array{T,S}
  ismodified :: Bool
end


you won't get that error.

If you want to pretty print results in Juno that won't be enough: Have a look here.

Chris Stook

unread,
Sep 29, 2016, 10:18:04 AM9/29/16
to julia-users
That fixed it.

Thank you!
Reply all
Reply to author
Forward
0 new messages