Repository navigation
Expand file tree
/
Copy pathbindings.c
More file actions
123 lines (116 loc) · 4.95 KB
/
Copy pathbindings.c
File metadata and controls
123 lines (116 loc) · 4.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <numpy/arrayobject.h>
/* Include atom bindings */
#include "atoms/add.h"
#include "atoms/asinh.h"
#include "atoms/atanh.h"
#include "atoms/const_scalar_mult.h"
#include "atoms/const_vector_mult.h"
#include "atoms/constant.h"
#include "atoms/cos.h"
#include "atoms/entr.h"
#include "atoms/exp.h"
#include "atoms/getters.h"
#include "atoms/index.h"
#include "atoms/left_matmul.h"
#include "atoms/linear.h"
#include "atoms/log.h"
#include "atoms/logistic.h"
#include "atoms/multiply.h"
#include "atoms/neg.h"
#include "atoms/power.h"
#include "atoms/promote.h"
#include "atoms/quad_form.h"
#include "atoms/quad_over_lin.h"
#include "atoms/rel_entr.h"
#include "atoms/reshape.h"
#include "atoms/right_matmul.h"
#include "atoms/sin.h"
#include "atoms/sinh.h"
#include "atoms/sum.h"
#include "atoms/tan.h"
#include "atoms/tanh.h"
#include "atoms/variable.h"
#include "atoms/xexp.h"
/* Include problem bindings */
#include "problem/constraint_forward.h"
#include "problem/gradient.h"
#include "problem/hessian.h"
#include "problem/init_derivatives.h"
#include "problem/jacobian.h"
#include "problem/make_problem.h"
#include "problem/objective_forward.h"
static int numpy_initialized = 0;
static int ensure_numpy(void)
{
if (numpy_initialized) return 0;
import_array1(-1);
numpy_initialized = 1;
return 0;
}
static PyMethodDef DNLPMethods[] = {
{"make_variable", py_make_variable, METH_VARARGS, "Create variable node"},
{"make_constant", py_make_constant, METH_VARARGS, "Create constant node"},
{"make_linear", py_make_linear, METH_VARARGS, "Create linear op node"},
{"make_log", py_make_log, METH_VARARGS, "Create log node"},
{"make_exp", py_make_exp, METH_VARARGS, "Create exp node"},
{"make_index", py_make_index, METH_VARARGS, "Create index node"},
{"make_add", py_make_add, METH_VARARGS, "Create add node"},
{"make_sum", py_make_sum, METH_VARARGS, "Create sum node"},
{"make_neg", py_make_neg, METH_VARARGS, "Create neg node"},
{"make_promote", py_make_promote, METH_VARARGS, "Create promote node"},
{"make_multiply", py_make_multiply, METH_VARARGS,
"Create elementwise multiply node"},
{"make_const_scalar_mult", py_make_const_scalar_mult, METH_VARARGS,
"Create constant scalar multiplication node (a * f(x))"},
{"make_const_vector_mult", py_make_const_vector_mult, METH_VARARGS,
"Create constant vector multiplication node (a ∘ f(x))"},
{"make_power", py_make_power, METH_VARARGS, "Create power node"},
{"make_sin", py_make_sin, METH_VARARGS, "Create sin node"},
{"make_cos", py_make_cos, METH_VARARGS, "Create cos node"},
{"make_tan", py_make_tan, METH_VARARGS, "Create tan node"},
{"make_sinh", py_make_sinh, METH_VARARGS, "Create sinh node"},
{"make_tanh", py_make_tanh, METH_VARARGS, "Create tanh node"},
{"make_asinh", py_make_asinh, METH_VARARGS, "Create asinh node"},
{"make_atanh", py_make_atanh, METH_VARARGS, "Create atanh node"},
{"make_entr", py_make_entr, METH_VARARGS, "Create entr node"},
{"make_logistic", py_make_logistic, METH_VARARGS, "Create logistic node"},
{"make_xexp", py_make_xexp, METH_VARARGS, "Create xexp node"},
{"make_left_matmul", py_make_left_matmul, METH_VARARGS,
"Create left matmul node (A @ f(x))"},
{"make_right_matmul", py_make_right_matmul, METH_VARARGS,
"Create right matmul node (f(x) @ A)"},
{"make_quad_form", py_make_quad_form, METH_VARARGS,
"Create quadratic form node (x' * Q * x)"},
{"make_quad_over_lin", py_make_quad_over_lin, METH_VARARGS,
"Create quad_over_lin node (sum(x^2) / y)"},
{"make_rel_entr", py_make_rel_entr, METH_VARARGS,
"Create rel_entr node: x * log(x/y) elementwise"},
{"get_expr_dimensions", py_get_expr_dimensions, METH_VARARGS,
"Get the dimensions (d1, d2) of an expression"},
{"get_expr_size", py_get_expr_size, METH_VARARGS,
"Get the total size of an expression"},
{"make_reshape", py_make_reshape, METH_VARARGS, "Create reshape atom"},
{"make_problem", py_make_problem, METH_VARARGS,
"Create problem from objective and constraints"},
{"problem_init_derivatives", py_problem_init_derivatives, METH_VARARGS,
"Initialize derivative structures"},
{"problem_objective_forward", py_problem_objective_forward, METH_VARARGS,
"Evaluate objective only"},
{"problem_constraint_forward", py_problem_constraint_forward, METH_VARARGS,
"Evaluate constraints only"},
{"problem_gradient", py_problem_gradient, METH_VARARGS,
"Compute objective gradient"},
{"problem_jacobian", py_problem_jacobian, METH_VARARGS,
"Compute constraint jacobian"},
{"problem_hessian", py_problem_hessian, METH_VARARGS,
"Compute Lagrangian Hessian"},
{NULL, NULL, 0, NULL}};
static struct PyModuleDef dnlp_module = {
PyModuleDef_HEAD_INIT, "dnlp_diff_engine._core", NULL, -1, DNLPMethods};
PyMODINIT_FUNC PyInit__core(void)
{
if (ensure_numpy() < 0) return NULL;
return PyModule_Create(&dnlp_module);
}