tinyopt 700
Tinyopt, a lightweight, header only optimization library
Loading...
Searching...
No Matches
c_api_sparse_double.h
1// Copyright 2026 Julien Michot.
2// SPDX-License-Identifier: Apache-2.0
3
4#ifndef TINYOPT_C_C_API_SPARSE_DOUBLE_H
5#define TINYOPT_C_C_API_SPARSE_DOUBLE_H
6
7#include <tinyopt/c/c_api_double.h>
8
9#if TINYOPT_C_API_ENABLE_SUITESPARSE
10
11#include <cholmod.h>
12
13#ifdef __cplusplus
14extern "C" {
15#endif
16
17/* Accumulates the scalar cost, gradient and sparse Hessian (dims x dims, dynamic size).
18 Return 0 to continue, or nonzero to stop optimization.
19 `gradient` and `hessian` are NULL when only the cost is requested. `gradient` is zeroed
20 beforehand. When `hessian` is not NULL, set `*hessian` to a newly allocated double precision,
21 real, int-indexed cholmod_sparse (e.g. with cholmod_triplet_to_sparse()) using `common`; Tinyopt
22 takes ownership and frees it. Its stype may be 0 (symmetric, upper triangle is read), 1 (upper) or
23 -1 (lower). */
24typedef int (*tinyopt_sparse_acc_hessian_func_t)(const double *x, int dims, double *cost,
25 double *gradient, cholmod_sparse **hessian,
26 cholmod_common *common, void *user_data);
27
28typedef struct tinyopt_sparse_problem_t {
29 tinyopt_sparse_acc_hessian_func_t acc_hessian; /* Cost, gradient and sparse Hessian callback. */
30 void *user_data; /* User data passed unchanged to the callback. */
31} tinyopt_sparse_problem_t;
32
33/* Uses Levenberg-Marquardt (or Gauss-Newton) with a SuiteSparse CHOLMOD linear solver. */
34TINYOPT_C_API tinyopt_status_t tinyopt_optimize_sparse(const tinyopt_params_t *params,
35 const tinyopt_sparse_problem_t *problem,
36 const tinyopt_options_t *options,
37 tinyopt_summary_t *summary);
38
39#ifdef __cplusplus
40}
41#endif
42
43#endif
44
45#endif
Definition c_api_common.h:79
Definition c_api_double.h:13
Definition c_api_common.h:25