CMSIS-DSP: Python wrapper update

New function arm_mat_mult_opt_q31 added to the wrapper.
pull/19/head
Christophe Favergeon 4 years ago
parent e45dc7c22e
commit 0365b59188

@ -7400,6 +7400,44 @@ cmsis_arm_mat_mult_q31(PyObject *obj, PyObject *args)
return(NULL); 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 * static PyObject *
cmsis_arm_mat_mult_fast_q31(PyObject *obj, PyObject *args) 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_q15", cmsis_arm_mat_mult_q15, METH_VARARGS,""},
{"arm_mat_mult_fast_q15", cmsis_arm_mat_mult_fast_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_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_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_f32", cmsis_arm_mat_sub_f32, METH_VARARGS,""},
{"arm_mat_sub_q15", cmsis_arm_mat_sub_q15, METH_VARARGS,""}, {"arm_mat_sub_q15", cmsis_arm_mat_sub_q15, METH_VARARGS,""},

@ -162,6 +162,7 @@ print(c[1])
printSubTitle("Fixed point") printSubTitle("Fixed point")
printSubTitle(" F32")
normalizationFactor=2.0*np.sqrt(np.max(np.abs(c[1]))) normalizationFactor=2.0*np.sqrt(np.max(np.abs(c[1])))
a = a / normalizationFactor a = a / normalizationFactor
b = b / normalizationFactor b = b / normalizationFactor
@ -171,9 +172,16 @@ print(c[1])
print("") print("")
af = f.toQ31(a) af = f.toQ31(a)
bf = f.toQ31(b) bf = f.toQ31(b)
c = dsp.arm_mat_mult_q31(af,bf) nbSamples = a.size
print(f.Q31toF32(c[1])) 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("") print("")
af = f.toQ15(a) af = f.toQ15(a)
bf = f.toQ15(b) bf = f.toQ15(b)
@ -183,6 +191,7 @@ tmp=np.zeros(nb)
c = dsp.arm_mat_mult_q15(af,bf,tmp) c = dsp.arm_mat_mult_q15(af,bf,tmp)
print(f.Q15toF32(c[1])) print(f.Q15toF32(c[1]))
printSubTitle(" Q7")
print("") print("")
af = f.toQ7(a) af = f.toQ7(a)
bf = f.toQ7(b) bf = f.toQ7(b)
@ -304,7 +313,7 @@ NBSAMPLES=10
printSubTitle("u32") printSubTitle("u32")
su32A=genBitvectors(NBSAMPLES,31) su32A=genBitvectors(NBSAMPLES,31)
su32B=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) ref=np.bitwise_and(su32A, su32B)
@ -331,7 +340,7 @@ printSubTitle("u16")
su16A=genBitvectors(NBSAMPLES,15) su16A=genBitvectors(NBSAMPLES,15)
su16B=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) ref=np.bitwise_and(su16A, su16B)

Loading…
Cancel
Save