tinyopt 700
Tinyopt, a lightweight, header only optimization library
Loading...
Searching...
No Matches
c_api_float.h
1// Copyright 2026 Julien Michot.
2// SPDX-License-Identifier: Apache-2.0
3
4#ifndef TINYOPT_C_C_API_FLOAT_H
5#define TINYOPT_C_C_API_FLOAT_H
6
7#include <tinyopt/c/c_api_common.h>
8
9#if TINYOPT_C_API_ENABLE_FLOAT
10
11#ifdef __cplusplus
12extern "C" {
13#endif
14
15typedef struct tinyopt_paramsf_t {
16 float *x; /* In/out parameter values; updated on success or requested stop. */
17 int dims; /* Number of parameter values; must be positive. */
18 void (*plus_eq)(float *x, float *dx); /* Optional update; NULL uses component-wise addition. */
19} tinyopt_paramsf_t;
20
21/* Return 0 to continue, or nonzero to stop optimization. */
22typedef int (*tinyopt_cost_funcf_t)(const float *x, int dims, float *cost, void *user_data);
23/* Jacobian is row-major. Leave *jacobian unchanged to fill it, or set it to NULL for numerical
24 differentiation; do not replace it with another non-NULL pointer. */
25typedef int (*tinyopt_residuals_funcf_t)(const float *x, int dims, float *residuals,
26 float **jacobian, int num_residuals, void *user_data);
27/* These callbacks manually accumulate the gradient and, optionally, Hessian. */
28typedef int (*tinyopt_acc_grad_funcf_t)(const float *x, int dims, float *cost, float *gradient,
29 void *user_data);
30typedef int (*tinyopt_acc_hessian_funcf_t)(const float *x, int dims, float *cost, float *gradient,
31 float *hessian, void *user_data);
32
33typedef struct tinyopt_problemf_t {
34 tinyopt_eval_type_t type; /* Callback evaluation mode. */
35 union {
36 tinyopt_cost_funcf_t cost; /* Scalar objective callback. */
37 tinyopt_residuals_funcf_t residuals; /* Residual and optional Jacobian callback. */
38 tinyopt_acc_grad_funcf_t acc_grad; /* Scalar cost and gradient accumulation callback. */
39 tinyopt_acc_hessian_funcf_t acc_hessian; /* Scalar cost, gradient, and Hessian callback. */
40 } fn; /* Callback matching type. */
41 int num_residuals; /* Number of residuals in residual evaluation mode. */
42 void *user_data; /* User data passed unchanged to the selected callback. */
43} tinyopt_problemf_t;
44
45/* Uses default Levenberg-Marquardt options and numerical differentiation. */
46TINYOPT_C_API tinyopt_status_t tinyopt_optimizef(const tinyopt_paramsf_t *params,
47 const tinyopt_problemf_t *problem,
48 const tinyopt_options_t *options,
49 tinyopt_summary_t *summary);
50
51#ifdef __cplusplus
52}
53#endif
54
55#include <tinyopt/c/c_api_fixed_float.h>
56
57#endif
58
59#endif
Definition c_api_common.h:79
Definition c_api_common.h:25