From 818ec7be2f087fa89926da400b17faf7671db24f Mon Sep 17 00:00:00 2001 From: Tangi Migot Date: Sat, 17 Aug 2024 18:44:34 +0200 Subject: [PATCH] Add eltype for NLPModels (#481) --- src/nlp/utils.jl | 7 +++++++ test/nlp/api.jl | 1 + test/nls/api.jl | 1 + 3 files changed, 9 insertions(+) diff --git a/src/nlp/utils.jl b/src/nlp/utils.jl index dd16b42b..8f2b4a1b 100644 --- a/src/nlp/utils.jl +++ b/src/nlp/utils.jl @@ -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) diff --git a/test/nlp/api.jl b/test/nlp/api.jl index 6d7d209e..730dc5ca 100644 --- a/test/nlp/api.jl +++ b/test/nlp/api.jl @@ -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 diff --git a/test/nls/api.jl b/test/nls/api.jl index 530696a7..c033dc6d 100644 --- a/test/nls/api.jl +++ b/test/nls/api.jl @@ -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