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