Skip to content

Commit

Permalink
Add eltype for NLPModels (#481)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmigot authored Aug 17, 2024
1 parent 82100be commit 818ec7b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/nlp/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,10 @@ macro default_counters(Model, inner)
)
ex
end

"""
eltype(nlp::AbstractNLPModel{T, S})
Element type of `nlp.meta.x0`.
"""
Base.eltype(nlp::AbstractNLPModel{T, S}) where {T, S} = eltype(nlp.meta.x0)
1 change: 1 addition & 0 deletions test/nlp/api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
H(x, y) = H(x) + y[2] * [-0.5 0; 0 -2.0]

nlp = SimpleNLPModel()
@test eltype(nlp) == Float64
n = nlp.meta.nvar
m = nlp.meta.ncon

Expand Down
1 change: 1 addition & 0 deletions test/nls/api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
HF(x, w) = w[2] * [-20.0 0; 0 0]

nls = SimpleNLSModel()
@test eltype(nls) == Float64
n = nls.meta.nvar
m = nls.meta.ncon
ne = nls_meta(nls).nequ
Expand Down

0 comments on commit 818ec7b

Please sign in to comment.