Skip to content

Commit

Permalink
CMSIS-DSP:New feature for issue ARM-software#1129 (PythonWrapper)
Browse files Browse the repository at this point in the history
  • Loading branch information
christophe0606 committed Feb 18, 2021
1 parent a78bcf9 commit d08d049
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
20 changes: 20 additions & 0 deletions CMSIS/DSP/PythonWrapper/cmsisdsp_pkg/src/cmsismodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,26 @@ CREATEMATRIX(f64,float64_t);
CREATEMATRIX(q31,q31_t);
CREATEMATRIX(q15,q15_t);

#define NUMPYVECTORFROMBUFFER(EXT,CTYPE,NUMPYTYPE_FROMC) \
PyObject *NumpyVectorFrom##EXT##Buffer(CTYPE *ptr,int nb) \
{ \
npy_intp dims[1]; \
const int ND=1; \
dims[0]=nb; \
\
void *pDst=PyMem_Malloc(sizeof(CTYPE) *nb); \
memcpy((void*)pDst,(void*)ptr,sizeof(CTYPE)*nb); \
\
PyObject *OBJ=PyArray_SimpleNewFromData(ND, dims, NUMPYTYPE_FROMC, pDst);\
PyObject *pythonResult = Py_BuildValue("O",OBJ); \
Py_DECREF(OBJ); \
return(pythonResult); \
}

NUMPYVECTORFROMBUFFER(f32,float32_t,NPY_FLOAT);



#define NUMPYARRAYFROMMATRIX(EXT,NUMPYTYPE_FROMC) \
PyObject *NumpyArrayFrom##EXT##Matrix(arm_matrix_instance_##EXT *mat) \
{ \
Expand Down
8 changes: 7 additions & 1 deletion CMSIS/DSP/PythonWrapper/cmsisdsp_pkg/src/cmsismodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -3922,11 +3922,17 @@ if (PyArg_ParseTupleAndKeywords(args, kwds, "|i", kwlist,&self->instance->numSta

GETFIELD(arm_biquad_cascade_df2T_instance_f32,numStages,"i");

static PyObject *
Method_arm_biquad_cascade_df2T_instance_f32_state(ml_arm_biquad_cascade_df2T_instance_f32Object *self, PyObject *ignored)
{
float32_t *state=self->instance->pState;
return(NumpyVectorFromf32Buffer(state,self->instance->numStages * 2));
}

static PyMethodDef arm_biquad_cascade_df2T_instance_f32_methods[] = {

{"numStages", (PyCFunction) Method_arm_biquad_cascade_df2T_instance_f32_numStages,METH_NOARGS,"numStages"},

{"state", (PyCFunction) Method_arm_biquad_cascade_df2T_instance_f32_state,METH_NOARGS,"state"},
{NULL} /* Sentinel */
};

Expand Down

0 comments on commit d08d049

Please sign in to comment.