Skip to content

Commit

Permalink
Merge pull request #122 from jepler/circuitpy-is-int
Browse files Browse the repository at this point in the history
Updates needed to build latest code on CircuitPython
  • Loading branch information
jepler authored Jun 1, 2020
2 parents 79f4247 + cbdd129 commit 0394801
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
10 changes: 5 additions & 5 deletions code/approx.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
const mp_obj_float_t xtolerance = {{&mp_type_float}, 2.4e-7};
const mp_obj_float_t rtolerance = {{&mp_type_float}, 0.0};

mp_float_t approx_python_call(const mp_obj_type_t *type, mp_obj_t fun, mp_float_t x, mp_obj_t *fargs, uint8_t nparams) {
STATIC mp_float_t approx_python_call(const mp_obj_type_t *type, mp_obj_t fun, mp_float_t x, mp_obj_t *fargs, uint8_t nparams) {
// Helper function for calculating the value of f(x, a, b, c, ...),
// where f is defined in python. Takes a float, returns a float.
// The array of mp_obj_t type must be supplied, as must the number of parameters (a, b, c...) in nparams
fargs[0] = mp_obj_new_float(x);
return mp_obj_get_float(type->call(fun, nparams+1, 0, fargs));
}

mp_obj_t approx_bisect(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
STATIC mp_obj_t approx_bisect(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
// Simple bisection routine
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_rom_obj = mp_const_none } },
Expand Down Expand Up @@ -75,7 +75,7 @@ mp_obj_t approx_bisect(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_arg

MP_DEFINE_CONST_FUN_OBJ_KW(approx_bisect_obj, 3, approx_bisect);

mp_obj_t approx_newton(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
STATIC mp_obj_t approx_newton(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
// this is actually the secant method, as the first derivative of the function
// is not accepted as an argument. The function whose root we want to solve for
// must depend on a single variable without parameters, i.e., f(x)
Expand Down Expand Up @@ -113,7 +113,7 @@ mp_obj_t approx_newton(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_arg

MP_DEFINE_CONST_FUN_OBJ_KW(approx_newton_obj, 2, approx_newton);

mp_obj_t approx_fmin(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
STATIC mp_obj_t approx_fmin(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
// downhill simplex method in 1D
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_rom_obj = mp_const_none } },
Expand Down Expand Up @@ -311,7 +311,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(approx_curve_fit_obj, 2, approx_curve_fit);

#endif

mp_obj_t approx_interp(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
STATIC mp_obj_t approx_interp(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_rom_obj = mp_const_none } },
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_rom_obj = mp_const_none } },
Expand Down
1 change: 1 addition & 0 deletions code/ndarray.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#if CIRCUITPY
#define mp_obj_is_bool(o) (MP_OBJ_IS_TYPE((o), &mp_type_bool))
#define mp_obj_is_int(x) (MP_OBJ_IS_INT((x)))
#else
#define translate(x) MP_ERROR_TEXT(x)
#endif
Expand Down
2 changes: 2 additions & 0 deletions code/vectorise.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ static mp_obj_t vectorise_arctan2(mp_obj_t x, mp_obj_t y) {
MP_DEFINE_CONST_FUN_OBJ_2(vectorise_arctan2_obj, vectorise_arctan2);

static mp_obj_t vectorise_vectorized_function_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
(void) n_args;
(void) n_kw;
vectorized_function_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_obj_t avalue[1];
mp_obj_t fvalue;
Expand Down

0 comments on commit 0394801

Please sign in to comment.