Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove allocations in jprod, hprod and nln_structure #90

Merged
merged 2 commits into from
Jan 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions src/feasibility-form-nls.jl
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ function NLPModels.jac_nln_structure!(
if m > 0
idx = nnzjF .+ (1:(nlp.internal.meta.nln_nnzj))
@views jac_nln_structure!(nlp.internal, rows[idx], cols[idx])
rows[idx] .+= ne
@views rows[idx] .+= ne
end
rows[(end - ne + 1):end] .= 1:ne
cols[(end - ne + 1):end] .= n .+ (1:ne)
Expand Down Expand Up @@ -223,10 +223,15 @@ function NLPModels.jprod_nln!(
increment!(nlp, :neval_jprod_nln)
n, m, ne = nlp.internal.meta.nvar, nlp.internal.meta.nnln, nlp.internal.nls_meta.nequ
x = @view xr[1:n]
@views jprod_residual!(nlp.internal, x, v[1:n], jv[1:ne])
@views jv[1:ne] .-= v[(n + 1):end]
@views jprod_residual!(nlp.internal, x, v[1:n], nlp.tmpy[1:ne])
for i = 1:ne
jv[i] = nlp.tmpy[i] - v[n + i]
end
if m > 0
@views jprod_nln!(nlp.internal, x, v[1:n], jv[(ne + 1):end])
@views jprod_nln!(nlp.internal, x, v[1:n], nlp.tmpy[(ne + 1):(nlp.meta.nnln)])
for i = (ne + 1):(nlp.meta.nnln)
jv[i] = nlp.tmpy[i]
end
end
return jv
end
Expand Down Expand Up @@ -369,13 +374,27 @@ function NLPModels.hprod!(
fill!(hv, zero(T))
end
for i = 1:ne
hprod_residual!(nlp.internal, x, i, v[1:n], nlp.tmp)
@views hprod_residual!(nlp.internal, x, i, v[1:n], nlp.tmp)
@views hv[1:n] .+= nlp.tmp .* y[i]
end
@views hv[(n + 1):end] .= obj_weight .* v[(n + 1):end]
return hv
end

function NLPModels.hprod!(
nlp::FeasibilityFormNLS,
xr::AbstractVector{T},
v::AbstractVector,
hv::AbstractVector;
obj_weight::Real = one(T),
) where {T}
@lencheck nlp.meta.nvar xr v hv
n = nlp.internal.meta.nvar
fill!(hv, zero(T))
@views hv[(n + 1):end] .= obj_weight .* v[(n + 1):end]
return hv
end

function NLPModels.ghjvprod!(
nlp::FeasibilityFormNLS,
x::AbstractVector,
Expand Down