From 0365b59188029dbc9070f16674c2dee13ccac4fc Mon Sep 17 00:00:00 2001 From: Christophe Favergeon Date: Mon, 15 Nov 2021 14:22:24 +0100 Subject: [PATCH] CMSIS-DSP: Python wrapper update New function arm_mat_mult_opt_q31 added to the wrapper. --- PythonWrapper/cmsisdsp_pkg/src/cmsismodule.h | 39 ++++++++++++++++++++ PythonWrapper/testdsp2.py | 17 +++++++-- 2 files changed, 52 insertions(+), 4 deletions(-) diff --git a/PythonWrapper/cmsisdsp_pkg/src/cmsismodule.h b/PythonWrapper/cmsisdsp_pkg/src/cmsismodule.h index b59a7253..cae19b20 100644 --- a/PythonWrapper/cmsisdsp_pkg/src/cmsismodule.h +++ b/PythonWrapper/cmsisdsp_pkg/src/cmsismodule.h @@ -7400,6 +7400,44 @@ cmsis_arm_mat_mult_q31(PyObject *obj, PyObject *args) return(NULL); } +static PyObject * +cmsis_arm_mat_mult_opt_q31(PyObject *obj, PyObject *args) +{ + + PyObject *pSrcA=NULL; // input + arm_matrix_instance_q31 *pSrcA_converted=NULL; // input + PyObject *pSrcB=NULL; // input + arm_matrix_instance_q31 *pSrcB_converted=NULL; // input + PyObject *pState=NULL; // input + q31_t *pState_converted=NULL; // input + + if (PyArg_ParseTuple(args,"OOO",&pSrcA,&pSrcB,&pState)) + { + + arm_matrix_instance_q31 *pSrcA_converted = q31MatrixFromNumpy(pSrcA); + arm_matrix_instance_q31 *pSrcB_converted = q31MatrixFromNumpy(pSrcB); + + GETARGUMENT(pState,NPY_INT32,int32_t,int32_t); + uint32_t row = pSrcA_converted->numRows ; + uint32_t column = pSrcB_converted->numCols ; + arm_matrix_instance_q31 *pDst_converted = createq31Matrix(row,column); + + arm_status returnValue = arm_mat_mult_opt_q31(pSrcA_converted,pSrcB_converted,pDst_converted,pState_converted); + PyObject* theReturnOBJ=Py_BuildValue("i",returnValue); + PyObject* pDstOBJ=NumpyArrayFromq31Matrix(pDst_converted); + + PyObject *pythonResult = Py_BuildValue("OO",theReturnOBJ,pDstOBJ); + + Py_DECREF(theReturnOBJ); + FREEARGUMENT(pSrcA_converted); + FREEARGUMENT(pSrcB_converted); + Py_DECREF(pDstOBJ); + FREEARGUMENT(pState_converted); + return(pythonResult); + + } + return(NULL); +} static PyObject * cmsis_arm_mat_mult_fast_q31(PyObject *obj, PyObject *args) @@ -17594,6 +17632,7 @@ static PyMethodDef CMSISMLMethods[] = { {"arm_mat_mult_q15", cmsis_arm_mat_mult_q15, METH_VARARGS,""}, {"arm_mat_mult_fast_q15", cmsis_arm_mat_mult_fast_q15, METH_VARARGS,""}, {"arm_mat_mult_q31", cmsis_arm_mat_mult_q31, METH_VARARGS,""}, +{"arm_mat_mult_opt_q31", cmsis_arm_mat_mult_opt_q31, METH_VARARGS,""}, {"arm_mat_mult_fast_q31", cmsis_arm_mat_mult_fast_q31, METH_VARARGS,""}, {"arm_mat_sub_f32", cmsis_arm_mat_sub_f32, METH_VARARGS,""}, {"arm_mat_sub_q15", cmsis_arm_mat_sub_q15, METH_VARARGS,""}, diff --git a/PythonWrapper/testdsp2.py b/PythonWrapper/testdsp2.py index 99886f85..0a56bf32 100755 --- a/PythonWrapper/testdsp2.py +++ b/PythonWrapper/testdsp2.py @@ -162,6 +162,7 @@ print(c[1]) printSubTitle("Fixed point") +printSubTitle(" F32") normalizationFactor=2.0*np.sqrt(np.max(np.abs(c[1]))) a = a / normalizationFactor b = b / normalizationFactor @@ -171,9 +172,16 @@ print(c[1]) print("") af = f.toQ31(a) bf = f.toQ31(b) -c = dsp.arm_mat_mult_q31(af,bf) -print(f.Q31toF32(c[1])) +nbSamples = a.size +tmp=np.zeros(nbSamples) +c1 = dsp.arm_mat_mult_q31(af,bf) +c2 = dsp.arm_mat_mult_opt_q31(af,bf,tmp) +printSubTitle(" Q31") +print(f.Q31toF32(c1[1])) +print(f.Q31toF32(c2[1])) + +printSubTitle(" Q15") print("") af = f.toQ15(a) bf = f.toQ15(b) @@ -183,6 +191,7 @@ tmp=np.zeros(nb) c = dsp.arm_mat_mult_q15(af,bf,tmp) print(f.Q15toF32(c[1])) +printSubTitle(" Q7") print("") af = f.toQ7(a) bf = f.toQ7(b) @@ -304,7 +313,7 @@ NBSAMPLES=10 printSubTitle("u32") su32A=genBitvectors(NBSAMPLES,31) su32B=genBitvectors(NBSAMPLES,31) -ffff = (np.ones(NBSAMPLES)*(-1)).astype(np.int) +ffff = (np.ones(NBSAMPLES)*(-1)).astype(int) ref=np.bitwise_and(su32A, su32B) @@ -331,7 +340,7 @@ printSubTitle("u16") su16A=genBitvectors(NBSAMPLES,15) su16B=genBitvectors(NBSAMPLES,15) -ffff = (np.ones(NBSAMPLES)*(-1)).astype(np.int) +ffff = (np.ones(NBSAMPLES)*(-1)).astype(int) ref=np.bitwise_and(su16A, su16B)