Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ulab.numpy: implement sinc for creating audio filters #617

Merged
merged 3 commits into from
May 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading