diff --git a/src/CUTEst.jl b/src/CUTEst.jl index 6c4ae43c..6316cf59 100644 --- a/src/CUTEst.jl +++ b/src/CUTEst.jl @@ -12,6 +12,7 @@ using JSON import Libdl.dlsym import REPL.TerminalMenus import Base.format_bytes +import Base.RefValue import Printf.@sprintf import DataStructures: OrderedDict diff --git a/src/julia_interface.jl b/src/julia_interface.jl index 3d72383d..3187ca0d 100644 --- a/src/julia_interface.jl +++ b/src/julia_interface.jl @@ -324,10 +324,14 @@ function NLPModels.jac_nln_structure!( ) where {T} @lencheck nlp.meta.nln_nnzj rows cols k = 1 - for i in findall(j -> j in nlp.meta.nln, nlp.jrows) - rows[k] = nlp.jrows[i] - count(x < nlp.jrows[i] for x in nlp.meta.lin) - cols[k] = nlp.jcols[i] - k += 1 + for index in eachindex(nlp.jrows) + jr = nlp.jrows[index] + if jr in nlp.meta.nln + offset = count(x < nlp.jrows[index] for x in nlp.meta.lin) + rows[k] = jr - offset + cols[k] = nlp.jcols[index] + k += 1 + end end return rows, cols end @@ -759,7 +763,6 @@ function NLPModels.jth_hess_coord!( @rangecheck 1 nlp.meta.ncon j ref_j = nlp.index ref_j[] = j - nnzh_output = Ref{Cint}() cish( T, nlp.libsif, @@ -767,7 +770,7 @@ function NLPModels.jth_hess_coord!( nlp.nvar, x, ref_j, - nnzh_output, + nlp.nnzh_jth, nlp.nnzh, vals, nlp.hcols, diff --git a/src/model.jl b/src/model.jl index 87f14265..e5eb6c2a 100644 --- a/src/model.jl +++ b/src/model.jl @@ -19,14 +19,15 @@ mutable struct CUTEstModel{T} <: AbstractNLPModel{T, Vector{T}} Jvar::Vector{Cint} libsif::Ptr{Cvoid} - funit::Ref{Cint} - index::Ref{Cint} - nvar::Ref{Cint} - ncon::Ref{Cint} - nnzj::Ref{Cint} - nnzh::Ref{Cint} - f::Ref{T} - status::Ref{Cint} + funit::RefValue{Cint} + index::RefValue{Cint} + nvar::RefValue{Cint} + ncon::RefValue{Cint} + nnzj::RefValue{Cint} + nnzh::RefValue{Cint} + nnzh_jth::RefValue{Cint} + f::RefValue{T} + status::RefValue{Cint} end """ @@ -326,6 +327,7 @@ function CUTEstModel{T}( Ref{Cint}(ncon), Ref{Cint}(nnzj), Ref{Cint}(nnzh), + Ref{Cint}(), Ref{T}(), status, ) diff --git a/test/runtests.jl b/test/runtests.jl index cf0d65ef..0442c602 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -60,6 +60,7 @@ include("test_core.jl") include("test_julia.jl") include("coverage.jl") include("multiple_precision.jl") +include("test_allocations.jl") for problem in problems for T in (Float32, Float64, Float128) diff --git a/test/test_allocations.jl b/test/test_allocations.jl new file mode 100644 index 00000000..42911f8e --- /dev/null +++ b/test/test_allocations.jl @@ -0,0 +1,12 @@ +# using CUTEst, NLPModelsTest, NLPModels, Quadmath + +@testset "allocations -- $pb" for pb in ("BROWNDEN", "HS5", "HS6", "HS10", "HS11", "HS13", "HS14") + @testset "precision -- $T" for T in (Float32, Float64, Float128) + (T == Float128) && (Sys.ARCH == :aarch64) && Sys.islinux() && continue + nlp = CUTEstModel{T}(pb) + NLPModelsTest.test_zero_allocations(nlp; linear_api=true, exclude=[jac_op]) + # mems = NLPModelsTest.test_allocs_nlpmodels(nlp; linear_api=true, exclude=[jac_op]) + # display(mems) + finalize(nlp) + end +end