-
Couldn't load subscription status.
- Fork 17
Description
Code
import SparseArrays: sparse
import ADNLPModels
params0 = [1.0, 0.1, 0.9]
A = sparse([
0 -1 1 # NOTE: integers here!
])
problem = ADNLPModels.ADNLPModel(
x -> x' * x, params0, # f, x0
[0., 0, 0], [Inf, Inf, 1], # lvar, uvar
A, [0.], [Inf] # A, lcon, ucon
)Output
julia> A = sparse([
0 -1 1 # NOTE: integers here!
])
1×3 SparseArrays.SparseMatrixCSC{Int64, Int64} with 2 stored entries:
⋅ -1 1
julia> ADNLPModels.ADNLPModel(
x -> x' * x, params0, # f, x0
[0., 0, 0], [Inf, Inf, 1], # lvar, uvar
A, [0.], [Inf] # A, lcon, ucon
)
ERROR: MethodError: no method matching ADNLPModels.ADNLPModel(::var"#1#2", ::Vector{…}, ::Vector{…}, ::Vector{…}, ::Vector{…}, ::Vector{…}, ::Vector{…}, ::Vector{…}, ::Vector{…})
The type `ADNLPModels.ADNLPModel` exists, but no method is defined for this combination of argument types when trying to construct it.
Closest candidates are:
ADNLPModels.ADNLPModel(::Any, ::S, ::S, ::S, ::Any, ::Any, ::S, ::S, ::S; kwargs...) where S
@ ADNLPModels ~/.julia/packages/ADNLPModels/bOFzz/src/nlp.jl:330
ADNLPModels.ADNLPModel(::Any, ::S, ::S, ::S, ::Any, ::Any, ::S, ::Any, ::S, ::S; kwargs...) where S
@ ADNLPModels ~/.julia/packages/ADNLPModels/bOFzz/src/nlp.jl:427
ADNLPModels.ADNLPModel(::Any, ::Any, ::Any, ::Any, ::SparseArrays.AbstractSparseMatrix{Tv, Ti}, ::Any, ::Any, ::Any; kwargs...) where {Tv, Ti}
@ ADNLPModels ~/.julia/packages/ADNLPModels/bOFzz/src/nlp.jl:507
...
Stacktrace:
[1] ADNLPModels.ADNLPModel(f::Function, x0::Vector{…}, lvar::Vector{…}, uvar::Vector{…}, A::SparseArrays.SparseMatrixCSC{…}, lcon::Vector{…}, ucon::Vector{…}; kwargs::@Kwargs{})
@ ADNLPModels ~/.julia/packages/ADNLPModels/bOFzz/src/nlp.jl:368
[2] ADNLPModels.ADNLPModel(f::Function, x0::Vector{…}, lvar::Vector{…}, uvar::Vector{…}, A::SparseArrays.SparseMatrixCSC{…}, lcon::Vector{…}, ucon::Vector{…})
@ ADNLPModels ~/.julia/packages/ADNLPModels/bOFzz/src/nlp.jl:358
[3] top-level scope
@ REPL[8]:1
Some type information was truncated. Use `show(err)` to see complete types.
Problem
Turns out, this happens because A is a matrix of integers, but the error message doesn't tell me this.
Also, I'm not calling ADNLPModels.ADNLPModel(::var"#1#2", ::Vector{Float64}, ::Vector{Float64}, ::Vector{Float64}, ::Vector{Int64}, ::Vector{Int64}, ::Vector{Int64}, ::Vector{Float64}, ::Vector{Float64}) - the package tries to call it here:
Lines 358 to 369 in 5d917ce
| function ADNLPModel( | |
| f, | |
| x0::S, | |
| lvar::S, | |
| uvar::S, | |
| A::AbstractSparseMatrix{Tv, Ti}, | |
| lcon::S, | |
| ucon::S; | |
| kwargs..., | |
| ) where {S, Tv, Ti} | |
| return ADNLPModel(f, x0, lvar, uvar, findnz(A)..., lcon, ucon; kwargs...) | |
| end |
The signature of this method doesn't constrain S or Tv in any way. Why not write:
const AV{T} = AbstractVector{T}
ADNLPModel(
f, x0::AV{Tv}, lvar::AV{Tv}, uvar::AV{Tv},
A::AbstractSparseMatrix{Tv, Ti},
lcon::AV{Tv}, ucon::AV{Tv};
kwargs...
) where {Tv, Ti} = ...This way, the error will move to user code, because then I'll be calling this constructor with (Tv = eltype(x0)) === Float64, but the AbstractSparseMatrix would need Tv = eltype(A) == Int64.