Initialize and evaluate the value, gradient, sparse constraint Jacobian and
sparse Lagrangian Hessian of a problem built with sd_problem.
Derivatives come in two forms, matching 'sparsediffpy': coordinate (COO)
form, with the Hessian as its lower triangle (the form CVXPY uses), and
compressed-sparse-row (CSR) form, with the full Hessian.
Usage
sd_init_derivatives(prob)
sd_init_jacobian(prob)
sd_init_jacobian_coo(prob)
sd_init_hessian_coo(prob)
sd_objective_forward(prob, u)
sd_constraint_forward(prob, u)
sd_gradient(prob)
sd_jacobian_sparsity(prob)
sd_jacobian_values(prob)
sd_hessian_sparsity(prob)
sd_hessian_values(prob, obj_w, w)
sd_jacobian(prob)
sd_get_jacobian(prob)
sd_init_hessian(prob)
sd_hessian(prob, obj_w, w)
sd_get_hessian(prob)Arguments
- prob
a problem handle from
sd_problem.- u
a numeric vector: the primal point at which to evaluate, laid out in the engine's column-major flat ordering (the same ordering used by the
var_idoffsets passed tosd_variable).- obj_w
a scalar weight \(\sigma\) multiplying the objective Hessian.
- w
a numeric vector of constraint multipliers (length equal to the total constraint size) weighting the constraint Hessians.
Value
sd_init_derivatives,sd_init_jacobian,sd_init_jacobian_coo,sd_init_hessian,sd_init_hessian_coocalled for their side effect; return
NULLinvisibly.sd_jacobian,sd_get_jacobian,sd_hessian,sd_get_hessiana list with the CSR arrays of the matrix:
data(double),indices(0-based column indices) andindptr(row pointers), plusshape = c(nrow, ncol).sd_jacobianevaluates the constraint Jacobian (aftersd_init_jacobianand a forward pass) andsd_hessianthe full Lagrangian Hessian \(\sigma\nabla^2 f + \sum_i w_i \nabla^2 g_i\) (aftersd_init_hessian); thesd_get_*forms return the matrix as last evaluated, without re-evaluating it.sd_objective_forwardthe scalar objective value at
u.sd_constraint_forwardthe constraint vector at
u.sd_gradientthe objective gradient, length
n_vars.sd_jacobian_sparsity,sd_hessian_sparsitya list with integer
rows/cols(0-based COO indices) andnrow/ncol.sd_jacobian_valuesthe constraint-Jacobian nonzeros, matching the Jacobian sparsity order.
sd_hessian_valuesthe nonzeros of \(\sigma\nabla^2 f + \sum_i w_i \nabla^2 g_i\), lower triangle, matching the Hessian sparsity order.
Details
Evaluation is ordered: a forward pass first
(sd_objective_forward / sd_constraint_forward) populates the
node values at u, after which sd_gradient,
sd_jacobian_values and sd_hessian_values read them. Sparsity
patterns are structural — fixed once the corresponding sd_init_*
routine has run — so they are queried once and reused, while the values are
recomputed at each new point. Row and column indices are 0-based (the engine
convention; a higher-level modeling layer such as CVXR translates them
to 1-based as needed).
