Skip to content

Unhelpful/confusing error message when extending functions from Base #4070

Closed
@ingmarschuster

Description

@ingmarschuster

importing the module quoted below and calling
HeldoutDatasets.HoldoutIndex(10,0.2)

gave me the error

ERROR: no method getindex(Dict{Any,Any},Int64)
in HoldoutIndex at HeldoutDatasets.jl:23

which I find completely confusing and very hard to debug. Removing the module HeldoutDatasets declaration gave the following much clearer Error:

ERROR: error in method definition: function Base.getindex must be explicitly imported to be extended
in include_from_node1 at loading.jl:92
in reload_path at loading.jl:117
in reload at loading.jl:59
at HeldoutDatasets.jl:43

module HeldoutDatasets
using HoldOuts

type HoldoutIndex
    num_entities::Int64
    to_remove::Dict

    function HoldoutIndex(num_entities::Int64, hold_out = 0.2)
        max_idx =   floor(num_entities^2*hold_out)
        to_remove = Dict()
        for i in 1:max_idx
            r = rand(1:num_entities)
            c = r
            while c == r
                c = rand(1:num_entities)
            end
            if !haskey(to_remove, r)
                tmp = Array(Int64,0)
                push!(tmp, c)
                to_remove[r] = tmp
            else
                tmp = to_remove[convert(Any,r)]
                push!(tmp, c)
            end
        end
        for k in keys(to_remove)
            to_remove[k] = Reverse(sort(to_remove[k]))
        end
        return new(num_entities, to_remove)
    end
end

function getindex(d::HoldoutIndex, r::Number)
    retval = convert(Array{Int64,1},1:d.num_entities)
    if !haskey(d.to_remove, r)
        return retval
    end
    for c in d.to_remove[r]
        splice!(retval, c)
    end
    return retval
end

end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions