CMSIS-DSP: Scalar version for arm_vlog_q31
Added scalar version of arm_vlog_q15
Updated PythonWrapper with vlog q31 and q15
Corrected small compilation issue with AC5 compiler.
diff --git a/CMSIS/DSP/PythonWrapper/README.md b/CMSIS/DSP/PythonWrapper/README.md
index 52f23f3..d032a68 100644
--- a/CMSIS/DSP/PythonWrapper/README.md
+++ b/CMSIS/DSP/PythonWrapper/README.md
@@ -66,6 +66,17 @@
Then you can copy the scripts testdsp.py and example.py and try to run them from this virtual environment. example.y is requiring a data file to be downloaded from the web. See below in this document for the link.
+It is also possible to compile and install directly from a Jupyter notebook by doing something like:
+
+ !pip install git+https://github.com/ARM-software/
+ CMSIS_5.git@5.8.0#egg=CMSISDSP\&subdirectory=CMSIS/DSP/PythonWrapper
+
+This will download, compile and install the PythonWrapper from the version 5.8.0 of the CMSIS-DSP (so not from the develop branch).
+
+It will work only if the compiler can be found and run from Jupyter.
+
+Note that due to the great number of possible configurations (OS, Compiler, Python), we can't give any support if you have problems compiling the PythonWrapper on your specific configuration. But, generally people manage to do it and solve all the problems.
+
# Usage
You can look at testdsp.py and example.py for some examples.
diff --git a/CMSIS/DSP/PythonWrapper/cmsisdsp_pkg/src/cmsismodule.h b/CMSIS/DSP/PythonWrapper/cmsisdsp_pkg/src/cmsismodule.h
index af8f812..6e68116 100644
--- a/CMSIS/DSP/PythonWrapper/cmsisdsp_pkg/src/cmsismodule.h
+++ b/CMSIS/DSP/PythonWrapper/cmsisdsp_pkg/src/cmsismodule.h
@@ -9867,6 +9867,37 @@
return(NULL);
}
+static PyObject *
+cmsis_arm_vlog_q15(PyObject *obj, PyObject *args)
+{
+
+ PyObject *pSrc=NULL; // input
+ q15_t *pSrc_converted=NULL; // input
+ q15_t *pDst=NULL; // output
+ uint32_t blockSize; // input
+
+ if (PyArg_ParseTuple(args,"O",&pSrc))
+ {
+
+ GETARGUMENT(pSrc,NPY_INT16,int16_t,int16_t);
+ blockSize = arraySizepSrc ;
+
+ pDst=PyMem_Malloc(sizeof(q15_t)*blockSize);
+
+
+ arm_vlog_q15(pSrc_converted,pDst,blockSize);
+ INT16ARRAY1(pDstOBJ,blockSize,pDst);
+
+ PyObject *pythonResult = Py_BuildValue("O",pDstOBJ);
+
+ FREEARGUMENT(pSrc_converted);
+ Py_DECREF(pDstOBJ);
+ return(pythonResult);
+
+ }
+ return(NULL);
+}
+
static PyObject *
cmsis_arm_abs_q31(PyObject *obj, PyObject *args)
@@ -9899,6 +9930,37 @@
return(NULL);
}
+static PyObject *
+cmsis_arm_vlog_q31(PyObject *obj, PyObject *args)
+{
+
+ PyObject *pSrc=NULL; // input
+ q31_t *pSrc_converted=NULL; // input
+ q31_t *pDst=NULL; // output
+ uint32_t blockSize; // input
+
+ if (PyArg_ParseTuple(args,"O",&pSrc))
+ {
+
+ GETARGUMENT(pSrc,NPY_INT32,int32_t,int32_t);
+ blockSize = arraySizepSrc ;
+
+ pDst=PyMem_Malloc(sizeof(q31_t)*blockSize);
+
+
+ arm_vlog_q31(pSrc_converted,pDst,blockSize);
+ INT32ARRAY1(pDstOBJ,blockSize,pDst);
+
+ PyObject *pythonResult = Py_BuildValue("O",pDstOBJ);
+
+ FREEARGUMENT(pSrc_converted);
+ Py_DECREF(pDstOBJ);
+ return(pythonResult);
+
+ }
+ return(NULL);
+}
+
#define FLOATDIST(NAME) \
static PyObject * \
cmsis_arm_##NAME##_f32(PyObject *obj, PyObject *args) \
@@ -13700,21 +13762,25 @@
{
float32_t theta; // input
- PyObject *pSinVal=NULL; // input
- float32_t *pSinVal_converted=NULL; // input
- PyObject *pCosVal=NULL; // input
- float32_t *pCosVal_converted=NULL; // input
+ float32_t pS;
+ float32_t pC;
- if (PyArg_ParseTuple(args,"fOO",&theta,&pSinVal,&pCosVal))
+ if (PyArg_ParseTuple(args,"f",&theta))
{
- GETARGUMENT(pSinVal,NPY_DOUBLE,double,float32_t);
- GETARGUMENT(pCosVal,NPY_DOUBLE,double,float32_t);
- arm_sin_cos_f32(theta,pSinVal_converted,pCosVal_converted);
- FREEARGUMENT(pSinVal_converted);
- FREEARGUMENT(pCosVal_converted);
- Py_RETURN_NONE;
+
+ arm_sin_cos_f32(theta,&pS,&pC);
+
+ PyObject* retS=Py_BuildValue("f",pS);
+ PyObject* retC=Py_BuildValue("f",pC);
+
+ PyObject *pythonResult = Py_BuildValue("OO",retS,retC);
+
+ Py_DECREF(retS);
+ Py_DECREF(retC);
+
+ return(pythonResult);
}
return(NULL);
@@ -13726,21 +13792,23 @@
{
q31_t theta; // input
- PyObject *pSinVal=NULL; // input
- q31_t *pSinVal_converted=NULL; // input
- PyObject *pCosVal=NULL; // input
- q31_t *pCosVal_converted=NULL; // input
+ q31_t pS;
+ q31_t pC;
- if (PyArg_ParseTuple(args,"iOO",&theta,&pSinVal,&pCosVal))
+ if (PyArg_ParseTuple(args,"i",&theta))
{
- GETARGUMENT(pSinVal,NPY_INT32,int32_t,int32_t);
- GETARGUMENT(pCosVal,NPY_INT32,int32_t,int32_t);
+ arm_sin_cos_q31(theta,&pS,&pC);
+
+ PyObject* retS=Py_BuildValue("i",pS);
+ PyObject* retC=Py_BuildValue("i",pC);
- arm_sin_cos_q31(theta,pSinVal_converted,pCosVal_converted);
- FREEARGUMENT(pSinVal_converted);
- FREEARGUMENT(pCosVal_converted);
- Py_RETURN_NONE;
+ PyObject *pythonResult = Py_BuildValue("OO",retS,retC);
+
+ Py_DECREF(retS);
+ Py_DECREF(retC);
+
+ return(pythonResult);
}
return(NULL);
@@ -14686,23 +14754,21 @@
{
float32_t in; // input
- float32_t *pOut=NULL; // output
+ float32_t pOut; // output
if (PyArg_ParseTuple(args,"f",&in))
{
- pOut=PyMem_Malloc(sizeof(float32_t)*1);
-
-
- arm_status returnValue = arm_sqrt_f32(in,pOut);
+ arm_status returnValue = arm_sqrt_f32(in,&pOut);
PyObject* theReturnOBJ=Py_BuildValue("i",returnValue);
- PyObject* pOutOBJ=Py_BuildValue("f",*pOut);
+ PyObject* pOutOBJ=Py_BuildValue("f",pOut);
PyObject *pythonResult = Py_BuildValue("OO",theReturnOBJ,pOutOBJ);
Py_DECREF(theReturnOBJ);
Py_DECREF(pOutOBJ);
+
return(pythonResult);
}
@@ -14715,18 +14781,17 @@
{
q31_t in; // input
- q31_t *pOut=NULL; // output
+ q31_t pOut; // output
if (PyArg_ParseTuple(args,"i",&in))
{
- pOut=PyMem_Malloc(sizeof(q31_t)*1);
- arm_status returnValue = arm_sqrt_q31(in,pOut);
+ arm_status returnValue = arm_sqrt_q31(in,&pOut);
PyObject* theReturnOBJ=Py_BuildValue("i",returnValue);
- PyObject* pOutOBJ=Py_BuildValue("i",*pOut);
+ PyObject* pOutOBJ=Py_BuildValue("i",pOut);
PyObject *pythonResult = Py_BuildValue("OO",theReturnOBJ,pOutOBJ);
@@ -14744,18 +14809,16 @@
{
q15_t in; // input
- q15_t *pOut=NULL; // output
+ q15_t pOut; // output
if (PyArg_ParseTuple(args,"h",&in))
{
- pOut=PyMem_Malloc(sizeof(q15_t)*1);
-
- arm_status returnValue = arm_sqrt_q15(in,pOut);
+ arm_status returnValue = arm_sqrt_q15(in,&pOut);
PyObject* theReturnOBJ=Py_BuildValue("i",returnValue);
- PyObject* pOutOBJ=Py_BuildValue("h",*pOut);
+ PyObject* pOutOBJ=Py_BuildValue("h",pOut);
PyObject *pythonResult = Py_BuildValue("OO",theReturnOBJ,pOutOBJ);
@@ -16931,6 +16994,8 @@
{"arm_abs_f32", cmsis_arm_abs_f32, METH_VARARGS,""},
{"arm_abs_q15", cmsis_arm_abs_q15, METH_VARARGS,""},
{"arm_abs_q31", cmsis_arm_abs_q31, METH_VARARGS,""},
+{"arm_vlog_q15", cmsis_arm_vlog_q15, METH_VARARGS,""},
+{"arm_vlog_q31", cmsis_arm_vlog_q31, METH_VARARGS,""},
{"arm_dot_prod_f32", cmsis_arm_dot_prod_f32, METH_VARARGS,""},
{"arm_dot_prod_q7", cmsis_arm_dot_prod_q7, METH_VARARGS,""},
{"arm_dot_prod_q15", cmsis_arm_dot_prod_q15, METH_VARARGS,""},
diff --git a/CMSIS/DSP/PythonWrapper/testdsp3.py b/CMSIS/DSP/PythonWrapper/testdsp3.py
new file mode 100755
index 0000000..cc5a8f4
--- /dev/null
+++ b/CMSIS/DSP/PythonWrapper/testdsp3.py
@@ -0,0 +1,53 @@
+import cmsisdsp as dsp
+import numpy as np
+import fixedpoint as f
+
+# Test vlog q31 and q15
+x = np.array([0.9,0.5,2**-16])
+
+r=dsp.arm_vlog_q15(f.toQ15(x))
+
+print(f.Q15toF32(r)*16.0)
+
+print(np.log(x))
+
+print("")
+# Test sin_cos
+t=20
+
+sinRef=np.sin(t * np.pi / 180)
+cosRef=np.cos(t * np.pi / 180)
+print(sinRef)
+print(cosRef)
+
+s,c=dsp.arm_sin_cos_f32(t)
+print(s)
+print(c)
+
+s,c=dsp.arm_sin_cos_q31(f.toQ31(t/180.0))
+print(f.Q31toF32(s))
+print(f.Q31toF32(c))
+
+print("")
+# Test sqrt
+a=0.6
+print(np.sqrt(a))
+
+err,r=dsp.arm_sqrt_f32(a)
+print(err,r)
+
+err,r=dsp.arm_sqrt_q31(f.toQ31(a))
+print(err,f.Q31toF32(r))
+
+err,r=dsp.arm_sqrt_q15(f.toQ15(a))
+print(err,f.Q15toF32(r))
+
+err,r=dsp.arm_sqrt_f32(-a)
+print(err,r)
+
+err,r=dsp.arm_sqrt_q31(f.toQ31(-a))
+print(err,f.Q31toF32(r))
+
+err,r=dsp.arm_sqrt_q15(f.toQ15(-a))
+print(err,f.Q15toF32(r))
+