Skip to content

Commit 5cbeace

Browse files
committedFeb 22, 2015
py: Make math special functions configurable and disabled by default.
The implementation of these functions is very large (order 4k) and they are rarely used, so we don't enable them by default. They are however enabled in stmhal and unix, since we have the room.
1 parent 9ab94c4 commit 5cbeace

File tree

5 files changed

+13
-0
lines changed

5 files changed

+13
-0
lines changed
 

‎py/modmath.c

+4
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ MATH_FUN_1_TO_BOOL(isnan, isnan)
120120
MATH_FUN_1_TO_INT(trunc, trunc)
121121
/// \function ldexp(x, exp)
122122
MATH_FUN_2(ldexp, ldexp)
123+
#if MICROPY_PY_MATH_SPECIAL_FUNCTIONS
123124
/// \function erf(x)
124125
/// Return the error function of `x`.
125126
MATH_FUN_1(erf, erf)
@@ -132,6 +133,7 @@ MATH_FUN_1(gamma, tgamma)
132133
/// \function lgamma(x)
133134
/// return the natural logarithm of the gamma function of `x`.
134135
MATH_FUN_1(lgamma, lgamma)
136+
#endif
135137
//TODO: factorial, fsum
136138

137139
// Functions that return a tuple
@@ -211,10 +213,12 @@ STATIC const mp_map_elem_t mp_module_math_globals_table[] = {
211213
{ MP_OBJ_NEW_QSTR(MP_QSTR_trunc), (mp_obj_t)&mp_math_trunc_obj },
212214
{ MP_OBJ_NEW_QSTR(MP_QSTR_radians), (mp_obj_t)&mp_math_radians_obj },
213215
{ MP_OBJ_NEW_QSTR(MP_QSTR_degrees), (mp_obj_t)&mp_math_degrees_obj },
216+
#if MICROPY_PY_MATH_SPECIAL_FUNCTIONS
214217
{ MP_OBJ_NEW_QSTR(MP_QSTR_erf), (mp_obj_t)&mp_math_erf_obj },
215218
{ MP_OBJ_NEW_QSTR(MP_QSTR_erfc), (mp_obj_t)&mp_math_erfc_obj },
216219
{ MP_OBJ_NEW_QSTR(MP_QSTR_gamma), (mp_obj_t)&mp_math_gamma_obj },
217220
{ MP_OBJ_NEW_QSTR(MP_QSTR_lgamma), (mp_obj_t)&mp_math_lgamma_obj },
221+
#endif
218222
};
219223

220224
STATIC MP_DEFINE_CONST_DICT(mp_module_math_globals, mp_module_math_globals_table);

‎py/mpconfig.h

+5
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,11 @@ typedef double mp_float_t;
419419
#define MICROPY_PY_MATH (1)
420420
#endif
421421

422+
// Whether to provide special math functions: math.{erf,erfc,gamma,lgamma}
423+
#ifndef MICROPY_PY_MATH_SPECIAL_FUNCTIONS
424+
#define MICROPY_PY_MATH_SPECIAL_FUNCTIONS (0)
425+
#endif
426+
422427
// Whether to provide "cmath" module
423428
#ifndef MICROPY_PY_CMATH
424429
#define MICROPY_PY_CMATH (0)

‎py/qstrdefs.h

+2
Original file line numberDiff line numberDiff line change
@@ -363,11 +363,13 @@ Q(frexp)
363363
Q(ldexp)
364364
Q(degrees)
365365
Q(radians)
366+
#if MICROPY_PY_MATH_SPECIAL_FUNCTIONS
366367
Q(erf)
367368
Q(erfc)
368369
Q(gamma)
369370
Q(lgamma)
370371
#endif
372+
#endif
371373

372374
#if MICROPY_PY_CMATH
373375
Q(cmath)

‎stmhal/mpconfigport.h

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
#define MICROPY_PY_MICROPYTHON_MEM_INFO (1)
6262
#define MICROPY_PY_SYS_EXIT (1)
6363
#define MICROPY_PY_SYS_STDFILES (1)
64+
#define MICROPY_PY_MATH_SPECIAL_FUNCTIONS (1)
6465
#define MICROPY_PY_CMATH (1)
6566
#define MICROPY_PY_IO (1)
6667
#define MICROPY_PY_IO_FILEIO (1)

‎unix/mpconfigport.h

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
#define MICROPY_PY_SYS_PLATFORM "linux"
6565
#define MICROPY_PY_SYS_MAXSIZE (1)
6666
#define MICROPY_PY_SYS_STDFILES (1)
67+
#define MICROPY_PY_MATH_SPECIAL_FUNCTIONS (1)
6768
#define MICROPY_PY_CMATH (1)
6869
#define MICROPY_PY_IO_FILEIO (1)
6970
#define MICROPY_PY_GC_COLLECT_RETVAL (1)

0 commit comments

Comments
 (0)
Please sign in to comment.