Skip to content

Commit edc6e31

Browse files
committed
Test tcc
1 parent 71206ab commit edc6e31

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

src/pyoptinterface/_src/codegen_c.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,30 @@
3838
def generate_csrc_prelude(io: IO[str]):
3939
io.write(
4040
"""// includes
41-
#include "stddef.h"
42-
#include "math.h"
41+
#include <stddef.h>
4342
4443
// typedefs
4544
typedef double float_point_t;
4645
46+
// declare mathematical functions
47+
#define UNARY(f) float_point_t f(float_point_t x)
48+
#define BINARY(f) float_point_t f(float_point_t x, float_point_t y)
49+
50+
// unary functions
51+
UNARY(fabs);
52+
UNARY(acos);
53+
UNARY(asin);
54+
UNARY(atan);
55+
UNARY(cos);
56+
UNARY(exp);
57+
UNARY(log);
58+
UNARY(sin);
59+
UNARY(sqrt);
60+
UNARY(tan);
61+
62+
// binary functions
63+
BINARY(pow);
64+
4765
// externals
4866
// azmul
4967
float_point_t azmul(float_point_t x, float_point_t y)

src/pyoptinterface/_src/jit_c.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
# On Linux/Mac, tcc has lib/tcc/include/ and lib/tcc/libtcc1.a which must be included in compilation
2121
libtcc_extra_include_path = None
2222
libtcc_extra_lib_path = None
23-
libtcc_extra_lib_name = None
23+
libtcc_extra_lib_names = None
2424
if system in ["Linux", "Darwin"]:
2525
libtcc_extra_include_path = os.path.join(libtcc_dir, "tcc", "include")
2626
libtcc_extra_lib_path = os.path.join(libtcc_dir, "tcc")
27-
libtcc_extra_lib_name = "libtcc1.a"
27+
libtcc_extra_lib_names = ["libtcc1.a", "m"]
2828

2929
# Define types
3030
TCCState = ctypes.c_void_p
@@ -82,9 +82,10 @@ def create_state(self):
8282
== -1
8383
):
8484
raise Exception("Failed to add extra library path")
85-
if libtcc_extra_lib_name:
86-
if self.libtcc.tcc_add_library(state, libtcc_extra_lib_name.encode()) == -1:
87-
raise Exception("Failed to add extra library")
85+
if libtcc_extra_lib_names:
86+
for name in libtcc_extra_lib_names:
87+
if self.libtcc.tcc_add_library(state, name.encode()) == -1:
88+
raise Exception("Failed to add extra library")
8889

8990
self.states.append(state)
9091

tests/test_nlp.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ def con(vars):
157157

158158

159159
if __name__ == "__main__":
160-
test_ipopt(ipopt.Model)
161-
test_nlp_param(ipopt.Model)
162-
test_nlfunc_ifelse(ipopt.Model)
160+
def c():
161+
return ipopt.Model(jit="C")
162+
test_ipopt(c)
163+
test_nlp_param(c)
164+
test_nlfunc_ifelse(c)

0 commit comments

Comments
 (0)