From a4c0c0b90fd716c18f9a48b45c3bd662ca60067a Mon Sep 17 00:00:00 2001 From: Harald Milz Date: Thu, 5 Dec 2024 13:21:20 +0100 Subject: [PATCH] compile unix double-precision, select integrations algos --- build.sh | 4 ++-- code/micropython.mk | 3 +++ code/scipy/integrate/integrate.c | 10 +++++++++- code/scipy/integrate/integrate.h | 2 +- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/build.sh b/build.sh index 7927d4a..47f777d 100755 --- a/build.sh +++ b/build.sh @@ -59,8 +59,8 @@ fi bash test-common.sh "${dims}" "$PROG" -# Build with single-precision float. -make -C micropython/ports/unix -j${NPROC} USER_C_MODULES="${HERE}" DEBUG=1 STRIP=: MICROPY_PY_FFI=0 MICROPY_PY_BTREE=0 CFLAGS_EXTRA=-DMICROPY_FLOAT_IMPL=MICROPY_FLOAT_IMPL_FLOAT CFLAGS_EXTRA+=-DULAB_MAX_DIMS=$dims CFLAGS_EXTRA+=-DULAB_HASH=$GIT_HASH BUILD=build-nanbox-$dims PROG=micropython-nanbox-$dims +# Build with double-precision float. +make -C micropython/ports/unix -j${NPROC} USER_C_MODULES="${HERE}" DEBUG=1 STRIP=: MICROPY_PY_FFI=0 MICROPY_PY_BTREE=0 CFLAGS_EXTRA=-DMICROPY_FLOAT_IMPL=MICROPY_FLOAT_IMPL_DOUBLE CFLAGS_EXTRA+=-DULAB_MAX_DIMS=$dims CFLAGS_EXTRA+=-DULAB_HASH=$GIT_HASH BUILD=build-nanbox-$dims PROG=micropython-nanbox-$dims # The unix nanbox variant builds as a 32-bit executable and requires gcc-multilib. # macOS doesn't support i386 builds so only build on linux. diff --git a/code/micropython.mk b/code/micropython.mk index 4aa6f61..98c1c99 100644 --- a/code/micropython.mk +++ b/code/micropython.mk @@ -2,6 +2,9 @@ USERMODULES_DIR := $(USERMOD_DIR) # Add all C files to SRC_USERMOD. +#if ULAB_SCIPY_HAS_INTEGRATE_MODULE +SRC_USERMOD += $(USERMODULES_DIR)/scipy/integrate/integrate.c +#endif SRC_USERMOD += $(USERMODULES_DIR)/scipy/linalg/linalg.c SRC_USERMOD += $(USERMODULES_DIR)/scipy/optimize/optimize.c SRC_USERMOD += $(USERMODULES_DIR)/scipy/signal/signal.c diff --git a/code/scipy/integrate/integrate.c b/code/scipy/integrate/integrate.c index f9de7e9..7186469 100644 --- a/code/scipy/integrate/integrate.c +++ b/code/scipy/integrate/integrate.c @@ -1,5 +1,5 @@ /* - * This file is not part of the micropython-ulab project, + * This file is part of the micropython-ulab project, * * https://github.com/v923z/micropython-ulab * @@ -261,9 +261,11 @@ static mp_obj_t integrate_quad(size_t n_args, const mp_obj_t *pos_args, mp_map_t mp_float_t a = mp_obj_get_float(args[1].u_obj); mp_float_t b = mp_obj_get_float(args[2].u_obj); uint16_t n = (uint16_t)args[3].u_int; +#if 0 if(n < 0) { mp_raise_ValueError(MP_ERROR_TEXT("levels should be > 0")); } +#endif mp_float_t eps = mp_obj_get_float(args[4].u_obj); mp_obj_t res[2]; @@ -355,9 +357,11 @@ static mp_obj_t integrate_romberg(size_t n_args, const mp_obj_t *pos_args, mp_ma mp_float_t a = mp_obj_get_float(args[1].u_obj); mp_float_t b = mp_obj_get_float(args[2].u_obj); uint16_t steps = (uint16_t)args[3].u_int; +# if 0 if(steps < 0) { mp_raise_ValueError(MP_ERROR_TEXT("steps should be > 0")); } +#endif mp_float_t eps = mp_obj_get_float(args[4].u_obj); return mp_obj_new_float(qromb(fun, a, b, steps, eps)); @@ -442,9 +446,11 @@ static mp_obj_t integrate_simpson(size_t n_args, const mp_obj_t *pos_args, mp_ma mp_float_t a = mp_obj_get_float(args[1].u_obj); mp_float_t b = mp_obj_get_float(args[2].u_obj); uint16_t steps = (uint16_t)args[3].u_int; +#if 0 if(steps < 0) { mp_raise_ValueError(MP_ERROR_TEXT("steps should be > 0")); } +#endif mp_float_t eps = mp_obj_get_float(args[4].u_obj); return mp_obj_new_float(qasi(fun, a, b, steps, eps)); @@ -606,9 +612,11 @@ static mp_obj_t integrate_quadgk(size_t n_args, const mp_obj_t *pos_args, mp_map mp_float_t a = mp_obj_get_float(args[1].u_obj); mp_float_t b = mp_obj_get_float(args[2].u_obj); uint16_t order = (uint16_t)args[3].u_int; +#if 0 if(order < 0) { mp_raise_ValueError(MP_ERROR_TEXT("levels should be > 0")); } +#endif mp_float_t eps = mp_obj_get_float(args[4].u_obj); mp_obj_t res[2]; diff --git a/code/scipy/integrate/integrate.h b/code/scipy/integrate/integrate.h index d2ef4e3..1dd42cc 100644 --- a/code/scipy/integrate/integrate.h +++ b/code/scipy/integrate/integrate.h @@ -1,6 +1,6 @@ /* - * This file is not part of the micropython-ulab project, + * This file is part of the micropython-ulab project, * * https://github.com/v923z/micropython-ulab *