From b416800e177492b428b2f4161139d2ffa4cc1eb2 Mon Sep 17 00:00:00 2001 From: Christophe Favergeon Date: Tue, 30 Aug 2022 09:42:29 +0200 Subject: [PATCH] Updated Python wrapper with new accumulate functions --- .../cmsisdsp_pkg/src/cmsisdsp_statistics.c | 58 +++++++++++++++++++ PythonWrapper/examples/example_1_6.py | 23 ++++++++ cmsisdsp/__init__.py | 4 +- cmsisdsp/version.py | 2 +- 4 files changed, 84 insertions(+), 3 deletions(-) create mode 100644 PythonWrapper/examples/example_1_6.py diff --git a/PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_statistics.c b/PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_statistics.c index 38745f24..e15c9fb4 100755 --- a/PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_statistics.c +++ b/PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_statistics.c @@ -1922,6 +1922,34 @@ cmsis_arm_entropy_f32(PyObject *obj, PyObject *args) return(NULL); } +static PyObject * +cmsis_arm_accumulate_f32(PyObject *obj, PyObject *args) +{ + + PyObject *pSrc=NULL; // input + float32_t *pSrc_converted=NULL; // input + uint32_t blockSize; // input + float32_t pResult; // output + + if (PyArg_ParseTuple(args,"O",&pSrc)) + { + + GETARGUMENT(pSrc,NPY_DOUBLE,double,float32_t); + blockSize = arraySizepSrc ; + + arm_accumulate_f32(pSrc_converted,blockSize,&pResult); + PyObject* pResultOBJ=Py_BuildValue("f",pResult); + + PyObject *pythonResult = Py_BuildValue("O",pResultOBJ); + + FREEARGUMENT(pSrc_converted); + Py_DECREF(pResultOBJ); + return(pythonResult); + + } + return(NULL); +} + static PyObject * cmsis_arm_entropy_f64(PyObject *obj, PyObject *args) { @@ -1950,6 +1978,34 @@ cmsis_arm_entropy_f64(PyObject *obj, PyObject *args) return(NULL); } +static PyObject * +cmsis_arm_accumulate_f64(PyObject *obj, PyObject *args) +{ + + PyObject *pSrc=NULL; // input + float64_t *pSrc_converted=NULL; // input + uint32_t blockSize; // input + float64_t pResult; // output + + if (PyArg_ParseTuple(args,"O",&pSrc)) + { + + GETARGUMENT(pSrc,NPY_DOUBLE,double,float64_t); + blockSize = arraySizepSrc ; + + arm_accumulate_f64(pSrc_converted,blockSize,&pResult); + PyObject* pResultOBJ=Py_BuildValue("d",pResult); + + PyObject *pythonResult = Py_BuildValue("O",pResultOBJ); + + FREEARGUMENT(pSrc_converted); + Py_DECREF(pResultOBJ); + return(pythonResult); + + } + return(NULL); +} + static PyObject * cmsis_arm_kullback_leibler_f32(PyObject *obj, PyObject *args) { @@ -2345,6 +2401,8 @@ static PyMethodDef CMSISDSPMethods[] = { {"arm_mse_q31", cmsis_arm_mse_q31, METH_VARARGS,""}, {"arm_mse_f32", cmsis_arm_mse_f32, METH_VARARGS,""}, {"arm_mse_f64", cmsis_arm_mse_f64, METH_VARARGS,""}, +{"arm_accumulate_f32", cmsis_arm_accumulate_f32, METH_VARARGS,""}, +{"arm_accumulate_f64", cmsis_arm_accumulate_f64, METH_VARARGS,""}, {"error_out", (PyCFunction)error_out, METH_NOARGS, NULL}, diff --git a/PythonWrapper/examples/example_1_6.py b/PythonWrapper/examples/example_1_6.py new file mode 100644 index 00000000..5f374c3b --- /dev/null +++ b/PythonWrapper/examples/example_1_6.py @@ -0,0 +1,23 @@ +# New functions for version 1.5 of the Python wrapper +import cmsisdsp as dsp +import cmsisdsp.fixedpoint as f +import numpy as np +import math +import colorama +from colorama import init,Fore, Back, Style +from numpy.testing import assert_allclose + + +NBSAMPLES=256 + +data1=np.random.randn(NBSAMPLES) + +ref = np.sum(data1) +#print(ref) +t = dsp.arm_accumulate_f64(data1) +#print(t) +assert_allclose(ref,t) + +t = dsp.arm_accumulate_f32(data1) +#print(t) +assert_allclose(ref,t,rtol=2e-6) \ No newline at end of file diff --git a/cmsisdsp/__init__.py b/cmsisdsp/__init__.py index 3ce5fe09..5df9cbc2 100755 --- a/cmsisdsp/__init__.py +++ b/cmsisdsp/__init__.py @@ -19,11 +19,11 @@ from cmsisdsp_svm import * __version__ = cmsisdsp.version.__version__ # CMSIS-DSP Version used to build the wrapper -cmsis_dsp_version="1.10.2" +cmsis_dsp_version="1.12.0" # CMSIS-DSP Commit hash used to build the wrapper -commit_hash="91f599c052d9790d55210981526e9f607bb85cd2" +commit_hash="7a8b3da85e97808b6b467377c93d447cfa6a6a6d" # True if development version of CMSIS-DSP used # (So several CMSIS-DSP versions may have same version number hence the commit hash) diff --git a/cmsisdsp/version.py b/cmsisdsp/version.py index 0f228f25..e4adfb83 100755 --- a/cmsisdsp/version.py +++ b/cmsisdsp/version.py @@ -1 +1 @@ -__version__ = "1.5.1" +__version__ = "1.6.0"