Skip to content

Commit 73ed8cc

Browse files
authored
Add scipy integration (#699)
* adding scipy integrate, initial check-in * compile unix double-precision, select integrations algos * bumping ulab version number to 6.7.0 * adding documentation * documentation fix * documentation fix * documentation fix * rewritten in some places * complex number error handling * added test cases * resolved importing scipy.integrate * resolved importing scipy.integrate #2 * build integrate only when we have MICROPY_FLOAT_IMPL_DOUBLE * reverting commit a4c0c0b * re-pushing failed commit * Revert "re-pushing failed commit" This reverts commit a10e89f. * improve tests using math.isclose() * enabled fp32 builds * removed conditional includes * adapted to new function names, corrected importing * function names similar to in CPython scipy.integrate, some minor corrections * major rewrite representing the name changes, mapping to CPython scipy.integrate, more background info
1 parent 303e8d7 commit 73ed8cc

File tree

9 files changed

+1306
-2
lines changed

9 files changed

+1306
-2
lines changed

code/micropython.mk

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
USERMODULES_DIR := $(USERMOD_DIR)
33

44
# Add all C files to SRC_USERMOD.
5+
SRC_USERMOD += $(USERMODULES_DIR)/scipy/integrate/integrate.c
56
SRC_USERMOD += $(USERMODULES_DIR)/scipy/linalg/linalg.c
67
SRC_USERMOD += $(USERMODULES_DIR)/scipy/optimize/optimize.c
78
SRC_USERMOD += $(USERMODULES_DIR)/scipy/signal/signal.c

code/scipy/integrate/integrate.c

+701
Large diffs are not rendered by default.

code/scipy/integrate/integrate.h

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
/*
3+
* This file is part of the micropython-ulab project,
4+
*
5+
* https://github.com/v923z/micropython-ulab
6+
*
7+
* The MIT License (MIT)
8+
*
9+
* Copyright (c) 2024 Harald Milz <[email protected]>
10+
*
11+
*/
12+
13+
#ifndef _SCIPY_INTEGRATE_
14+
#define _SCIPY_INTEGRATE_
15+
16+
#include "../../ulab_tools.h"
17+
18+
extern const mp_obj_module_t ulab_scipy_integrate_module;
19+
20+
#if ULAB_INTEGRATE_HAS_TANHSINH
21+
MP_DECLARE_CONST_FUN_OBJ_KW(optimize_tanhsinh_obj);
22+
#endif
23+
#if ULAB_INTEGRATE_HAS_ROMBERG
24+
MP_DECLARE_CONST_FUN_OBJ_KW(optimize_romberg_obj);
25+
#endif
26+
#if ULAB_INTEGRATE_HAS_SIMPSON
27+
MP_DECLARE_CONST_FUN_OBJ_KW(optimize_simpson_obj);
28+
#endif
29+
#if ULAB_INTEGRATE_HAS_QUAD
30+
MP_DECLARE_CONST_FUN_OBJ_KW(optimize_quad_obj);
31+
#endif
32+
33+
#endif /* _SCIPY_INTEGRATE_ */
34+

code/scipy/scipy.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
/*
32
* This file is part of the micropython-ulab project,
43
*
@@ -20,6 +19,8 @@
2019
#include "signal/signal.h"
2120
#include "special/special.h"
2221
#include "linalg/linalg.h"
22+
#include "integrate/integrate.h"
23+
2324

2425
#if ULAB_HAS_SCIPY
2526

@@ -28,6 +29,9 @@
2829

2930
static const mp_rom_map_elem_t ulab_scipy_globals_table[] = {
3031
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_scipy) },
32+
#if ULAB_SCIPY_HAS_INTEGRATE_MODULE
33+
{ MP_ROM_QSTR(MP_QSTR_integrate), MP_ROM_PTR(&ulab_scipy_integrate_module) },
34+
#endif
3135
#if ULAB_SCIPY_HAS_LINALG_MODULE
3236
{ MP_ROM_QSTR(MP_QSTR_linalg), MP_ROM_PTR(&ulab_scipy_linalg_module) },
3337
#endif

code/ulab.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#include "user/user.h"
3434
#include "utils/utils.h"
3535

36-
#define ULAB_VERSION 6.6.1
36+
#define ULAB_VERSION 6.7.0
3737
#define xstr(s) str(s)
3838
#define str(s) #s
3939

code/ulab.h

+22
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,28 @@
398398
#define ULAB_NUMPY_HAS_WHERE (1)
399399
#endif
400400

401+
// the integrate module; functions of the integrate module still have
402+
// to be defined separately
403+
#ifndef ULAB_SCIPY_HAS_INTEGRATE_MODULE
404+
#define ULAB_SCIPY_HAS_INTEGRATE_MODULE (1)
405+
#endif
406+
407+
#ifndef ULAB_INTEGRATE_HAS_TANHSINH
408+
#define ULAB_INTEGRATE_HAS_TANHSINH (1)
409+
#endif
410+
411+
#ifndef ULAB_INTEGRATE_HAS_ROMBERG
412+
#define ULAB_INTEGRATE_HAS_ROMBERG (1)
413+
#endif
414+
415+
#ifndef ULAB_INTEGRATE_HAS_SIMPSON
416+
#define ULAB_INTEGRATE_HAS_SIMPSON (1)
417+
#endif
418+
419+
#ifndef ULAB_INTEGRATE_HAS_QUAD
420+
#define ULAB_INTEGRATE_HAS_QUAD (1)
421+
#endif
422+
401423
// the linalg module; functions of the linalg module still have
402424
// to be defined separately
403425
#ifndef ULAB_NUMPY_HAS_LINALG_MODULE

0 commit comments

Comments
 (0)