Skip to content

Implement Base.zero for VariableIndex #1016

@cynddl

Description

@cynddl

I ran into an obscure error while trying to port https://github.com/blegat/EntropicCone.jl/ to recent packages including MOI. I don't have any code to reproduce yet, but apparently testing for subset inclusion with Polyhedra.jl calls Polyhedra._hinh which ends up calling Base.zero on MOI.VariableIndex. A function not implemented yet.

MethodError: no method matching zero(::Type{MathOptInterface.VariableIndex})

I am assuming this can be fixed with:

Base.zero(::Type{MOI.VariableIndex}) = MOI.VariableIndex(0)

Correct?


If useful, the complete stack below:

  Test threw exception
  Expression: !(zhangyeungineq in G)
  MethodError: no method matching zero(::Type{MathOptInterface.VariableIndex})
  Closest candidates are:
    zero(!Matched::Type{Missing}) at missing.jl:103
    zero(!Matched::Type{LibGit2.GitHash}) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.3/LibGit2/src/oid.jl:220
    zero(!Matched::Type{Pkg.Resolve.VersionWeights.VersionWeight}) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.3/Pkg/src/resolve/VersionWeights.jl:19
    ...
  Stacktrace:
   [1] _zeros_eltypes at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.3/SparseArrays/src/higherorderfns.jl:203 [inlined]
   [2] _zeros_eltypes at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.3/SparseArrays/src/higherorderfns.jl:204 [inlined]
   [3] _noshapecheck_map(::Type{MathOptInterface.ScalarAffineTerm{Float64}}, ::SparseArrays.SparseVector{Int64,Int64}, ::SparseArrays.SparseVector{MathOptInterface.VariableIndex,Int64}) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.3/SparseArrays/src/higherorderfns.jl:159
   [4] _shapecheckbc(::Type, ::SparseArrays.SparseVector{Int64,Int64}, ::Vararg{Any,N} where N) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.3/SparseArrays/src/higherorderfns.jl:1025
   [5] _copy(::Type, ::SparseArrays.SparseVector{Int64,Int64}, ::SparseArrays.SparseVector{MathOptInterface.VariableIndex,Int64}) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.3/SparseArrays/src/higherorderfns.jl:1014
   [6] copy(::Base.Broadcast.Broadcasted{SparseArrays.HigherOrderFns.PromoteToSparse,Tuple{Base.OneTo{Int64}},Type{MathOptInterface.ScalarAffineTerm{Float64}},Tuple{SparseArrays.SparseVector{Int64,Int64},Array{MathOptInterface.VariableIndex,1}}}) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.3/SparseArrays/src/higherorderfns.jl:1131
   [7] materialize(::Base.Broadcast.Broadcasted{SparseArrays.HigherOrderFns.PromoteToSparse,Nothing,Type{MathOptInterface.ScalarAffineTerm{Float64}},Tuple{SparseArrays.SparseVector{Int64,Int64},Array{MathOptInterface.VariableIndex,1}}}) at ./broadcast.jl:819
   [8] support_function_model(::SparseArrays.SparseVector{Int64,Int64}, ::DefaultPolyhedron{Float64,Polyhedra.Intersection{Float64,SparseArrays.SparseVector{Float64,Int64},Int64},Polyhedra.Hull{Float64,Array{Float64,1},Int64}}, ::OptimizerFactory) at /Users/cynddl/.julia/packages/Polyhedra/RI4Vm/src/repelemop.jl:126
   [9] _hinh(::HalfSpace{Int64,SparseArrays.SparseVector{Int64,Int64}}, ::DefaultPolyhedron{Float64,Polyhedra.Intersection{Float64,SparseArrays.SparseVector{Float64,Int64},Int64},Polyhedra.Hull{Float64,Array{Float64,1},Int64}}, ::OptimizerFactory) at /Users/cynddl/.julia/packages/Polyhedra/RI4Vm/src/repelemop.jl:160
   [10] issubset at /Users/cynddl/.julia/packages/Polyhedra/RI4Vm/src/repelemop.jl:191 [inlined]
   [11] issubset(::DefaultPolyhedron{Float64,Polyhedra.Intersection{Float64,SparseArrays.SparseVector{Float64,Int64},Int64},Polyhedra.Hull{Float64,Array{Float64,1},Int64}}, ::HalfSpace{Int64,SparseArrays.SparseVector{Int64,Int64}}) at /Users/cynddl/.julia/packages/Polyhedra/RI4Vm/src/repelemop.jl:188
   [12] in(::DualEntropy{false,Int64,SparseArrays.SparseVector{Int64,Int64}}, ::EntropyCone{Float64}) at /Users/cynddl/.julia/dev/EntropicCone/src/coneoperations.jl:63
   [13] eval_test(::Expr, ::Expr, ::LineNumberNode, ::Bool) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.3/Test/src/Test.jl:245
   [14] top-level scope at /Users/cynddl/.julia/dev/EntropicCone/test/zhangyeung.jl:39
   [15] top-level scope at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.3/Test/src/Test.jl:1107
   [16] top-level scope at /Users/cynddl/.julia/dev/EntropicCone/test/zhangyeung.jl:39
   [17] top-level scope at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.3/Test/src/Test.jl:1107
   [18] top-level scope at /Users/cynddl/.julia/dev/EntropicCone/test/zhangyeung.jl:8

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions