Skip to content

Commit

Permalink
Merge pull request #617 from jepler/sinc-function
Browse files Browse the repository at this point in the history
ulab.numpy: implement sinc for creating audio filters
  • Loading branch information
jepler committed May 16, 2023
2 parents ac2e995 + f3e6e1c commit 6619c20
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 2 deletions.
3 changes: 3 additions & 0 deletions code/numpy/numpy.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,9 @@ static const mp_rom_map_elem_t ulab_numpy_globals_table[] = {
#if ULAB_NUMPY_HAS_SIN
{ MP_ROM_QSTR(MP_QSTR_sin), MP_ROM_PTR(&vector_sin_obj) },
#endif
#if ULAB_NUMPY_HAS_SINC
{ MP_ROM_QSTR(MP_QSTR_sinc), MP_ROM_PTR(&vector_sinc_obj) },
#endif
#if ULAB_NUMPY_HAS_SINH
{ MP_ROM_QSTR(MP_QSTR_sinh), MP_ROM_PTR(&vector_sinh_obj) },
#endif
Expand Down
21 changes: 21 additions & 0 deletions code/numpy/vector.c
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,27 @@ MATH_FUN_1(sin, sin);
MP_DEFINE_CONST_FUN_OBJ_1(vector_sin_obj, vector_sin);
#endif

#if ULAB_NUMPY_HAS_SINC
//| def sinc(a: _ArrayLike) -> ulab.numpy.ndarray:
//| """Computes the normalized sinc function"""
//| ...
//|

static mp_float_t ulab_sinc1(mp_float_t x) {
if (fpclassify(x) == FP_ZERO) {
return MICROPY_FLOAT_CONST(1.);
}
x *= MP_PI;
return MICROPY_FLOAT_C_FUN(sin)(x) / x;
}

static mp_obj_t vector_sinc(mp_obj_t x_obj) {
return vector_generic_vector(x_obj, ulab_sinc1);
}

MP_DEFINE_CONST_FUN_OBJ_1(vector_sinc_obj, vector_sinc);
#endif

#if ULAB_NUMPY_HAS_SINH
//| def sinh(a: _ArrayLike) -> ulab.numpy.ndarray:
//| """Computes the hyperbolic sine"""
Expand Down
1 change: 1 addition & 0 deletions code/numpy/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ MP_DECLARE_CONST_FUN_OBJ_1(vector_log10_obj);
MP_DECLARE_CONST_FUN_OBJ_1(vector_log2_obj);
MP_DECLARE_CONST_FUN_OBJ_1(vector_radians_obj);
MP_DECLARE_CONST_FUN_OBJ_1(vector_sin_obj);
MP_DECLARE_CONST_FUN_OBJ_1(vector_sinc_obj);
MP_DECLARE_CONST_FUN_OBJ_1(vector_sinh_obj);
#if ULAB_SUPPORTS_COMPLEX
MP_DECLARE_CONST_FUN_OBJ_KW(vector_sqrt_obj);
Expand Down
4 changes: 4 additions & 0 deletions code/ulab.h
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,10 @@
#define ULAB_NUMPY_HAS_SIN (1)
#endif

#ifndef ULAB_NUMPY_HAS_SINC
#define ULAB_NUMPY_HAS_SINC (1)
#endif

#ifndef ULAB_NUMPY_HAS_SINH
#define ULAB_NUMPY_HAS_SINH (1)
#endif
Expand Down
3 changes: 1 addition & 2 deletions requirements_cp_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@ myst-parser

# For stubs and annotations
adafruit-circuitpython-typing


build

0 comments on commit 6619c20

Please sign in to comment.