From fb90fab3e74d9c4280b15a107b2f58ac316d308f Mon Sep 17 00:00:00 2001 From: Christophe Favergeon Date: Mon, 7 Mar 2022 11:05:01 +0100 Subject: [PATCH] CMSIS-DSP: Added missing functions to the Python wrapper Changed the version of Jinja2 required by the wrapper to avoid warnings when using google colab. --- Include/dsp/fast_math_functions.h | 12 - MANIFEST.in | 2 + .../cmsisdsp_pkg/src/cmsisdsp_basic.c | 319 ++++- .../cmsisdsp_pkg/src/cmsisdsp_bayes.c | 272 ++++ .../cmsisdsp_pkg/src/cmsisdsp_complexf.c | 146 ++- .../cmsisdsp_pkg/src/cmsisdsp_distance.c | 308 +++++ .../cmsisdsp_pkg/src/cmsisdsp_fastmath.c | 128 +- .../cmsisdsp_pkg/src/cmsisdsp_filtering.c | 179 +++ .../cmsisdsp_pkg/src/cmsisdsp_interpolation.c | 175 ++- .../cmsisdsp_pkg/src/cmsisdsp_matrix.c | 388 ++++++ .../cmsisdsp_pkg/src/cmsisdsp_module.h | 2 +- .../cmsisdsp_pkg/src/cmsisdsp_statistics.c | 1154 ++++++++++++----- .../cmsisdsp_pkg/src/cmsisdsp_support.c | 290 ++++- PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_svm.c | 695 ++++++++++ PythonWrapper/examples/testdistance.py | 185 +++ PythonWrapper/examples/testdsp5.py | 490 +++++++ PythonWrapper/examples/testdsp6.py | 185 +++ PythonWrapper_README.md | 4 +- Source/MatrixFunctions/arm_mat_ldlt_f32.c | 2 + Source/MatrixFunctions/arm_mat_ldlt_f64.c | 2 + Testing/testmain.cpp | 2 + cmsisdsp/__init__.py | 4 + cmsisdsp/version.py | 2 +- setup.py | 171 +-- 24 files changed, 4630 insertions(+), 487 deletions(-) create mode 100755 PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_bayes.c create mode 100755 PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_distance.c create mode 100755 PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_svm.c create mode 100755 PythonWrapper/examples/testdistance.py create mode 100755 PythonWrapper/examples/testdsp5.py create mode 100755 PythonWrapper/examples/testdsp6.py diff --git a/Include/dsp/fast_math_functions.h b/Include/dsp/fast_math_functions.h index 6bb4ba78..bb3172d5 100755 --- a/Include/dsp/fast_math_functions.h +++ b/Include/dsp/fast_math_functions.h @@ -309,18 +309,6 @@ arm_status arm_sqrt_q15( q15_t in, q15_t * pOut); - /** - * @brief Vector Floating-point square root function. - * @param[in] pIn input vector. - * @param[out] pOut vector of square roots of input elements. - * @param[in] len length of input vector. - * @return The function returns ARM_MATH_SUCCESS if input value is positive value or ARM_MATH_ARGUMENT_ERROR if - * in is negative value and returns zero output for negative values. - */ - void arm_vsqrt_f32( - float32_t * pIn, - float32_t * pOut, - uint16_t len); /** diff --git a/MANIFEST.in b/MANIFEST.in index 2f448c78..c05f6a46 100755 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -3,3 +3,5 @@ recursive-include Include *.h recursive-include PrivateInclude *.h recursive-include PythonWrapper/cmsisdsp_pkg/src *.h include cmsisdsp/sdf/scheduler/templates/* +include Source/DistanceFunctions/arm_boolean_distance_template.h + diff --git a/PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_basic.c b/PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_basic.c index 62f1fcf8..7024b688 100755 --- a/PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_basic.c +++ b/PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_basic.c @@ -46,7 +46,7 @@ cmsis_arm_recip_q31(PyObject *obj, PyObject *args) { q31_t in; // input - q31_t *dst=NULL; // output + q31_t dst; // output PyObject *pRecipTable=NULL; // input q31_t *pRecipTable_converted=NULL; // input @@ -55,12 +55,10 @@ cmsis_arm_recip_q31(PyObject *obj, PyObject *args) GETARGUMENT(pRecipTable,NPY_INT32,int32_t,int32_t); - dst=PyMem_Malloc(sizeof(q31_t)*1); - - uint32_t returnValue = arm_recip_q31(in,dst,pRecipTable_converted); + uint32_t returnValue = arm_recip_q31(in,&dst,pRecipTable_converted); PyObject* theReturnOBJ=Py_BuildValue("i",returnValue); - PyObject* dstOBJ=Py_BuildValue("i",*dst); + PyObject* dstOBJ=Py_BuildValue("i",dst); PyObject *pythonResult = Py_BuildValue("OO",theReturnOBJ,dstOBJ); @@ -79,7 +77,7 @@ cmsis_arm_recip_q15(PyObject *obj, PyObject *args) { q15_t in; // input - q15_t *dst=NULL; // output + q15_t dst; // output PyObject *pRecipTable=NULL; // input q15_t *pRecipTable_converted=NULL; // input @@ -88,12 +86,10 @@ cmsis_arm_recip_q15(PyObject *obj, PyObject *args) GETARGUMENT(pRecipTable,NPY_INT16,int16_t,int16_t); - dst=PyMem_Malloc(sizeof(q15_t)*1); - - uint32_t returnValue = arm_recip_q15(in,dst,pRecipTable_converted); + uint32_t returnValue = arm_recip_q15(in,&dst,pRecipTable_converted); PyObject* theReturnOBJ=Py_BuildValue("i",returnValue); - PyObject* dstOBJ=Py_BuildValue("h",*dst); + PyObject* dstOBJ=Py_BuildValue("h",dst); PyObject *pythonResult = Py_BuildValue("OO",theReturnOBJ,dstOBJ); @@ -250,6 +246,41 @@ cmsis_arm_mult_f32(PyObject *obj, PyObject *args) return(NULL); } +static PyObject * +cmsis_arm_mult_f64(PyObject *obj, PyObject *args) +{ + + PyObject *pSrcA=NULL; // input + float64_t *pSrcA_converted=NULL; // input + PyObject *pSrcB=NULL; // input + float64_t *pSrcB_converted=NULL; // input + float64_t *pDst=NULL; // output + uint32_t blockSize; // input + + if (PyArg_ParseTuple(args,"OO",&pSrcA,&pSrcB)) + { + + GETARGUMENT(pSrcA,NPY_DOUBLE,double,float64_t); + GETARGUMENT(pSrcB,NPY_DOUBLE,double,float64_t); + blockSize = arraySizepSrcA ; + + pDst=PyMem_Malloc(sizeof(float64_t)*blockSize); + + + arm_mult_f64(pSrcA_converted,pSrcB_converted,pDst,blockSize); + FLOAT64ARRAY1(pDstOBJ,blockSize,pDst); + + PyObject *pythonResult = Py_BuildValue("O",pDstOBJ); + + FREEARGUMENT(pSrcA_converted); + FREEARGUMENT(pSrcB_converted); + Py_DECREF(pDstOBJ); + return(pythonResult); + + } + return(NULL); +} + static PyObject * @@ -287,6 +318,41 @@ cmsis_arm_add_f32(PyObject *obj, PyObject *args) return(NULL); } +static PyObject * +cmsis_arm_add_f64(PyObject *obj, PyObject *args) +{ + + PyObject *pSrcA=NULL; // input + float64_t *pSrcA_converted=NULL; // input + PyObject *pSrcB=NULL; // input + float64_t *pSrcB_converted=NULL; // input + float64_t *pDst=NULL; // output + uint32_t blockSize; // input + + if (PyArg_ParseTuple(args,"OO",&pSrcA,&pSrcB)) + { + + GETARGUMENT(pSrcA,NPY_DOUBLE,double,float64_t); + GETARGUMENT(pSrcB,NPY_DOUBLE,double,float64_t); + blockSize = arraySizepSrcA ; + + pDst=PyMem_Malloc(sizeof(float64_t)*blockSize); + + + arm_add_f64(pSrcA_converted,pSrcB_converted,pDst,blockSize); + FLOAT64ARRAY1(pDstOBJ,blockSize,pDst); + + PyObject *pythonResult = Py_BuildValue("O",pDstOBJ); + + FREEARGUMENT(pSrcA_converted); + FREEARGUMENT(pSrcB_converted); + Py_DECREF(pDstOBJ); + return(pythonResult); + + } + return(NULL); +} + /* For the arm_(and|xor|or)_u(32|16|8) @@ -520,6 +586,41 @@ cmsis_arm_sub_f32(PyObject *obj, PyObject *args) return(NULL); } +static PyObject * +cmsis_arm_sub_f64(PyObject *obj, PyObject *args) +{ + + PyObject *pSrcA=NULL; // input + float64_t *pSrcA_converted=NULL; // input + PyObject *pSrcB=NULL; // input + float64_t *pSrcB_converted=NULL; // input + float64_t *pDst=NULL; // output + uint32_t blockSize; // input + + if (PyArg_ParseTuple(args,"OO",&pSrcA,&pSrcB)) + { + + GETARGUMENT(pSrcA,NPY_DOUBLE,double,float64_t); + GETARGUMENT(pSrcB,NPY_DOUBLE,double,float64_t); + blockSize = arraySizepSrcA ; + + pDst=PyMem_Malloc(sizeof(float64_t)*blockSize); + + + arm_sub_f64(pSrcA_converted,pSrcB_converted,pDst,blockSize); + FLOAT64ARRAY1(pDstOBJ,blockSize,pDst); + + PyObject *pythonResult = Py_BuildValue("O",pDstOBJ); + + FREEARGUMENT(pSrcA_converted); + FREEARGUMENT(pSrcB_converted); + Py_DECREF(pDstOBJ); + return(pythonResult); + + } + return(NULL); +} + static PyObject * cmsis_arm_sub_q7(PyObject *obj, PyObject *args) @@ -661,6 +762,38 @@ cmsis_arm_scale_f32(PyObject *obj, PyObject *args) return(NULL); } +static PyObject * +cmsis_arm_scale_f64(PyObject *obj, PyObject *args) +{ + + PyObject *pSrc=NULL; // input + float64_t *pSrc_converted=NULL; // input + float64_t scale; // input + float64_t *pDst=NULL; // output + uint32_t blockSize; // input + + if (PyArg_ParseTuple(args,"Od",&pSrc,&scale)) + { + + GETARGUMENT(pSrc,NPY_DOUBLE,double,float64_t); + blockSize = arraySizepSrc ; + + pDst=PyMem_Malloc(sizeof(float64_t)*blockSize); + + + arm_scale_f64(pSrc_converted,scale,pDst,blockSize); + FLOAT64ARRAY1(pDstOBJ,blockSize,pDst); + + PyObject *pythonResult = Py_BuildValue("O",pDstOBJ); + + FREEARGUMENT(pSrc_converted); + Py_DECREF(pDstOBJ); + return(pythonResult); + + } + return(NULL); +} + static PyObject * cmsis_arm_scale_q7(PyObject *obj, PyObject *args) @@ -827,6 +960,37 @@ cmsis_arm_abs_f32(PyObject *obj, PyObject *args) return(NULL); } +static PyObject * +cmsis_arm_abs_f64(PyObject *obj, PyObject *args) +{ + + PyObject *pSrc=NULL; // input + float64_t *pSrc_converted=NULL; // input + float64_t *pDst=NULL; // output + uint32_t blockSize; // input + + if (PyArg_ParseTuple(args,"O",&pSrc)) + { + + GETARGUMENT(pSrc,NPY_DOUBLE,double,float64_t); + blockSize = arraySizepSrc ; + + pDst=PyMem_Malloc(sizeof(float64_t)*blockSize); + + + arm_abs_f64(pSrc_converted,pDst,blockSize); + FLOAT64ARRAY1(pDstOBJ,blockSize,pDst); + + PyObject *pythonResult = Py_BuildValue("O",pDstOBJ); + + FREEARGUMENT(pSrc_converted); + Py_DECREF(pDstOBJ); + return(pythonResult); + + } + return(NULL); +} + static PyObject * cmsis_arm_abs_q15(PyObject *obj, PyObject *args) @@ -904,7 +1068,7 @@ cmsis_arm_dot_prod_f32(PyObject *obj, PyObject *args) PyObject *pSrcB=NULL; // input float32_t *pSrcB_converted=NULL; // input uint32_t blockSize; // input - float32_t *result=NULL; // output + float32_t result; // output if (PyArg_ParseTuple(args,"OO",&pSrcA,&pSrcB)) { @@ -913,11 +1077,44 @@ cmsis_arm_dot_prod_f32(PyObject *obj, PyObject *args) GETARGUMENT(pSrcB,NPY_DOUBLE,double,float32_t); blockSize = arraySizepSrcA ; - result=PyMem_Malloc(sizeof(float32_t)*1); - arm_dot_prod_f32(pSrcA_converted,pSrcB_converted,blockSize,result); - PyObject* resultOBJ=Py_BuildValue("f",*result); + arm_dot_prod_f32(pSrcA_converted,pSrcB_converted,blockSize,&result); + PyObject* resultOBJ=Py_BuildValue("f",result); + + PyObject *pythonResult = Py_BuildValue("O",resultOBJ); + + FREEARGUMENT(pSrcA_converted); + FREEARGUMENT(pSrcB_converted); + Py_DECREF(resultOBJ); + return(pythonResult); + + } + return(NULL); +} + +static PyObject * +cmsis_arm_dot_prod_f64(PyObject *obj, PyObject *args) +{ + + PyObject *pSrcA=NULL; // input + float64_t *pSrcA_converted=NULL; // input + PyObject *pSrcB=NULL; // input + float64_t *pSrcB_converted=NULL; // input + uint32_t blockSize; // input + float64_t result; // output + + if (PyArg_ParseTuple(args,"OO",&pSrcA,&pSrcB)) + { + + GETARGUMENT(pSrcA,NPY_DOUBLE,double,float64_t); + GETARGUMENT(pSrcB,NPY_DOUBLE,double,float64_t); + blockSize = arraySizepSrcA ; + + + + arm_dot_prod_f64(pSrcA_converted,pSrcB_converted,blockSize,&result); + PyObject* resultOBJ=Py_BuildValue("d",result); PyObject *pythonResult = Py_BuildValue("O",resultOBJ); @@ -940,7 +1137,7 @@ cmsis_arm_dot_prod_q7(PyObject *obj, PyObject *args) PyObject *pSrcB=NULL; // input q7_t *pSrcB_converted=NULL; // input uint32_t blockSize; // input - q31_t *result=NULL; // output + q31_t result; // output if (PyArg_ParseTuple(args,"OO",&pSrcA,&pSrcB)) { @@ -949,11 +1146,10 @@ cmsis_arm_dot_prod_q7(PyObject *obj, PyObject *args) GETARGUMENT(pSrcB,NPY_BYTE,int8_t,q7_t); blockSize = arraySizepSrcA ; - result=PyMem_Malloc(sizeof(q31_t)*1); - arm_dot_prod_q7(pSrcA_converted,pSrcB_converted,blockSize,result); - PyObject* resultOBJ=Py_BuildValue("i",*result); + arm_dot_prod_q7(pSrcA_converted,pSrcB_converted,blockSize,&result); + PyObject* resultOBJ=Py_BuildValue("i",result); PyObject *pythonResult = Py_BuildValue("O",resultOBJ); @@ -976,7 +1172,7 @@ cmsis_arm_dot_prod_q15(PyObject *obj, PyObject *args) PyObject *pSrcB=NULL; // input q15_t *pSrcB_converted=NULL; // input uint32_t blockSize; // input - q63_t *result=NULL; // output + q63_t result; // output if (PyArg_ParseTuple(args,"OO",&pSrcA,&pSrcB)) { @@ -985,11 +1181,10 @@ cmsis_arm_dot_prod_q15(PyObject *obj, PyObject *args) GETARGUMENT(pSrcB,NPY_INT16,int16_t,int16_t); blockSize = arraySizepSrcA ; - result=PyMem_Malloc(sizeof(q63_t)*1); - arm_dot_prod_q15(pSrcA_converted,pSrcB_converted,blockSize,result); - PyObject* resultOBJ=Py_BuildValue("L",*result); + arm_dot_prod_q15(pSrcA_converted,pSrcB_converted,blockSize,&result); + PyObject* resultOBJ=Py_BuildValue("L",result); PyObject *pythonResult = Py_BuildValue("O",resultOBJ); @@ -1012,7 +1207,7 @@ cmsis_arm_dot_prod_q31(PyObject *obj, PyObject *args) PyObject *pSrcB=NULL; // input q31_t *pSrcB_converted=NULL; // input uint32_t blockSize; // input - q63_t *result=NULL; // output + q63_t result; // output if (PyArg_ParseTuple(args,"OO",&pSrcA,&pSrcB)) { @@ -1021,11 +1216,10 @@ cmsis_arm_dot_prod_q31(PyObject *obj, PyObject *args) GETARGUMENT(pSrcB,NPY_INT32,int32_t,int32_t); blockSize = arraySizepSrcA ; - result=PyMem_Malloc(sizeof(q63_t)*1); - arm_dot_prod_q31(pSrcA_converted,pSrcB_converted,blockSize,result); - PyObject* resultOBJ=Py_BuildValue("L",*result); + arm_dot_prod_q31(pSrcA_converted,pSrcB_converted,blockSize,&result); + PyObject* resultOBJ=Py_BuildValue("L",result); PyObject *pythonResult = Py_BuildValue("O",resultOBJ); @@ -1299,6 +1493,38 @@ cmsis_arm_offset_f32(PyObject *obj, PyObject *args) return(NULL); } +static PyObject * +cmsis_arm_offset_f64(PyObject *obj, PyObject *args) +{ + + PyObject *pSrc=NULL; // input + float64_t *pSrc_converted=NULL; // input + float64_t offset; // input + float64_t *pDst=NULL; // output + uint32_t blockSize; // input + + if (PyArg_ParseTuple(args,"Od",&pSrc,&offset)) + { + + GETARGUMENT(pSrc,NPY_DOUBLE,double,float64_t); + blockSize = arraySizepSrc ; + + pDst=PyMem_Malloc(sizeof(float64_t)*blockSize); + + + arm_offset_f64(pSrc_converted,offset,pDst,blockSize); + FLOAT64ARRAY1(pDstOBJ,blockSize,pDst); + + PyObject *pythonResult = Py_BuildValue("O",pDstOBJ); + + FREEARGUMENT(pSrc_converted); + Py_DECREF(pDstOBJ); + return(pythonResult); + + } + return(NULL); +} + static PyObject * cmsis_arm_offset_q7(PyObject *obj, PyObject *args) @@ -1430,6 +1656,36 @@ cmsis_arm_negate_f32(PyObject *obj, PyObject *args) return(NULL); } +static PyObject * +cmsis_arm_negate_f64(PyObject *obj, PyObject *args) +{ + + PyObject *pSrc=NULL; // input + float64_t *pSrc_converted=NULL; // input + float64_t *pDst=NULL; // output + uint32_t blockSize; // input + + if (PyArg_ParseTuple(args,"O",&pSrc)) + { + + GETARGUMENT(pSrc,NPY_DOUBLE,double,float64_t); + blockSize = arraySizepSrc ; + + pDst=PyMem_Malloc(sizeof(float64_t)*blockSize); + + + arm_negate_f64(pSrc_converted,pDst,blockSize); + FLOAT64ARRAY1(pDstOBJ,blockSize,pDst); + + PyObject *pythonResult = Py_BuildValue("O",pDstOBJ); + + FREEARGUMENT(pSrc_converted); + Py_DECREF(pDstOBJ); + return(pythonResult); + + } + return(NULL); +} static PyObject * cmsis_arm_negate_q7(PyObject *obj, PyObject *args) @@ -1597,25 +1853,33 @@ static PyMethodDef CMSISDSPMethods[] = { {"arm_mult_q15", cmsis_arm_mult_q15, METH_VARARGS,""}, {"arm_mult_q31", cmsis_arm_mult_q31, METH_VARARGS,""}, {"arm_mult_f32", cmsis_arm_mult_f32, METH_VARARGS,""}, +{"arm_mult_f64", cmsis_arm_mult_f64, METH_VARARGS,""}, {"arm_add_f32", cmsis_arm_add_f32, METH_VARARGS,""}, +{"arm_add_f64", cmsis_arm_add_f64, METH_VARARGS,""}, {"arm_add_q7", cmsis_arm_add_q7, METH_VARARGS,""}, {"arm_add_q15", cmsis_arm_add_q15, METH_VARARGS,""}, {"arm_add_q31", cmsis_arm_add_q31, METH_VARARGS,""}, {"arm_sub_f32", cmsis_arm_sub_f32, METH_VARARGS,""}, +{"arm_sub_f64", cmsis_arm_sub_f64, METH_VARARGS,""}, + {"arm_sub_q7", cmsis_arm_sub_q7, METH_VARARGS,""}, {"arm_sub_q15", cmsis_arm_sub_q15, METH_VARARGS,""}, {"arm_sub_q31", cmsis_arm_sub_q31, METH_VARARGS,""}, {"arm_scale_f32", cmsis_arm_scale_f32, METH_VARARGS,""}, +{"arm_scale_f64", cmsis_arm_scale_f64, METH_VARARGS,""}, {"arm_scale_q7", cmsis_arm_scale_q7, METH_VARARGS,""}, {"arm_scale_q15", cmsis_arm_scale_q15, METH_VARARGS,""}, {"arm_scale_q31", cmsis_arm_scale_q31, METH_VARARGS,""}, {"arm_abs_q7", cmsis_arm_abs_q7, METH_VARARGS,""}, {"arm_abs_f32", cmsis_arm_abs_f32, METH_VARARGS,""}, +{"arm_abs_f64", cmsis_arm_abs_f64, METH_VARARGS,""}, {"arm_abs_q15", cmsis_arm_abs_q15, METH_VARARGS,""}, {"arm_abs_q31", cmsis_arm_abs_q31, METH_VARARGS,""}, {"arm_dot_prod_f32", cmsis_arm_dot_prod_f32, METH_VARARGS,""}, +{"arm_dot_prod_f64", cmsis_arm_dot_prod_f64, METH_VARARGS,""}, + {"arm_dot_prod_q7", cmsis_arm_dot_prod_q7, METH_VARARGS,""}, {"arm_dot_prod_q15", cmsis_arm_dot_prod_q15, METH_VARARGS,""}, {"arm_dot_prod_q31", cmsis_arm_dot_prod_q31, METH_VARARGS,""}, @@ -1627,10 +1891,13 @@ static PyMethodDef CMSISDSPMethods[] = { {"arm_clip_q15", cmsis_arm_clip_q15, METH_VARARGS,""}, {"arm_clip_q7", cmsis_arm_clip_q7, METH_VARARGS,""}, {"arm_offset_f32", cmsis_arm_offset_f32, METH_VARARGS,""}, +{"arm_offset_f64", cmsis_arm_offset_f64, METH_VARARGS,""}, + {"arm_offset_q7", cmsis_arm_offset_q7, METH_VARARGS,""}, {"arm_offset_q15", cmsis_arm_offset_q15, METH_VARARGS,""}, {"arm_offset_q31", cmsis_arm_offset_q31, METH_VARARGS,""}, {"arm_negate_f32", cmsis_arm_negate_f32, METH_VARARGS,""}, +{"arm_negate_f64", cmsis_arm_negate_f64, METH_VARARGS,""}, {"arm_negate_q7", cmsis_arm_negate_q7, METH_VARARGS,""}, {"arm_negate_q15", cmsis_arm_negate_q15, METH_VARARGS,""}, {"arm_negate_q31", cmsis_arm_negate_q31, METH_VARARGS,""}, diff --git a/PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_bayes.c b/PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_bayes.c new file mode 100755 index 00000000..e9d8024f --- /dev/null +++ b/PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_bayes.c @@ -0,0 +1,272 @@ +/* ---------------------------------------------------------------------- + * Project: CMSIS DSP Python Wrapper + * Title: cmsismodule.h + * Description: C code for the CMSIS-DSP Python wrapper + * + * $Date: 27 April 2021 + * $Revision: V1.0 + * + * Target Processor: Cortex-M cores + * -------------------------------------------------------------------- */ +/* + * Copyright (C) 2010-2021 ARM Limited or its affiliates. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define MODNAME "cmsisdsp_bayes" +#define MODINITNAME cmsisdsp_bayes + +#include "cmsisdsp_module.h" + + + +NUMPYVECTORFROMBUFFER(f32,float32_t,NPY_FLOAT); + + + +typedef struct { + PyObject_HEAD + arm_gaussian_naive_bayes_instance_f32 *instance; +} dsp_arm_gaussian_naive_bayes_instance_f32Object; + + +static void +arm_gaussian_naive_bayes_instance_f32_dealloc(dsp_arm_gaussian_naive_bayes_instance_f32Object* self) +{ + //printf("Dealloc called\n"); + if (self->instance) + { + + if (self->instance->theta) + { + PyMem_Free((float32_t*)self->instance->theta); + } + + if (self->instance->sigma) + { + PyMem_Free((float32_t*)self->instance->sigma); + } + + if (self->instance->classPriors) + { + PyMem_Free((float32_t*)self->instance->classPriors); + } + + PyMem_Free(self->instance); + } + + Py_TYPE(self)->tp_free((PyObject*)self); +} + + +static PyObject * +arm_gaussian_naive_bayes_instance_f32_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + dsp_arm_gaussian_naive_bayes_instance_f32Object *self; + //printf("New called\n"); + + self = (dsp_arm_gaussian_naive_bayes_instance_f32Object *)type->tp_alloc(type, 0); + //printf("alloc called\n"); + + if (self != NULL) { + + self->instance = PyMem_Malloc(sizeof(arm_gaussian_naive_bayes_instance_f32)); + self->instance->theta=NULL; + self->instance->sigma=NULL; + self->instance->classPriors=NULL; + + } + + + return (PyObject *)self; +} + +static int +arm_gaussian_naive_bayes_instance_f32_init(dsp_arm_gaussian_naive_bayes_instance_f32Object *self, PyObject *args, PyObject *kwds) +{ + +PyObject *theta=NULL; +PyObject *sigma=NULL; +PyObject *classPriors=NULL; + +char *kwlist[] = { +"vectorDimension", +"numberOfClasses", +"theta", +"sigma", +"classPriors", +"epsilon",NULL +}; + +if (PyArg_ParseTupleAndKeywords(args, kwds, "|iiOOOf", kwlist, + &self->instance->vectorDimension +,&self->instance->numberOfClasses +,&theta +,&sigma +,&classPriors +,&self->instance->epsilon +)) + { + + INITARRAYFIELD(theta,NPY_DOUBLE,double,float32_t); + INITARRAYFIELD(sigma,NPY_DOUBLE,double,float32_t); + INITARRAYFIELD(classPriors,NPY_DOUBLE,double,float32_t); + } + return 0; +} + +GETFIELD(arm_gaussian_naive_bayes_instance_f32,vectorDimension,"i"); +GETFIELD(arm_gaussian_naive_bayes_instance_f32,numberOfClasses,"i"); +GETFIELD(arm_gaussian_naive_bayes_instance_f32,epsilon,"f"); + + +static PyMethodDef arm_gaussian_naive_bayes_instance_f32_methods[] = { + + {"vectorDimension", (PyCFunction) Method_arm_gaussian_naive_bayes_instance_f32_vectorDimension,METH_NOARGS,"vectorDimension"}, + {"numberOfClasses", (PyCFunction) Method_arm_gaussian_naive_bayes_instance_f32_numberOfClasses,METH_NOARGS,"numberOfClasses"}, + {"epsilon", (PyCFunction) Method_arm_gaussian_naive_bayes_instance_f32_epsilon,METH_NOARGS,"epsilon"}, + + {NULL} /* Sentinel */ +}; + + +DSPType(arm_gaussian_naive_bayes_instance_f32,arm_gaussian_naive_bayes_instance_f32_new,arm_gaussian_naive_bayes_instance_f32_dealloc,arm_gaussian_naive_bayes_instance_f32_init,arm_gaussian_naive_bayes_instance_f32_methods); + + + + +void typeRegistration(PyObject *module) { + + + + ADDTYPE(arm_gaussian_naive_bayes_instance_f32); + + +} + + +static PyObject * +cmsis_arm_gaussian_naive_bayes_predict_f32(PyObject *obj, PyObject *args) +{ + + PyObject *S=NULL; // input + PyObject *pSrc=NULL; // input + float32_t *pSrc_converted=NULL; // input + float32_t *pDst=NULL; // output + uint32_t nbClasses; // input + + if (PyArg_ParseTuple(args,"OO",&S,&pSrc)) + { + + dsp_arm_gaussian_naive_bayes_instance_f32Object *selfS = (dsp_arm_gaussian_naive_bayes_instance_f32Object *)S; + GETARGUMENT(pSrc,NPY_DOUBLE,double,float32_t); + + nbClasses=selfS->instance->numberOfClasses; + + + pDst=PyMem_Malloc(sizeof(float32_t)*nbClasses); + float32_t *temp=PyMem_Malloc(sizeof(float32_t)*nbClasses); + + + uint32_t res=arm_gaussian_naive_bayes_predict_f32(selfS->instance,pSrc_converted,pDst,temp); + FLOATARRAY1(pDstOBJ,nbClasses,pDst); + + PyObject *pythonResult = Py_BuildValue("Ok",pDstOBJ,res); + + FREEARGUMENT(pSrc_converted); + PyMem_Free(temp); + Py_DECREF(pDstOBJ); + return(pythonResult); + + } + return(NULL); +} + + + +static PyMethodDef CMSISDSPMethods[] = { + + + +{"arm_gaussian_naive_bayes_predict_f32", cmsis_arm_gaussian_naive_bayes_predict_f32, METH_VARARGS,""}, + + + + {"error_out", (PyCFunction)error_out, METH_NOARGS, NULL}, + {NULL, NULL, 0, NULL} /* Sentinel */ +}; + +#ifdef IS_PY3K +static int cmsisdsp_traverse(PyObject *m, visitproc visit, void *arg) { + Py_VISIT(GETSTATE(m)->error); + return 0; +} + +static int cmsisdsp_clear(PyObject *m) { + Py_CLEAR(GETSTATE(m)->error); + return 0; +} + + +static struct PyModuleDef moduledef = { + PyModuleDef_HEAD_INIT, + MODNAME, + NULL, + sizeof(struct module_state), + CMSISDSPMethods, + NULL, + cmsisdsp_traverse, + cmsisdsp_clear, + NULL +}; + +#define INITERROR return NULL + +PyMODINIT_FUNC +CAT(PyInit_,MODINITNAME)(void) + + +#else +#define INITERROR return + +void CAT(init,MODINITNAME)(void) +#endif +{ + import_array(); + + #ifdef IS_PY3K + PyObject *module = PyModule_Create(&moduledef); + #else + PyObject *module = Py_InitModule(MODNAME, CMSISDSPMethods); + #endif + + if (module == NULL) + INITERROR; + struct module_state *st = GETSTATE(module); + + st->error = PyErr_NewException(MODNAME".Error", NULL, NULL); + if (st->error == NULL) { + Py_DECREF(module); + INITERROR; + } + + + typeRegistration(module); + + #ifdef IS_PY3K + return module; + #endif +} \ No newline at end of file diff --git a/PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_complexf.c b/PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_complexf.c index edf5bc0f..ae14bb44 100755 --- a/PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_complexf.c +++ b/PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_complexf.c @@ -181,6 +181,38 @@ cmsis_arm_cmplx_mag_squared_f32(PyObject *obj, PyObject *args) return(NULL); } +static PyObject * +cmsis_arm_cmplx_mag_squared_f64(PyObject *obj, PyObject *args) +{ + + PyObject *pSrc=NULL; // input + float64_t *pSrc_converted=NULL; // input + float64_t *pDst=NULL; // output + uint32_t numSamples; // input + + if (PyArg_ParseTuple(args,"O",&pSrc)) + { + + GETARGUMENT(pSrc,NPY_DOUBLE,double,float64_t); + numSamples = arraySizepSrc ; + numSamples = numSamples / 2; + + pDst=PyMem_Malloc(sizeof(float64_t)*2*numSamples); + + + arm_cmplx_mag_squared_f64(pSrc_converted,pDst,numSamples); + FLOAT64ARRAY1(pDstOBJ,numSamples,pDst); + + PyObject *pythonResult = Py_BuildValue("O",pDstOBJ); + + FREEARGUMENT(pSrc_converted); + Py_DECREF(pDstOBJ); + return(pythonResult); + + } + return(NULL); +} + static PyObject * cmsis_arm_cmplx_mag_squared_q31(PyObject *obj, PyObject *args) @@ -285,6 +317,38 @@ cmsis_arm_cmplx_mag_f32(PyObject *obj, PyObject *args) return(NULL); } +static PyObject * +cmsis_arm_cmplx_mag_f64(PyObject *obj, PyObject *args) +{ + + PyObject *pSrc=NULL; // input + float64_t *pSrc_converted=NULL; // input + float64_t *pDst=NULL; // output + uint32_t numSamples; // input + + if (PyArg_ParseTuple(args,"O",&pSrc)) + { + + GETARGUMENT(pSrc,NPY_DOUBLE,double,float64_t); + numSamples = arraySizepSrc ; + numSamples = numSamples / 2; + + pDst=PyMem_Malloc(sizeof(float64_t)*2*numSamples); + + + arm_cmplx_mag_f64(pSrc_converted,pDst,numSamples); + FLOAT64ARRAY1(pDstOBJ,numSamples,pDst); + + PyObject *pythonResult = Py_BuildValue("O",pDstOBJ); + + FREEARGUMENT(pSrc_converted); + Py_DECREF(pDstOBJ); + return(pythonResult); + + } + return(NULL); +} + static PyObject * cmsis_arm_cmplx_mag_q31(PyObject *obj, PyObject *args) @@ -392,8 +456,8 @@ cmsis_arm_cmplx_dot_prod_q15(PyObject *obj, PyObject *args) PyObject *pSrcB=NULL; // input q15_t *pSrcB_converted=NULL; // input uint32_t numSamples; // input - q31_t *realResult=NULL; // output - q31_t *imagResult=NULL; // output + q31_t realResult; // output + q31_t imagResult; // output if (PyArg_ParseTuple(args,"OO",&pSrcA,&pSrcB)) { @@ -403,15 +467,10 @@ cmsis_arm_cmplx_dot_prod_q15(PyObject *obj, PyObject *args) numSamples = arraySizepSrcA ; numSamples = numSamples / 2; - realResult=PyMem_Malloc(sizeof(q31_t)*1); - - - imagResult=PyMem_Malloc(sizeof(q31_t)*1); - - arm_cmplx_dot_prod_q15(pSrcA_converted,pSrcB_converted,numSamples,realResult,imagResult); - PyObject* realResultOBJ=Py_BuildValue("i",*realResult); - PyObject* imagResultOBJ=Py_BuildValue("i",*imagResult); + arm_cmplx_dot_prod_q15(pSrcA_converted,pSrcB_converted,numSamples,&realResult,&imagResult); + PyObject* realResultOBJ=Py_BuildValue("i",realResult); + PyObject* imagResultOBJ=Py_BuildValue("i",imagResult); PyObject *pythonResult = Py_BuildValue("OO",realResultOBJ,imagResultOBJ); @@ -435,8 +494,8 @@ cmsis_arm_cmplx_dot_prod_q31(PyObject *obj, PyObject *args) PyObject *pSrcB=NULL; // input q31_t *pSrcB_converted=NULL; // input uint32_t numSamples; // input - q63_t *realResult=NULL; // output - q63_t *imagResult=NULL; // output + q63_t realResult; // output + q63_t imagResult; // output if (PyArg_ParseTuple(args,"OO",&pSrcA,&pSrcB)) { @@ -446,15 +505,10 @@ cmsis_arm_cmplx_dot_prod_q31(PyObject *obj, PyObject *args) numSamples = arraySizepSrcA ; numSamples = numSamples / 2; - realResult=PyMem_Malloc(sizeof(q63_t)*1); - - imagResult=PyMem_Malloc(sizeof(q63_t)*1); - - - arm_cmplx_dot_prod_q31(pSrcA_converted,pSrcB_converted,numSamples,realResult,imagResult); - PyObject* realResultOBJ=Py_BuildValue("L",*realResult); - PyObject* imagResultOBJ=Py_BuildValue("L",*imagResult); + arm_cmplx_dot_prod_q31(pSrcA_converted,pSrcB_converted,numSamples,&realResult,&imagResult); + PyObject* realResultOBJ=Py_BuildValue("L",realResult); + PyObject* imagResultOBJ=Py_BuildValue("L",imagResult); PyObject *pythonResult = Py_BuildValue("OO",realResultOBJ,imagResultOBJ); @@ -478,8 +532,8 @@ cmsis_arm_cmplx_dot_prod_f32(PyObject *obj, PyObject *args) PyObject *pSrcB=NULL; // input float32_t *pSrcB_converted=NULL; // input uint32_t numSamples; // input - float32_t *realResult=NULL; // output - float32_t *imagResult=NULL; // output + float32_t realResult; // output + float32_t imagResult; // output if (PyArg_ParseTuple(args,"OO",&pSrcA,&pSrcB)) { @@ -489,15 +543,10 @@ cmsis_arm_cmplx_dot_prod_f32(PyObject *obj, PyObject *args) numSamples = arraySizepSrcA ; numSamples = numSamples / 2; - realResult=PyMem_Malloc(sizeof(float32_t)*1); - - - imagResult=PyMem_Malloc(sizeof(float32_t)*1); - - arm_cmplx_dot_prod_f32(pSrcA_converted,pSrcB_converted,numSamples,realResult,imagResult); - PyObject* realResultOBJ=Py_BuildValue("f",*realResult); - PyObject* imagResultOBJ=Py_BuildValue("f",*imagResult); + arm_cmplx_dot_prod_f32(pSrcA_converted,pSrcB_converted,numSamples,&realResult,&imagResult); + PyObject* realResultOBJ=Py_BuildValue("f",realResult); + PyObject* imagResultOBJ=Py_BuildValue("f",imagResult); PyObject *pythonResult = Py_BuildValue("OO",realResultOBJ,imagResultOBJ); @@ -735,7 +784,41 @@ cmsis_arm_cmplx_mult_cmplx_f32(PyObject *obj, PyObject *args) return(NULL); } +static PyObject * +cmsis_arm_cmplx_mult_cmplx_f64(PyObject *obj, PyObject *args) +{ + + PyObject *pSrcA=NULL; // input + float64_t *pSrcA_converted=NULL; // input + PyObject *pSrcB=NULL; // input + float64_t *pSrcB_converted=NULL; // input + float64_t *pDst=NULL; // output + uint32_t numSamples; // input + + if (PyArg_ParseTuple(args,"OO",&pSrcA,&pSrcB)) + { + + GETARGUMENT(pSrcA,NPY_DOUBLE,double,float64_t); + GETARGUMENT(pSrcB,NPY_DOUBLE,double,float64_t); + numSamples = arraySizepSrcA ; + numSamples = numSamples / 2; + + pDst=PyMem_Malloc(sizeof(float64_t)*2*numSamples); + + + arm_cmplx_mult_cmplx_f64(pSrcA_converted,pSrcB_converted,pDst,numSamples); + FLOAT64ARRAY1(pDstOBJ,2*numSamples,pDst); + PyObject *pythonResult = Py_BuildValue("O",pDstOBJ); + + FREEARGUMENT(pSrcA_converted); + FREEARGUMENT(pSrcB_converted); + Py_DECREF(pDstOBJ); + return(pythonResult); + + } + return(NULL); +} static PyMethodDef CMSISDSPMethods[] = { @@ -745,11 +828,13 @@ static PyMethodDef CMSISDSPMethods[] = { {"arm_cmplx_conj_q31", cmsis_arm_cmplx_conj_q31, METH_VARARGS,""}, {"arm_cmplx_conj_q15", cmsis_arm_cmplx_conj_q15, METH_VARARGS,""}, {"arm_cmplx_mag_squared_f32", cmsis_arm_cmplx_mag_squared_f32, METH_VARARGS,""}, +{"arm_cmplx_mag_squared_f64", cmsis_arm_cmplx_mag_squared_f64, METH_VARARGS,""}, {"arm_cmplx_mag_squared_q31", cmsis_arm_cmplx_mag_squared_q31, METH_VARARGS,""}, {"arm_cmplx_mag_squared_q15", cmsis_arm_cmplx_mag_squared_q15, METH_VARARGS,""}, {"arm_cmplx_mag_f32", cmsis_arm_cmplx_mag_f32, METH_VARARGS,""}, +{"arm_cmplx_mag_f64", cmsis_arm_cmplx_mag_f64, METH_VARARGS,""}, {"arm_cmplx_mag_q31", cmsis_arm_cmplx_mag_q31, METH_VARARGS,""}, {"arm_cmplx_mag_q15", cmsis_arm_cmplx_mag_q15, METH_VARARGS,""}, {"arm_cmplx_mag_fast_q15", cmsis_arm_cmplx_mag_fast_q15, METH_VARARGS,""}, @@ -762,6 +847,7 @@ static PyMethodDef CMSISDSPMethods[] = { {"arm_cmplx_mult_cmplx_q15", cmsis_arm_cmplx_mult_cmplx_q15, METH_VARARGS,""}, {"arm_cmplx_mult_cmplx_q31", cmsis_arm_cmplx_mult_cmplx_q31, METH_VARARGS,""}, {"arm_cmplx_mult_cmplx_f32", cmsis_arm_cmplx_mult_cmplx_f32, METH_VARARGS,""}, +{"arm_cmplx_mult_cmplx_f64", cmsis_arm_cmplx_mult_cmplx_f64, METH_VARARGS,""}, {"error_out", (PyCFunction)error_out, METH_NOARGS, NULL}, {NULL, NULL, 0, NULL} /* Sentinel */ diff --git a/PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_distance.c b/PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_distance.c new file mode 100755 index 00000000..a9f3bd34 --- /dev/null +++ b/PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_distance.c @@ -0,0 +1,308 @@ +/* ---------------------------------------------------------------------- + * Project: CMSIS DSP Python Wrapper + * Title: cmsismodule.h + * Description: C code for the CMSIS-DSP Python wrapper + * + * $Date: 27 April 2021 + * $Revision: V1.0 + * + * Target Processor: Cortex-M cores + * -------------------------------------------------------------------- */ +/* + * Copyright (C) 2010-2021 ARM Limited or its affiliates. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define MODNAME "cmsisdsp_distance" +#define MODINITNAME cmsisdsp_distance + +#include "cmsisdsp_module.h" + + +NUMPYVECTORFROMBUFFER(f32,float32_t,NPY_FLOAT); + + +void typeRegistration(PyObject *module) { + + +} + +#define FLOATDIST(NAME) \ +static PyObject * \ +cmsis_arm_##NAME##_f32(PyObject *obj, PyObject *args) \ +{ \ + \ + PyObject *pSrcA=NULL; \ + float32_t *pSrcA_converted=NULL; \ + PyObject *pSrcB=NULL; \ + float32_t *pSrcB_converted=NULL; \ + uint32_t blockSize; \ + float32_t result; \ + \ + if (PyArg_ParseTuple(args,"OO",&pSrcA,&pSrcB)) \ + { \ + \ + GETARGUMENT(pSrcA,NPY_DOUBLE,double,float32_t); \ + GETARGUMENT(pSrcB,NPY_DOUBLE,double,float32_t); \ + blockSize = arraySizepSrcA ; \ + \ + \ + \ + result=arm_##NAME##_f32(pSrcA_converted,pSrcB_converted,blockSize);\ + PyObject* resultOBJ=Py_BuildValue("f",result); \ + \ + PyObject *pythonResult = Py_BuildValue("O",resultOBJ); \ + \ + FREEARGUMENT(pSrcA_converted); \ + FREEARGUMENT(pSrcB_converted); \ + Py_DECREF(resultOBJ); \ + return(pythonResult); \ + \ + } \ + return(NULL); \ +} + +#define FLOAT64DIST(NAME) \ +static PyObject * \ +cmsis_arm_##NAME##_f64(PyObject *obj, PyObject *args) \ +{ \ + \ + PyObject *pSrcA=NULL; \ + float64_t *pSrcA_converted=NULL; \ + PyObject *pSrcB=NULL; \ + float64_t *pSrcB_converted=NULL; \ + uint32_t blockSize; \ + float64_t result; \ + \ + if (PyArg_ParseTuple(args,"OO",&pSrcA,&pSrcB)) \ + { \ + \ + GETARGUMENT(pSrcA,NPY_DOUBLE,double,float64_t); \ + GETARGUMENT(pSrcB,NPY_DOUBLE,double,float64_t); \ + blockSize = arraySizepSrcA ; \ + \ + \ + \ + result=arm_##NAME##_f64(pSrcA_converted,pSrcB_converted,blockSize);\ + PyObject* resultOBJ=Py_BuildValue("d",result); \ + \ + PyObject *pythonResult = Py_BuildValue("O",resultOBJ); \ + \ + FREEARGUMENT(pSrcA_converted); \ + FREEARGUMENT(pSrcB_converted); \ + Py_DECREF(resultOBJ); \ + return(pythonResult); \ + \ + } \ + return(NULL); \ +} + +FLOAT64DIST(chebyshev_distance); +FLOAT64DIST(cityblock_distance); +FLOAT64DIST(cosine_distance); +FLOAT64DIST(euclidean_distance); + + +FLOATDIST(braycurtis_distance); +FLOATDIST(canberra_distance); +FLOATDIST(chebyshev_distance); +FLOATDIST(cityblock_distance); +FLOATDIST(correlation_distance); +FLOATDIST(cosine_distance); +FLOATDIST(euclidean_distance); +FLOATDIST(jensenshannon_distance); + +static PyObject * +cmsis_arm_minkowski_distance_f32(PyObject *obj, PyObject *args) +{ + + PyObject *pSrcA=NULL; + float32_t *pSrcA_converted=NULL; + PyObject *pSrcB=NULL; + float32_t *pSrcB_converted=NULL; + int32_t w; + uint32_t blockSize; + float32_t result; + + if (PyArg_ParseTuple(args,"OOl",&pSrcA,&pSrcB,&w)) + { + + GETARGUMENT(pSrcA,NPY_DOUBLE,double,float32_t); + GETARGUMENT(pSrcB,NPY_DOUBLE,double,float32_t); + + blockSize = arraySizepSrcA ; + + + + result=arm_minkowski_distance_f32(pSrcA_converted,pSrcB_converted,w,blockSize); + PyObject* resultOBJ=Py_BuildValue("f",result); + + PyObject *pythonResult = Py_BuildValue("O",resultOBJ); + + FREEARGUMENT(pSrcA_converted); + FREEARGUMENT(pSrcB_converted); + + Py_DECREF(resultOBJ); + return(pythonResult); + + } + return(NULL); +} + + +#define INTDIST(NAME) \ +static PyObject * \ +cmsis_arm_##NAME (PyObject *obj, PyObject *args) \ +{ \ + \ + PyObject *pSrcA=NULL; \ + uint32_t *pSrcA_converted=NULL; \ + PyObject *pSrcB=NULL; \ + uint32_t *pSrcB_converted=NULL; \ + uint32_t blockSize; \ + float32_t result; \ + \ + \ + if (PyArg_ParseTuple(args,"OOl",&pSrcA,&pSrcB,&blockSize)) \ + { \ + \ + GETARGUMENT(pSrcA,NPY_UINT32,uint32_t,uint32_t); \ + GETARGUMENT(pSrcB,NPY_UINT32,uint32_t,uint32_t); \ + \ + \ + \ + result=arm_##NAME (pSrcA_converted,pSrcB_converted,blockSize); \ + PyObject* resultOBJ=Py_BuildValue("f",result); \ + \ + PyObject *pythonResult = Py_BuildValue("O",resultOBJ); \ + \ + FREEARGUMENT(pSrcA_converted); \ + FREEARGUMENT(pSrcB_converted); \ + Py_DECREF(resultOBJ); \ + return(pythonResult); \ + \ + } \ + return(NULL); \ +} + + +INTDIST(dice_distance); +INTDIST(hamming_distance); +INTDIST(jaccard_distance); +INTDIST(kulsinski_distance); +INTDIST(rogerstanimoto_distance); +INTDIST(russellrao_distance); +INTDIST(sokalmichener_distance); +INTDIST(sokalsneath_distance); +INTDIST(yule_distance); + + +static PyMethodDef CMSISDSPMethods[] = { + + {"arm_braycurtis_distance_f32", cmsis_arm_braycurtis_distance_f32, METH_VARARGS,""}, + {"arm_canberra_distance_f32" , cmsis_arm_canberra_distance_f32, METH_VARARGS,""}, + {"arm_chebyshev_distance_f32" , cmsis_arm_chebyshev_distance_f32, METH_VARARGS,""}, + {"arm_chebyshev_distance_f64" , cmsis_arm_chebyshev_distance_f64, METH_VARARGS,""}, + + {"arm_cityblock_distance_f32", cmsis_arm_cityblock_distance_f32, METH_VARARGS,""}, + {"arm_cityblock_distance_f64", cmsis_arm_cityblock_distance_f64, METH_VARARGS,""}, + + {"arm_correlation_distance_f32", cmsis_arm_correlation_distance_f32, METH_VARARGS,""}, + + {"arm_cosine_distance_f32", cmsis_arm_cosine_distance_f32, METH_VARARGS,""}, + {"arm_cosine_distance_f64", cmsis_arm_cosine_distance_f64, METH_VARARGS,""}, + + {"arm_euclidean_distance_f32", cmsis_arm_euclidean_distance_f32, METH_VARARGS,""}, + {"arm_euclidean_distance_f64", cmsis_arm_euclidean_distance_f64, METH_VARARGS,""}, + + {"arm_jensenshannon_distance_f32", cmsis_arm_jensenshannon_distance_f32, METH_VARARGS,""}, + {"arm_minkowski_distance_f32", cmsis_arm_minkowski_distance_f32, METH_VARARGS,""}, + + {"arm_dice_distance",cmsis_arm_dice_distance, METH_VARARGS,""}, + {"arm_hamming_distance",cmsis_arm_hamming_distance, METH_VARARGS,""}, + {"arm_jaccard_distance",cmsis_arm_jaccard_distance, METH_VARARGS,""}, + {"arm_kulsinski_distance",cmsis_arm_kulsinski_distance, METH_VARARGS,""}, + {"arm_rogerstanimoto_distance",cmsis_arm_rogerstanimoto_distance, METH_VARARGS,""}, + {"arm_russellrao_distance",cmsis_arm_russellrao_distance, METH_VARARGS,""}, + {"arm_sokalmichener_distance",cmsis_arm_sokalmichener_distance, METH_VARARGS,""}, + {"arm_sokalsneath_distance",cmsis_arm_sokalsneath_distance, METH_VARARGS,""}, + {"arm_yule_distance",cmsis_arm_yule_distance, METH_VARARGS,""}, + + {"error_out", (PyCFunction)error_out, METH_NOARGS, NULL}, + {NULL, NULL, 0, NULL} /* Sentinel */ +}; + +#ifdef IS_PY3K +static int cmsisdsp_traverse(PyObject *m, visitproc visit, void *arg) { + Py_VISIT(GETSTATE(m)->error); + return 0; +} + +static int cmsisdsp_clear(PyObject *m) { + Py_CLEAR(GETSTATE(m)->error); + return 0; +} + + +static struct PyModuleDef moduledef = { + PyModuleDef_HEAD_INIT, + MODNAME, + NULL, + sizeof(struct module_state), + CMSISDSPMethods, + NULL, + cmsisdsp_traverse, + cmsisdsp_clear, + NULL +}; + +#define INITERROR return NULL + +PyMODINIT_FUNC +CAT(PyInit_,MODINITNAME)(void) + + +#else +#define INITERROR return + +void CAT(init,MODINITNAME)(void) +#endif +{ + import_array(); + + #ifdef IS_PY3K + PyObject *module = PyModule_Create(&moduledef); + #else + PyObject *module = Py_InitModule(MODNAME, CMSISDSPMethods); + #endif + + if (module == NULL) + INITERROR; + struct module_state *st = GETSTATE(module); + + st->error = PyErr_NewException(MODNAME".Error", NULL, NULL); + if (st->error == NULL) { + Py_DECREF(module); + INITERROR; + } + + + typeRegistration(module); + + #ifdef IS_PY3K + return module; + #endif +} \ No newline at end of file diff --git a/PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_fastmath.c b/PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_fastmath.c index 86915cda..0096a4bd 100755 --- a/PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_fastmath.c +++ b/PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_fastmath.c @@ -388,6 +388,129 @@ cmsis_arm_sqrt_q15(PyObject *obj, PyObject *args) } +static PyObject * +cmsis_arm_vexp_f32(PyObject *obj, PyObject *args) +{ + + PyObject *pSrc=NULL; // input + float32_t *pSrc_converted=NULL; // input + float32_t *pDst=NULL; // output + uint32_t blockSize; // input + + if (PyArg_ParseTuple(args,"O",&pSrc)) + { + + GETARGUMENT(pSrc,NPY_DOUBLE,double,float32_t); + blockSize = arraySizepSrc ; + + pDst=PyMem_Malloc(sizeof(float32_t)*blockSize); + + + arm_vexp_f32(pSrc_converted,pDst,blockSize); + FLOATARRAY1(pDstOBJ,blockSize,pDst); + + PyObject *pythonResult = Py_BuildValue("O",pDstOBJ); + + FREEARGUMENT(pSrc_converted); + Py_DECREF(pDstOBJ); + return(pythonResult); + + } + return(NULL); +} + +static PyObject * +cmsis_arm_vexp_f64(PyObject *obj, PyObject *args) +{ + + PyObject *pSrc=NULL; // input + float64_t *pSrc_converted=NULL; // input + float64_t *pDst=NULL; // output + uint32_t blockSize; // input + + if (PyArg_ParseTuple(args,"O",&pSrc)) + { + + GETARGUMENT(pSrc,NPY_DOUBLE,double,float64_t); + blockSize = arraySizepSrc ; + + pDst=PyMem_Malloc(sizeof(float64_t)*blockSize); + + + arm_vexp_f64(pSrc_converted,pDst,blockSize); + FLOAT64ARRAY1(pDstOBJ,blockSize,pDst); + + PyObject *pythonResult = Py_BuildValue("O",pDstOBJ); + + FREEARGUMENT(pSrc_converted); + Py_DECREF(pDstOBJ); + return(pythonResult); + + } + return(NULL); +} + +static PyObject * +cmsis_arm_vlog_f32(PyObject *obj, PyObject *args) +{ + + PyObject *pSrc=NULL; // input + float32_t *pSrc_converted=NULL; // input + float32_t *pDst=NULL; // output + uint32_t blockSize; // input + + if (PyArg_ParseTuple(args,"O",&pSrc)) + { + + GETARGUMENT(pSrc,NPY_DOUBLE,double,float32_t); + blockSize = arraySizepSrc ; + + pDst=PyMem_Malloc(sizeof(float32_t)*blockSize); + + + arm_vlog_f32(pSrc_converted,pDst,blockSize); + FLOATARRAY1(pDstOBJ,blockSize,pDst); + + PyObject *pythonResult = Py_BuildValue("O",pDstOBJ); + + FREEARGUMENT(pSrc_converted); + Py_DECREF(pDstOBJ); + return(pythonResult); + + } + return(NULL); +} + +static PyObject * +cmsis_arm_vlog_f64(PyObject *obj, PyObject *args) +{ + + PyObject *pSrc=NULL; // input + float64_t *pSrc_converted=NULL; // input + float64_t *pDst=NULL; // output + uint32_t blockSize; // input + + if (PyArg_ParseTuple(args,"O",&pSrc)) + { + + GETARGUMENT(pSrc,NPY_DOUBLE,double,float64_t); + blockSize = arraySizepSrc ; + + pDst=PyMem_Malloc(sizeof(float64_t)*blockSize); + + + arm_vlog_f64(pSrc_converted,pDst,blockSize); + FLOAT64ARRAY1(pDstOBJ,blockSize,pDst); + + PyObject *pythonResult = Py_BuildValue("O",pDstOBJ); + + FREEARGUMENT(pSrc_converted); + Py_DECREF(pDstOBJ); + return(pythonResult); + + } + return(NULL); +} @@ -411,7 +534,10 @@ static PyMethodDef CMSISDSPMethods[] = { {"arm_sqrt_q15", cmsis_arm_sqrt_q15, METH_VARARGS,""}, {"arm_divide_q31", cmsis_arm_divide_q31, METH_VARARGS,""}, {"arm_divide_q15", cmsis_arm_divide_q15, METH_VARARGS,""}, - +{"arm_vexp_f32", cmsis_arm_vexp_f32, METH_VARARGS,""}, +{"arm_vlog_f32", cmsis_arm_vlog_f32, METH_VARARGS,""}, +{"arm_vexp_f64", cmsis_arm_vexp_f64, METH_VARARGS,""}, +{"arm_vlog_f64", cmsis_arm_vlog_f64, METH_VARARGS,""}, {"error_out", (PyCFunction)error_out, METH_NOARGS, NULL}, {NULL, NULL, 0, NULL} /* Sentinel */ }; diff --git a/PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_filtering.c b/PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_filtering.c index 732b3c2f..ab6b693c 100755 --- a/PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_filtering.c +++ b/PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_filtering.c @@ -302,6 +302,10 @@ typedef struct { arm_fir_instance_f32 *instance; } dsp_arm_fir_instance_f32Object; +typedef struct { + PyObject_HEAD + arm_fir_instance_f64 *instance; +} dsp_arm_fir_instance_f64Object; static void arm_fir_instance_f32_dealloc(dsp_arm_fir_instance_f32Object* self) @@ -329,6 +333,32 @@ arm_fir_instance_f32_dealloc(dsp_arm_fir_instance_f32Object* self) Py_TYPE(self)->tp_free((PyObject*)self); } +static void +arm_fir_instance_f64_dealloc(dsp_arm_fir_instance_f64Object* self) +{ + //printf("Dealloc called\n"); + if (self->instance) + { + + + if (self->instance->pState) + { + PyMem_Free(self->instance->pState); + } + + + if (self->instance->pCoeffs) + { + PyMem_Free((float64_t*)self->instance->pCoeffs); + } + + + PyMem_Free(self->instance); + } + + Py_TYPE(self)->tp_free((PyObject*)self); +} + static PyObject * arm_fir_instance_f32_new(PyTypeObject *type, PyObject *args, PyObject *kwds) @@ -352,6 +382,28 @@ arm_fir_instance_f32_new(PyTypeObject *type, PyObject *args, PyObject *kwds) return (PyObject *)self; } +static PyObject * +arm_fir_instance_f64_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + dsp_arm_fir_instance_f64Object *self; + //printf("New called\n"); + + self = (dsp_arm_fir_instance_f64Object *)type->tp_alloc(type, 0); + //printf("alloc called\n"); + + if (self != NULL) { + + self->instance = PyMem_Malloc(sizeof(arm_fir_instance_f64)); + + self->instance->pState = NULL; + self->instance->pCoeffs = NULL; + + } + + + return (PyObject *)self; +} + static int arm_fir_instance_f32_init(dsp_arm_fir_instance_f32Object *self, PyObject *args, PyObject *kwds) { @@ -371,7 +423,27 @@ if (PyArg_ParseTupleAndKeywords(args, kwds, "|h", kwlist,&self->instance->numTap return 0; } +static int +arm_fir_instance_f64_init(dsp_arm_fir_instance_f64Object *self, PyObject *args, PyObject *kwds) +{ + + PyObject *pState=NULL; + PyObject *pCoeffs=NULL; +char *kwlist[] = { +"numTaps",NULL +}; + +if (PyArg_ParseTupleAndKeywords(args, kwds, "|h", kwlist,&self->instance->numTaps +)) + { + + + } + return 0; +} + GETFIELD(arm_fir_instance_f32,numTaps,"h"); +GETFIELD(arm_fir_instance_f64,numTaps,"h"); static PyMethodDef arm_fir_instance_f32_methods[] = { @@ -381,8 +453,16 @@ static PyMethodDef arm_fir_instance_f32_methods[] = { {NULL} /* Sentinel */ }; +static PyMethodDef arm_fir_instance_f64_methods[] = { + + {"numTaps", (PyCFunction) Method_arm_fir_instance_f64_numTaps,METH_NOARGS,"numTaps"}, + + {NULL} /* Sentinel */ +}; + DSPType(arm_fir_instance_f32,arm_fir_instance_f32_new,arm_fir_instance_f32_dealloc,arm_fir_instance_f32_init,arm_fir_instance_f32_methods); +DSPType(arm_fir_instance_f64,arm_fir_instance_f64_new,arm_fir_instance_f64_dealloc,arm_fir_instance_f64_init,arm_fir_instance_f64_methods); typedef struct { @@ -3135,6 +3215,7 @@ void typeRegistration(PyObject *module) { ADDTYPE(arm_fir_instance_q15); ADDTYPE(arm_fir_instance_q31); ADDTYPE(arm_fir_instance_f32); + ADDTYPE(arm_fir_instance_f64); ADDTYPE(arm_biquad_casd_df1_inst_q15); ADDTYPE(arm_biquad_casd_df1_inst_q31); ADDTYPE(arm_biquad_casd_df1_inst_f32); @@ -3464,6 +3545,39 @@ cmsis_arm_fir_f32(PyObject *obj, PyObject *args) return(NULL); } +static PyObject * +cmsis_arm_fir_f64(PyObject *obj, PyObject *args) +{ + + PyObject *S=NULL; // input + PyObject *pSrc=NULL; // input + float64_t *pSrc_converted=NULL; // input + float64_t *pDst=NULL; // output + uint32_t blockSize; // input + + if (PyArg_ParseTuple(args,"OO",&S,&pSrc)) + { + + dsp_arm_fir_instance_f64Object *selfS = (dsp_arm_fir_instance_f64Object *)S; + GETARGUMENT(pSrc,NPY_DOUBLE,double,float64_t); + blockSize = arraySizepSrc ; + + pDst=PyMem_Malloc(sizeof(float64_t)*blockSize); + + + arm_fir_f64(selfS->instance,pSrc_converted,pDst,blockSize); + FLOAT64ARRAY1(pDstOBJ,blockSize,pDst); + + PyObject *pythonResult = Py_BuildValue("O",pDstOBJ); + + FREEARGUMENT(pSrc_converted); + Py_DECREF(pDstOBJ); + return(pythonResult); + + } + return(NULL); +} + static PyObject * cmsis_arm_fir_init_f32(PyObject *obj, PyObject *args) @@ -3492,6 +3606,33 @@ cmsis_arm_fir_init_f32(PyObject *obj, PyObject *args) return(NULL); } +static PyObject * +cmsis_arm_fir_init_f64(PyObject *obj, PyObject *args) +{ + + PyObject *S=NULL; // input + uint16_t numTaps; // input + PyObject *pCoeffs=NULL; // input + float64_t *pCoeffs_converted=NULL; // input + PyObject *pState=NULL; // input + float64_t *pState_converted=NULL; // input + uint32_t blockSize; // input + + if (PyArg_ParseTuple(args,"OhOO",&S,&numTaps,&pCoeffs,&pState)) + { + + dsp_arm_fir_instance_f64Object *selfS = (dsp_arm_fir_instance_f64Object *)S; + GETARGUMENT(pCoeffs,NPY_DOUBLE,double,float64_t); + GETARGUMENT(pState,NPY_DOUBLE,double,float64_t); + blockSize = arraySizepState - arraySizepCoeffs + 1; + + arm_fir_init_f64(selfS->instance,numTaps,pCoeffs_converted,pState_converted,blockSize); + Py_RETURN_NONE; + + } + return(NULL); +} + static PyObject * cmsis_arm_biquad_cascade_df1_q15(PyObject *obj, PyObject *args) @@ -6120,6 +6261,41 @@ cmsis_arm_correlate_f32(PyObject *obj, PyObject *args) return(NULL); } +static PyObject * +cmsis_arm_correlate_f64(PyObject *obj, PyObject *args) +{ + + PyObject *pSrcA=NULL; // input + float64_t *pSrcA_converted=NULL; // input + uint32_t srcALen; // input + PyObject *pSrcB=NULL; // input + float64_t *pSrcB_converted=NULL; // input + uint32_t srcBLen; // input + float64_t *pDst=NULL; // output + + if (PyArg_ParseTuple(args,"OiOi",&pSrcA,&srcALen,&pSrcB,&srcBLen)) + { + + GETARGUMENT(pSrcA,NPY_DOUBLE,double,float64_t); + GETARGUMENT(pSrcB,NPY_DOUBLE,double,float64_t); + uint32_t outputLength = 2*MAX(srcALen,srcBLen) - 1 ; + + pDst=PyMem_Malloc(sizeof(float64_t)*outputLength); + + + arm_correlate_f64(pSrcA_converted,srcALen,pSrcB_converted,srcBLen,pDst); + FLOAT64ARRAY1(pDstOBJ,outputLength,pDst); + + PyObject *pythonResult = Py_BuildValue("O",pDstOBJ); + + FREEARGUMENT(pSrcA_converted); + FREEARGUMENT(pSrcB_converted); + Py_DECREF(pDstOBJ); + return(pythonResult); + + } + return(NULL); +} static PyObject * cmsis_arm_correlate_opt_q15(PyObject *obj, PyObject *args) @@ -6713,6 +6889,8 @@ static PyMethodDef CMSISDSPMethods[] = { {"arm_fir_init_q31", cmsis_arm_fir_init_q31, METH_VARARGS,""}, {"arm_fir_f32", cmsis_arm_fir_f32, METH_VARARGS,""}, {"arm_fir_init_f32", cmsis_arm_fir_init_f32, METH_VARARGS,""}, +{"arm_fir_f64", cmsis_arm_fir_f64, METH_VARARGS,""}, +{"arm_fir_init_f64", cmsis_arm_fir_init_f64, METH_VARARGS,""}, {"arm_biquad_cascade_df1_q15", cmsis_arm_biquad_cascade_df1_q15, METH_VARARGS,""}, {"arm_biquad_cascade_df1_init_q15", cmsis_arm_biquad_cascade_df1_init_q15, METH_VARARGS,""}, {"arm_biquad_cascade_df1_fast_q15", cmsis_arm_biquad_cascade_df1_fast_q15, METH_VARARGS,""}, @@ -6789,6 +6967,7 @@ static PyMethodDef CMSISDSPMethods[] = { {"arm_lms_norm_q15", cmsis_arm_lms_norm_q15, METH_VARARGS,""}, {"arm_lms_norm_init_q15", cmsis_arm_lms_norm_init_q15, METH_VARARGS,""}, {"arm_correlate_f32", cmsis_arm_correlate_f32, METH_VARARGS,""}, +{"arm_correlate_f64", cmsis_arm_correlate_f64, METH_VARARGS,""}, {"arm_correlate_opt_q15", cmsis_arm_correlate_opt_q15, METH_VARARGS,""}, {"arm_correlate_q15", cmsis_arm_correlate_q15, METH_VARARGS,""}, {"arm_correlate_fast_q15", cmsis_arm_correlate_fast_q15, METH_VARARGS,""}, diff --git a/PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_interpolation.c b/PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_interpolation.c index 0283f2aa..29504abc 100755 --- a/PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_interpolation.c +++ b/PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_interpolation.c @@ -463,6 +463,107 @@ static PyMethodDef arm_bilinear_interp_instance_q7_methods[] = { DSPType(arm_bilinear_interp_instance_q7,arm_bilinear_interp_instance_q7_new,arm_bilinear_interp_instance_q7_dealloc,arm_bilinear_interp_instance_q7_init,arm_bilinear_interp_instance_q7_methods); +typedef struct { + PyObject_HEAD + arm_spline_instance_f32 *instance; +} dsp_arm_spline_instance_f32Object; + + +static void +arm_spline_instance_f32_dealloc(dsp_arm_spline_instance_f32Object* self) +{ + //printf("Dealloc called\n"); + if (self->instance) + { + + + if (self->instance->x) + { + PyMem_Free((float32_t *)self->instance->x); + } + + if (self->instance->y) + { + PyMem_Free((float32_t *)self->instance->y); + } + + if (self->instance->coeffs) + { + PyMem_Free((float32_t *)self->instance->coeffs); + } + + + PyMem_Free(self->instance); + } + + Py_TYPE(self)->tp_free((PyObject*)self); +} + + +static PyObject * +arm_spline_instance_f32_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + dsp_arm_spline_instance_f32Object *self; + //printf("New called\n"); + + self = (dsp_arm_spline_instance_f32Object *)type->tp_alloc(type, 0); + //printf("alloc called\n"); + + if (self != NULL) { + + self->instance = PyMem_Malloc(sizeof(arm_spline_instance_f32)); + + self->instance->x = NULL; + self->instance->y = NULL; + self->instance->coeffs = NULL; + + } + + + return (PyObject *)self; +} + +static int +arm_spline_instance_f32_init(dsp_arm_spline_instance_f32Object *self, PyObject *args, PyObject *kwds) +{ + + PyObject *x=NULL; + PyObject *y=NULL; + +char *kwlist[] = { +"type","x","y","n_x",NULL +}; + +if (PyArg_ParseTupleAndKeywords(args, kwds, "|iOOi", kwlist,&self->instance->type +,&x +,&y +,&self->instance->type +)) + { + + INITARRAYFIELD(x,NPY_DOUBLE,double,float32_t); + INITARRAYFIELD(y,NPY_DOUBLE,double,float32_t); + + } + return 0; +} + +GETFIELD(arm_spline_instance_f32,type,"i"); +GETFIELD(arm_spline_instance_f32,n_x,"i"); + + +static PyMethodDef arm_spline_instance_f32_methods[] = { + + {"type", (PyCFunction) Method_arm_spline_instance_f32_type,METH_NOARGS,"type"}, + {"n_x", (PyCFunction) Method_arm_spline_instance_f32_n_x,METH_NOARGS,"n_x"}, + + {NULL} /* Sentinel */ +}; + + +DSPType(arm_spline_instance_f32,arm_spline_instance_f32_new,arm_spline_instance_f32_dealloc,arm_spline_instance_f32_init,arm_spline_instance_f32_methods); + + void typeRegistration(PyObject *module) { @@ -474,7 +575,8 @@ void typeRegistration(PyObject *module) { ADDTYPE(arm_bilinear_interp_instance_q31); ADDTYPE(arm_bilinear_interp_instance_q15); ADDTYPE(arm_bilinear_interp_instance_q7); - + ADDTYPE(arm_spline_instance_f32); + } @@ -697,7 +799,76 @@ cmsis_arm_bilinear_interp_q7(PyObject *obj, PyObject *args) +static PyObject * +cmsis_arm_spline_init_f32(PyObject *obj, PyObject *args) +{ + + PyObject *S=NULL; // input + uint32_t type; + PyObject *pX=NULL; // input + float32_t *pX_converted=NULL; // input + PyObject *pY=NULL; // input + float32_t *pY_converted=NULL; // input + uint32_t n; + + if (PyArg_ParseTuple(args,"OiOO",&S,&type,&pX,&pY)) + { + + dsp_arm_spline_instance_f32Object *selfS = (dsp_arm_spline_instance_f32Object *)S; + + GETARGUMENT(pX,NPY_DOUBLE,double,float32_t); + GETARGUMENT(pY,NPY_DOUBLE,double,float32_t); + n = arraySizepX ; + float32_t * coeffs=PyMem_Malloc(sizeof(float32_t)*n*3); + float32_t * tempBuffer=PyMem_Malloc(sizeof(float32_t)*n*2); + + arm_spline_init_f32(selfS->instance, + type,pX_converted,pY_converted,n,coeffs,tempBuffer); + + PyObject* theReturnOBJ=Py_BuildValue("i",0); + PyObject *pythonResult = Py_BuildValue("O",theReturnOBJ); + + Py_DECREF(theReturnOBJ); + PyMem_Free(tempBuffer); + return(pythonResult); + + } + return(NULL); +} + +static PyObject * +cmsis_arm_spline_f32(PyObject *obj, PyObject *args) +{ + + PyObject *S=NULL; // input + PyObject *pSrc=NULL; // input + float32_t *pSrc_converted=NULL; // input + float32_t *pDst=NULL; // output + uint32_t blockSize; // input + + if (PyArg_ParseTuple(args,"OO",&S,&pSrc)) + { + + dsp_arm_spline_instance_f32Object *selfS = (dsp_arm_spline_instance_f32Object *)S; + GETARGUMENT(pSrc,NPY_DOUBLE,double,float32_t); + blockSize = arraySizepSrc ; + + pDst=PyMem_Malloc(sizeof(float32_t)*blockSize); + + + arm_spline_f32(selfS->instance,pSrc_converted,pDst,blockSize); + FLOATARRAY1(pDstOBJ,blockSize,pDst); + + PyObject *pythonResult = Py_BuildValue("O",pDstOBJ); + + FREEARGUMENT(pSrc_converted); + Py_DECREF(pDstOBJ); + return(pythonResult); + + } + return(NULL); +} static PyMethodDef CMSISDSPMethods[] = { @@ -712,6 +883,8 @@ static PyMethodDef CMSISDSPMethods[] = { {"arm_bilinear_interp_q31", cmsis_arm_bilinear_interp_q31, METH_VARARGS,""}, {"arm_bilinear_interp_q15", cmsis_arm_bilinear_interp_q15, METH_VARARGS,""}, {"arm_bilinear_interp_q7", cmsis_arm_bilinear_interp_q7, METH_VARARGS,""}, +{"arm_spline_f32", cmsis_arm_spline_f32, METH_VARARGS,""}, +{"arm_spline_init_f32", cmsis_arm_spline_init_f32, METH_VARARGS,""}, {"error_out", (PyCFunction)error_out, METH_NOARGS, NULL}, {NULL, NULL, 0, NULL} /* Sentinel */ }; diff --git a/PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_matrix.c b/PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_matrix.c index a9ff80a6..20d03150 100755 --- a/PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_matrix.c +++ b/PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_matrix.c @@ -789,6 +789,36 @@ cmsis_arm_mat_trans_f32(PyObject *obj, PyObject *args) return(NULL); } +static PyObject * +cmsis_arm_mat_trans_f64(PyObject *obj, PyObject *args) +{ + + PyObject *pSrc=NULL; // input + arm_matrix_instance_f64 *pSrc_converted=NULL; // input + + if (PyArg_ParseTuple(args,"O",&pSrc)) + { + + arm_matrix_instance_f64 *pSrc_converted = f64MatrixFromNumpy(pSrc); + uint32_t row = pSrc_converted->numCols ; + uint32_t column = pSrc_converted->numRows ; + arm_matrix_instance_f64 *pDst_converted = createf64Matrix(row,column); + + arm_status returnValue = arm_mat_trans_f64(pSrc_converted,pDst_converted); + PyObject* theReturnOBJ=Py_BuildValue("i",returnValue); + PyObject* pDstOBJ=NumpyArrayFromf64Matrix(pDst_converted); + + PyObject *pythonResult = Py_BuildValue("OO",theReturnOBJ,pDstOBJ); + + Py_DECREF(theReturnOBJ); + FREEARGUMENT(pSrc_converted); + Py_DECREF(pDstOBJ); + return(pythonResult); + + } + return(NULL); +} + static PyObject * cmsis_arm_mat_trans_q7(PyObject *obj, PyObject *args) { @@ -947,6 +977,40 @@ cmsis_arm_mat_mult_f32(PyObject *obj, PyObject *args) return(NULL); } +static PyObject * +cmsis_arm_mat_mult_f64(PyObject *obj, PyObject *args) +{ + + PyObject *pSrcA=NULL; // input + arm_matrix_instance_f64 *pSrcA_converted=NULL; // input + PyObject *pSrcB=NULL; // input + arm_matrix_instance_f64 *pSrcB_converted=NULL; // input + + if (PyArg_ParseTuple(args,"OO",&pSrcA,&pSrcB)) + { + + arm_matrix_instance_f64 *pSrcA_converted = f64MatrixFromNumpy(pSrcA); + arm_matrix_instance_f64 *pSrcB_converted = f64MatrixFromNumpy(pSrcB); + uint32_t row = pSrcA_converted->numRows ; + uint32_t column = pSrcB_converted->numCols ; + arm_matrix_instance_f64 *pDst_converted = createf64Matrix(row,column); + + arm_status returnValue = arm_mat_mult_f64(pSrcA_converted,pSrcB_converted,pDst_converted); + PyObject* theReturnOBJ=Py_BuildValue("i",returnValue); + PyObject* pDstOBJ=NumpyArrayFromf64Matrix(pDst_converted); + + PyObject *pythonResult = Py_BuildValue("OO",theReturnOBJ,pDstOBJ); + + Py_DECREF(theReturnOBJ); + FREEARGUMENT(pSrcA_converted); + FREEARGUMENT(pSrcB_converted); + Py_DECREF(pDstOBJ); + return(pythonResult); + + } + return(NULL); +} + static PyObject * cmsis_arm_mat_vec_mult_q15(PyObject *obj, PyObject *args) { @@ -1304,6 +1368,40 @@ cmsis_arm_mat_sub_f32(PyObject *obj, PyObject *args) return(NULL); } +static PyObject * +cmsis_arm_mat_sub_f64(PyObject *obj, PyObject *args) +{ + + PyObject *pSrcA=NULL; // input + arm_matrix_instance_f64 *pSrcA_converted=NULL; // input + PyObject *pSrcB=NULL; // input + arm_matrix_instance_f64 *pSrcB_converted=NULL; // input + + if (PyArg_ParseTuple(args,"OO",&pSrcA,&pSrcB)) + { + + arm_matrix_instance_f64 *pSrcA_converted = f64MatrixFromNumpy(pSrcA); + arm_matrix_instance_f64 *pSrcB_converted = f64MatrixFromNumpy(pSrcB); + uint32_t row = pSrcA_converted->numRows ; + uint32_t column = pSrcB_converted->numCols ; + arm_matrix_instance_f64 *pDst_converted = createf64Matrix(row,column); + + arm_status returnValue = arm_mat_sub_f64(pSrcA_converted,pSrcB_converted,pDst_converted); + PyObject* theReturnOBJ=Py_BuildValue("i",returnValue); + PyObject* pDstOBJ=NumpyArrayFromf64Matrix(pDst_converted); + + PyObject *pythonResult = Py_BuildValue("OO",theReturnOBJ,pDstOBJ); + + Py_DECREF(theReturnOBJ); + FREEARGUMENT(pSrcA_converted); + FREEARGUMENT(pSrcB_converted); + Py_DECREF(pDstOBJ); + return(pythonResult); + + } + return(NULL); +} + static PyObject * cmsis_arm_mat_sub_q15(PyObject *obj, PyObject *args) @@ -1536,7 +1634,285 @@ cmsis_arm_mat_inverse_f64(PyObject *obj, PyObject *args) } +static PyObject * +cmsis_arm_mat_cholesky_f32(PyObject *obj, PyObject *args) +{ + + PyObject *src=NULL; // input + arm_matrix_instance_f32 *src_converted=NULL; // input + + if (PyArg_ParseTuple(args,"O",&src)) + { + + arm_matrix_instance_f32 *src_converted = f32MatrixFromNumpy(src); + uint32_t column = src_converted->numCols ; + uint32_t row = src_converted->numRows ; + arm_matrix_instance_f32 *dst_converted = createf32Matrix(row,column); + + arm_status returnValue = arm_mat_cholesky_f32(src_converted,dst_converted); + PyObject* theReturnOBJ=Py_BuildValue("i",returnValue); + PyObject* dstOBJ=NumpyArrayFromf32Matrix(dst_converted); + + PyObject *pythonResult = Py_BuildValue("OO",theReturnOBJ,dstOBJ); + + Py_DECREF(theReturnOBJ); + FREEARGUMENT(src_converted); + Py_DECREF(dstOBJ); + return(pythonResult); + + } + return(NULL); +} + +static PyObject * +cmsis_arm_mat_cholesky_f64(PyObject *obj, PyObject *args) +{ + + PyObject *src=NULL; // input + arm_matrix_instance_f64 *src_converted=NULL; // input + if (PyArg_ParseTuple(args,"O",&src)) + { + + arm_matrix_instance_f64 *src_converted = f64MatrixFromNumpy(src); + uint32_t column = src_converted->numCols ; + uint32_t row = src_converted->numRows ; + arm_matrix_instance_f64 *dst_converted = createf64Matrix(row,column); + + arm_status returnValue = arm_mat_cholesky_f64(src_converted,dst_converted); + PyObject* theReturnOBJ=Py_BuildValue("i",returnValue); + PyObject* dstOBJ=NumpyArrayFromf64Matrix(dst_converted); + + PyObject *pythonResult = Py_BuildValue("OO",theReturnOBJ,dstOBJ); + + Py_DECREF(theReturnOBJ); + FREEARGUMENT(src_converted); + Py_DECREF(dstOBJ); + return(pythonResult); + + } + return(NULL); +} + +static PyObject * +cmsis_arm_mat_ldlt_f32(PyObject *obj, PyObject *args) +{ + + PyObject *src=NULL; // input + arm_matrix_instance_f32 *src_converted=NULL; // input + + if (PyArg_ParseTuple(args,"O",&src)) + { + + arm_matrix_instance_f32 *src_converted = f32MatrixFromNumpy(src); + uint32_t column = src_converted->numCols ; + uint32_t row = src_converted->numRows ; + + arm_matrix_instance_f32 *l_converted = createf32Matrix(row,column); + arm_matrix_instance_f32 *d_converted = createf32Matrix(row,column); + + uint16_t *pPerm=(uint16_t *)PyMem_Malloc(sizeof(uint16_t)*row); + INT16ARRAY1(pPermOBJ,row,pPerm); + + arm_status returnValue = arm_mat_ldlt_f32(src_converted,l_converted,d_converted,pPerm); + PyObject* theReturnOBJ=Py_BuildValue("i",returnValue); + + PyObject* lOBJ=NumpyArrayFromf32Matrix(l_converted); + PyObject* dOBJ=NumpyArrayFromf32Matrix(d_converted); + + + PyObject *pythonResult = Py_BuildValue("OOOO",theReturnOBJ,lOBJ,dOBJ,pPermOBJ); + + Py_DECREF(theReturnOBJ); + FREEARGUMENT(src_converted); + Py_DECREF(lOBJ); + Py_DECREF(dOBJ); + Py_DECREF(pPermOBJ); + + return(pythonResult); + + } + return(NULL); +} + +static PyObject * +cmsis_arm_mat_ldlt_f64(PyObject *obj, PyObject *args) +{ + + PyObject *src=NULL; // input + arm_matrix_instance_f64 *src_converted=NULL; // input + + if (PyArg_ParseTuple(args,"O",&src)) + { + + arm_matrix_instance_f64 *src_converted = f64MatrixFromNumpy(src); + uint32_t column = src_converted->numCols ; + uint32_t row = src_converted->numRows ; + + arm_matrix_instance_f64 *l_converted = createf64Matrix(row,column); + arm_matrix_instance_f64 *d_converted = createf64Matrix(row,column); + + uint16_t *pPerm=(uint16_t *)PyMem_Malloc(sizeof(uint16_t)*row); + INT16ARRAY1(pPermOBJ,row,pPerm); + + arm_status returnValue = arm_mat_ldlt_f64(src_converted,l_converted,d_converted,pPerm); + PyObject* theReturnOBJ=Py_BuildValue("i",returnValue); + + PyObject* lOBJ=NumpyArrayFromf64Matrix(l_converted); + PyObject* dOBJ=NumpyArrayFromf64Matrix(d_converted); + + + PyObject *pythonResult = Py_BuildValue("OOOO",theReturnOBJ,lOBJ,dOBJ,pPermOBJ); + + Py_DECREF(theReturnOBJ); + FREEARGUMENT(src_converted); + Py_DECREF(lOBJ); + Py_DECREF(dOBJ); + Py_DECREF(pPermOBJ); + + return(pythonResult); + + } + return(NULL); +} + +static PyObject * +cmsis_arm_mat_solve_lower_triangular_f32(PyObject *obj, PyObject *args) +{ + + PyObject *pSrcA=NULL; // input + arm_matrix_instance_f32 *pSrcA_converted=NULL; // input + PyObject *pSrcB=NULL; // input + arm_matrix_instance_f32 *pSrcB_converted=NULL; // input + + if (PyArg_ParseTuple(args,"OO",&pSrcA,&pSrcB)) + { + + arm_matrix_instance_f32 *pSrcA_converted = f32MatrixFromNumpy(pSrcA); + arm_matrix_instance_f32 *pSrcB_converted = f32MatrixFromNumpy(pSrcB); + uint32_t column = pSrcB_converted->numCols ; + uint32_t row = pSrcA_converted->numRows ; + + arm_matrix_instance_f32 *pDst_converted = createf32Matrix(row,column); + + arm_status returnValue = arm_mat_solve_lower_triangular_f32(pSrcA_converted,pSrcB_converted,pDst_converted); + PyObject* theReturnOBJ=Py_BuildValue("i",returnValue); + PyObject* pDstOBJ=NumpyArrayFromf32Matrix(pDst_converted); + + PyObject *pythonResult = Py_BuildValue("OO",theReturnOBJ,pDstOBJ); + + Py_DECREF(theReturnOBJ); + FREEARGUMENT(pSrcA_converted); + FREEARGUMENT(pSrcB_converted); + Py_DECREF(pDstOBJ); + return(pythonResult); + + } + return(NULL); +} + +static PyObject * +cmsis_arm_mat_solve_lower_triangular_f64(PyObject *obj, PyObject *args) +{ + + PyObject *pSrcA=NULL; // input + arm_matrix_instance_f64 *pSrcA_converted=NULL; // input + PyObject *pSrcB=NULL; // input + arm_matrix_instance_f64 *pSrcB_converted=NULL; // input + + if (PyArg_ParseTuple(args,"OO",&pSrcA,&pSrcB)) + { + + arm_matrix_instance_f64 *pSrcA_converted = f64MatrixFromNumpy(pSrcA); + arm_matrix_instance_f64 *pSrcB_converted = f64MatrixFromNumpy(pSrcB); + uint32_t column = pSrcB_converted->numCols ; + uint32_t row = pSrcA_converted->numRows ; + + arm_matrix_instance_f64 *pDst_converted = createf64Matrix(row,column); + + arm_status returnValue = arm_mat_solve_lower_triangular_f64(pSrcA_converted,pSrcB_converted,pDst_converted); + PyObject* theReturnOBJ=Py_BuildValue("i",returnValue); + PyObject* pDstOBJ=NumpyArrayFromf64Matrix(pDst_converted); + + PyObject *pythonResult = Py_BuildValue("OO",theReturnOBJ,pDstOBJ); + + Py_DECREF(theReturnOBJ); + FREEARGUMENT(pSrcA_converted); + FREEARGUMENT(pSrcB_converted); + Py_DECREF(pDstOBJ); + return(pythonResult); + + } + return(NULL); +} + +static PyObject * +cmsis_arm_mat_solve_upper_triangular_f32(PyObject *obj, PyObject *args) +{ + + PyObject *pSrcA=NULL; // input + arm_matrix_instance_f32 *pSrcA_converted=NULL; // input + PyObject *pSrcB=NULL; // input + arm_matrix_instance_f32 *pSrcB_converted=NULL; // input + + if (PyArg_ParseTuple(args,"OO",&pSrcA,&pSrcB)) + { + + arm_matrix_instance_f32 *pSrcA_converted = f32MatrixFromNumpy(pSrcA); + arm_matrix_instance_f32 *pSrcB_converted = f32MatrixFromNumpy(pSrcB); + uint32_t column = pSrcB_converted->numCols ; + uint32_t row = pSrcA_converted->numRows ; + arm_matrix_instance_f32 *pDst_converted = createf32Matrix(row,column); + + arm_status returnValue = arm_mat_solve_upper_triangular_f32(pSrcA_converted,pSrcB_converted,pDst_converted); + PyObject* theReturnOBJ=Py_BuildValue("i",returnValue); + PyObject* pDstOBJ=NumpyArrayFromf32Matrix(pDst_converted); + + PyObject *pythonResult = Py_BuildValue("OO",theReturnOBJ,pDstOBJ); + + Py_DECREF(theReturnOBJ); + FREEARGUMENT(pSrcA_converted); + FREEARGUMENT(pSrcB_converted); + Py_DECREF(pDstOBJ); + return(pythonResult); + + } + return(NULL); +} + +static PyObject * +cmsis_arm_mat_solve_upper_triangular_f64(PyObject *obj, PyObject *args) +{ + + PyObject *pSrcA=NULL; // input + arm_matrix_instance_f64 *pSrcA_converted=NULL; // input + PyObject *pSrcB=NULL; // input + arm_matrix_instance_f64 *pSrcB_converted=NULL; // input + + if (PyArg_ParseTuple(args,"OO",&pSrcA,&pSrcB)) + { + + arm_matrix_instance_f64 *pSrcA_converted = f64MatrixFromNumpy(pSrcA); + arm_matrix_instance_f64 *pSrcB_converted = f64MatrixFromNumpy(pSrcB); + uint32_t column = pSrcB_converted->numCols ; + uint32_t row = pSrcA_converted->numRows ; + arm_matrix_instance_f64 *pDst_converted = createf64Matrix(row,column); + + arm_status returnValue = arm_mat_solve_upper_triangular_f64(pSrcA_converted,pSrcB_converted,pDst_converted); + PyObject* theReturnOBJ=Py_BuildValue("i",returnValue); + PyObject* pDstOBJ=NumpyArrayFromf64Matrix(pDst_converted); + + PyObject *pythonResult = Py_BuildValue("OO",theReturnOBJ,pDstOBJ); + + Py_DECREF(theReturnOBJ); + FREEARGUMENT(pSrcA_converted); + FREEARGUMENT(pSrcB_converted); + Py_DECREF(pDstOBJ); + return(pythonResult); + + } + return(NULL); +} static PyMethodDef CMSISDSPMethods[] = { @@ -1547,6 +1923,7 @@ static PyMethodDef CMSISDSPMethods[] = { {"arm_mat_cmplx_mult_q15", cmsis_arm_mat_cmplx_mult_q15, METH_VARARGS,""}, {"arm_mat_cmplx_mult_q31", cmsis_arm_mat_cmplx_mult_q31, METH_VARARGS,""}, {"arm_mat_trans_f32", cmsis_arm_mat_trans_f32, METH_VARARGS,""}, +{"arm_mat_trans_f64", cmsis_arm_mat_trans_f64, METH_VARARGS,""}, {"arm_mat_trans_q15", cmsis_arm_mat_trans_q15, METH_VARARGS,""}, {"arm_mat_trans_q31", cmsis_arm_mat_trans_q31, METH_VARARGS,""}, {"arm_mat_trans_q7", cmsis_arm_mat_trans_q7, METH_VARARGS,""}, @@ -1558,6 +1935,7 @@ static PyMethodDef CMSISDSPMethods[] = { {"arm_mat_vec_mult_q7", cmsis_arm_mat_vec_mult_q7, METH_VARARGS,""}, {"arm_mat_mult_f32", cmsis_arm_mat_mult_f32, METH_VARARGS,""}, +{"arm_mat_mult_f64", cmsis_arm_mat_mult_f32, METH_VARARGS,""}, {"arm_mat_mult_q7", cmsis_arm_mat_mult_q7, 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,""}, @@ -1565,6 +1943,7 @@ static PyMethodDef CMSISDSPMethods[] = { {"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_f64", cmsis_arm_mat_sub_f64, METH_VARARGS,""}, {"arm_mat_sub_q15", cmsis_arm_mat_sub_q15, METH_VARARGS,""}, {"arm_mat_sub_q31", cmsis_arm_mat_sub_q31, METH_VARARGS,""}, {"arm_mat_scale_f32", cmsis_arm_mat_scale_f32, METH_VARARGS,""}, @@ -1575,7 +1954,16 @@ static PyMethodDef CMSISDSPMethods[] = { {"arm_mat_cmplx_trans_f32", cmsis_arm_mat_cmplx_trans_f32, METH_VARARGS,""}, {"arm_mat_cmplx_trans_q31", cmsis_arm_mat_cmplx_trans_q31, METH_VARARGS,""}, {"arm_mat_cmplx_trans_q15", cmsis_arm_mat_cmplx_trans_q15, METH_VARARGS,""}, +{"arm_mat_cholesky_f32", cmsis_arm_mat_cholesky_f32, METH_VARARGS,""}, +{"arm_mat_cholesky_f64", cmsis_arm_mat_cholesky_f64, METH_VARARGS,""}, +{"arm_mat_ldlt_f32", cmsis_arm_mat_ldlt_f32, METH_VARARGS,""}, +{"arm_mat_ldlt_f64", cmsis_arm_mat_ldlt_f64, METH_VARARGS,""}, +{"arm_mat_solve_lower_triangular_f32", cmsis_arm_mat_solve_lower_triangular_f32, METH_VARARGS,""}, +{"arm_mat_solve_lower_triangular_f64", cmsis_arm_mat_solve_lower_triangular_f64, METH_VARARGS,""}, +{"arm_mat_solve_upper_triangular_f32", cmsis_arm_mat_solve_upper_triangular_f32, METH_VARARGS,""}, +{"arm_mat_solve_upper_triangular_f64", cmsis_arm_mat_solve_upper_triangular_f64, METH_VARARGS,""}, {"error_out", (PyCFunction)error_out, METH_NOARGS, NULL}, + {NULL, NULL, 0, NULL} /* Sentinel */ }; diff --git a/PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_module.h b/PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_module.h index c9869a97..0b80194a 100644 --- a/PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_module.h +++ b/PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_module.h @@ -117,7 +117,7 @@ Method_##NAME##_##FIELD(dsp_##NAME##Object *self, PyObject *ignored)\ SRCFORMAT *f=(SRCFORMAT*)PyArray_DATA(FIELD##c); \ uint32_t n = PyArray_SIZE(FIELD##c); \ self->instance->FIELD =PyMem_Malloc(sizeof(DSTFORMAT)*n); \ - MEMCPY(self->instance->FIELD ,f,n,DSTFORMAT); \ + MEMCPY((DSTFORMAT*)self->instance->FIELD ,f,n,DSTFORMAT); \ Py_DECREF(FIELD##c); \ } \ } diff --git a/PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_statistics.c b/PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_statistics.c index 3be5f5ff..e774d1ce 100755 --- a/PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_statistics.c +++ b/PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_statistics.c @@ -51,7 +51,7 @@ cmsis_arm_power_q31(PyObject *obj, PyObject *args) PyObject *pSrc=NULL; // input q31_t *pSrc_converted=NULL; // input uint32_t blockSize; // input - q63_t *pResult=NULL; // output + q63_t pResult; // output if (PyArg_ParseTuple(args,"O",&pSrc)) { @@ -59,11 +59,9 @@ cmsis_arm_power_q31(PyObject *obj, PyObject *args) GETARGUMENT(pSrc,NPY_INT32,int32_t,int32_t); blockSize = arraySizepSrc ; - pResult=PyMem_Malloc(sizeof(q63_t)*1); - - arm_power_q31(pSrc_converted,blockSize,pResult); - PyObject* pResultOBJ=Py_BuildValue("L",*pResult); + arm_power_q31(pSrc_converted,blockSize,&pResult); + PyObject* pResultOBJ=Py_BuildValue("L",pResult); PyObject *pythonResult = Py_BuildValue("O",pResultOBJ); @@ -83,7 +81,7 @@ cmsis_arm_power_f32(PyObject *obj, PyObject *args) PyObject *pSrc=NULL; // input float32_t *pSrc_converted=NULL; // input uint32_t blockSize; // input - float32_t *pResult=NULL; // output + float32_t pResult; // output if (PyArg_ParseTuple(args,"O",&pSrc)) { @@ -91,11 +89,38 @@ cmsis_arm_power_f32(PyObject *obj, PyObject *args) GETARGUMENT(pSrc,NPY_DOUBLE,double,float32_t); blockSize = arraySizepSrc ; - pResult=PyMem_Malloc(sizeof(float32_t)*1); + + arm_power_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_power_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_power_f32(pSrc_converted,blockSize,pResult); - PyObject* pResultOBJ=Py_BuildValue("f",*pResult); + arm_power_f64(pSrc_converted,blockSize,&pResult); + PyObject* pResultOBJ=Py_BuildValue("d",pResult); PyObject *pythonResult = Py_BuildValue("O",pResultOBJ); @@ -115,7 +140,7 @@ cmsis_arm_power_q15(PyObject *obj, PyObject *args) PyObject *pSrc=NULL; // input q15_t *pSrc_converted=NULL; // input uint32_t blockSize; // input - q63_t *pResult=NULL; // output + q63_t pResult; // output if (PyArg_ParseTuple(args,"O",&pSrc)) { @@ -123,11 +148,10 @@ cmsis_arm_power_q15(PyObject *obj, PyObject *args) GETARGUMENT(pSrc,NPY_INT16,int16_t,int16_t); blockSize = arraySizepSrc ; - pResult=PyMem_Malloc(sizeof(q63_t)*1); - arm_power_q15(pSrc_converted,blockSize,pResult); - PyObject* pResultOBJ=Py_BuildValue("L",*pResult); + arm_power_q15(pSrc_converted,blockSize,&pResult); + PyObject* pResultOBJ=Py_BuildValue("L",pResult); PyObject *pythonResult = Py_BuildValue("O",pResultOBJ); @@ -147,7 +171,7 @@ cmsis_arm_power_q7(PyObject *obj, PyObject *args) PyObject *pSrc=NULL; // input q7_t *pSrc_converted=NULL; // input uint32_t blockSize; // input - q31_t *pResult=NULL; // output + q31_t pResult; // output if (PyArg_ParseTuple(args,"O",&pSrc)) { @@ -155,11 +179,9 @@ cmsis_arm_power_q7(PyObject *obj, PyObject *args) GETARGUMENT(pSrc,NPY_BYTE,int8_t,q7_t); blockSize = arraySizepSrc ; - pResult=PyMem_Malloc(sizeof(q31_t)*1); - - arm_power_q7(pSrc_converted,blockSize,pResult); - PyObject* pResultOBJ=Py_BuildValue("i",*pResult); + arm_power_q7(pSrc_converted,blockSize,&pResult); + PyObject* pResultOBJ=Py_BuildValue("i",pResult); PyObject *pythonResult = Py_BuildValue("O",pResultOBJ); @@ -179,7 +201,7 @@ cmsis_arm_mean_q7(PyObject *obj, PyObject *args) PyObject *pSrc=NULL; // input q7_t *pSrc_converted=NULL; // input uint32_t blockSize; // input - q7_t *pResult=NULL; // output + q7_t pResult; // output if (PyArg_ParseTuple(args,"O",&pSrc)) { @@ -187,11 +209,10 @@ cmsis_arm_mean_q7(PyObject *obj, PyObject *args) GETARGUMENT(pSrc,NPY_BYTE,int8_t,q7_t); blockSize = arraySizepSrc ; - pResult=PyMem_Malloc(sizeof(q7_t)*1); - arm_mean_q7(pSrc_converted,blockSize,pResult); - PyObject* pResultOBJ=Py_BuildValue("i",*pResult); + arm_mean_q7(pSrc_converted,blockSize,&pResult); + PyObject* pResultOBJ=Py_BuildValue("i",pResult); PyObject *pythonResult = Py_BuildValue("O",pResultOBJ); @@ -211,7 +232,7 @@ cmsis_arm_mean_q15(PyObject *obj, PyObject *args) PyObject *pSrc=NULL; // input q15_t *pSrc_converted=NULL; // input uint32_t blockSize; // input - q15_t *pResult=NULL; // output + q15_t pResult; // output if (PyArg_ParseTuple(args,"O",&pSrc)) { @@ -219,11 +240,10 @@ cmsis_arm_mean_q15(PyObject *obj, PyObject *args) GETARGUMENT(pSrc,NPY_INT16,int16_t,int16_t); blockSize = arraySizepSrc ; - pResult=PyMem_Malloc(sizeof(q15_t)*1); - arm_mean_q15(pSrc_converted,blockSize,pResult); - PyObject* pResultOBJ=Py_BuildValue("h",*pResult); + arm_mean_q15(pSrc_converted,blockSize,&pResult); + PyObject* pResultOBJ=Py_BuildValue("h",pResult); PyObject *pythonResult = Py_BuildValue("O",pResultOBJ); @@ -243,7 +263,7 @@ cmsis_arm_mean_q31(PyObject *obj, PyObject *args) PyObject *pSrc=NULL; // input q31_t *pSrc_converted=NULL; // input uint32_t blockSize; // input - q31_t *pResult=NULL; // output + q31_t pResult; // output if (PyArg_ParseTuple(args,"O",&pSrc)) { @@ -251,11 +271,10 @@ cmsis_arm_mean_q31(PyObject *obj, PyObject *args) GETARGUMENT(pSrc,NPY_INT32,int32_t,int32_t); blockSize = arraySizepSrc ; - pResult=PyMem_Malloc(sizeof(q31_t)*1); - arm_mean_q31(pSrc_converted,blockSize,pResult); - PyObject* pResultOBJ=Py_BuildValue("i",*pResult); + arm_mean_q31(pSrc_converted,blockSize,&pResult); + PyObject* pResultOBJ=Py_BuildValue("i",pResult); PyObject *pythonResult = Py_BuildValue("O",pResultOBJ); @@ -275,7 +294,7 @@ cmsis_arm_mean_f32(PyObject *obj, PyObject *args) PyObject *pSrc=NULL; // input float32_t *pSrc_converted=NULL; // input uint32_t blockSize; // input - float32_t *pResult=NULL; // output + float32_t pResult; // output if (PyArg_ParseTuple(args,"O",&pSrc)) { @@ -283,11 +302,9 @@ cmsis_arm_mean_f32(PyObject *obj, PyObject *args) GETARGUMENT(pSrc,NPY_DOUBLE,double,float32_t); blockSize = arraySizepSrc ; - pResult=PyMem_Malloc(sizeof(float32_t)*1); - - arm_mean_f32(pSrc_converted,blockSize,pResult); - PyObject* pResultOBJ=Py_BuildValue("f",*pResult); + arm_mean_f32(pSrc_converted,blockSize,&pResult); + PyObject* pResultOBJ=Py_BuildValue("f",pResult); PyObject *pythonResult = Py_BuildValue("O",pResultOBJ); @@ -299,6 +316,34 @@ cmsis_arm_mean_f32(PyObject *obj, PyObject *args) return(NULL); } +static PyObject * +cmsis_arm_mean_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_mean_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_var_f32(PyObject *obj, PyObject *args) @@ -307,7 +352,7 @@ cmsis_arm_var_f32(PyObject *obj, PyObject *args) PyObject *pSrc=NULL; // input float32_t *pSrc_converted=NULL; // input uint32_t blockSize; // input - float32_t *pResult=NULL; // output + float32_t pResult; // output if (PyArg_ParseTuple(args,"O",&pSrc)) { @@ -315,11 +360,10 @@ cmsis_arm_var_f32(PyObject *obj, PyObject *args) GETARGUMENT(pSrc,NPY_DOUBLE,double,float32_t); blockSize = arraySizepSrc ; - pResult=PyMem_Malloc(sizeof(float32_t)*1); - arm_var_f32(pSrc_converted,blockSize,pResult); - PyObject* pResultOBJ=Py_BuildValue("f",*pResult); + arm_var_f32(pSrc_converted,blockSize,&pResult); + PyObject* pResultOBJ=Py_BuildValue("f",pResult); PyObject *pythonResult = Py_BuildValue("O",pResultOBJ); @@ -331,6 +375,35 @@ cmsis_arm_var_f32(PyObject *obj, PyObject *args) return(NULL); } +static PyObject * +cmsis_arm_var_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_var_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_var_q31(PyObject *obj, PyObject *args) @@ -339,7 +412,7 @@ cmsis_arm_var_q31(PyObject *obj, PyObject *args) PyObject *pSrc=NULL; // input q31_t *pSrc_converted=NULL; // input uint32_t blockSize; // input - q31_t *pResult=NULL; // output + q31_t pResult; // output if (PyArg_ParseTuple(args,"O",&pSrc)) { @@ -347,11 +420,9 @@ cmsis_arm_var_q31(PyObject *obj, PyObject *args) GETARGUMENT(pSrc,NPY_INT32,int32_t,int32_t); blockSize = arraySizepSrc ; - pResult=PyMem_Malloc(sizeof(q31_t)*1); - - arm_var_q31(pSrc_converted,blockSize,pResult); - PyObject* pResultOBJ=Py_BuildValue("i",*pResult); + arm_var_q31(pSrc_converted,blockSize,&pResult); + PyObject* pResultOBJ=Py_BuildValue("i",pResult); PyObject *pythonResult = Py_BuildValue("O",pResultOBJ); @@ -371,7 +442,7 @@ cmsis_arm_var_q15(PyObject *obj, PyObject *args) PyObject *pSrc=NULL; // input q15_t *pSrc_converted=NULL; // input uint32_t blockSize; // input - q15_t *pResult=NULL; // output + q15_t pResult; // output if (PyArg_ParseTuple(args,"O",&pSrc)) { @@ -379,11 +450,8 @@ cmsis_arm_var_q15(PyObject *obj, PyObject *args) GETARGUMENT(pSrc,NPY_INT16,int16_t,int16_t); blockSize = arraySizepSrc ; - pResult=PyMem_Malloc(sizeof(q15_t)*1); - - - arm_var_q15(pSrc_converted,blockSize,pResult); - PyObject* pResultOBJ=Py_BuildValue("h",*pResult); + arm_var_q15(pSrc_converted,blockSize,&pResult); + PyObject* pResultOBJ=Py_BuildValue("h",pResult); PyObject *pythonResult = Py_BuildValue("O",pResultOBJ); @@ -403,7 +471,7 @@ cmsis_arm_rms_f32(PyObject *obj, PyObject *args) PyObject *pSrc=NULL; // input float32_t *pSrc_converted=NULL; // input uint32_t blockSize; // input - float32_t *pResult=NULL; // output + float32_t pResult; // output if (PyArg_ParseTuple(args,"O",&pSrc)) { @@ -411,11 +479,10 @@ cmsis_arm_rms_f32(PyObject *obj, PyObject *args) GETARGUMENT(pSrc,NPY_DOUBLE,double,float32_t); blockSize = arraySizepSrc ; - pResult=PyMem_Malloc(sizeof(float32_t)*1); - arm_rms_f32(pSrc_converted,blockSize,pResult); - PyObject* pResultOBJ=Py_BuildValue("f",*pResult); + arm_rms_f32(pSrc_converted,blockSize,&pResult); + PyObject* pResultOBJ=Py_BuildValue("f",pResult); PyObject *pythonResult = Py_BuildValue("O",pResultOBJ); @@ -435,7 +502,7 @@ cmsis_arm_rms_q31(PyObject *obj, PyObject *args) PyObject *pSrc=NULL; // input q31_t *pSrc_converted=NULL; // input uint32_t blockSize; // input - q31_t *pResult=NULL; // output + q31_t pResult; // output if (PyArg_ParseTuple(args,"O",&pSrc)) { @@ -443,11 +510,8 @@ cmsis_arm_rms_q31(PyObject *obj, PyObject *args) GETARGUMENT(pSrc,NPY_INT32,int32_t,int32_t); blockSize = arraySizepSrc ; - pResult=PyMem_Malloc(sizeof(q31_t)*1); - - - arm_rms_q31(pSrc_converted,blockSize,pResult); - PyObject* pResultOBJ=Py_BuildValue("i",*pResult); + arm_rms_q31(pSrc_converted,blockSize,&pResult); + PyObject* pResultOBJ=Py_BuildValue("i",pResult); PyObject *pythonResult = Py_BuildValue("O",pResultOBJ); @@ -467,7 +531,7 @@ cmsis_arm_rms_q15(PyObject *obj, PyObject *args) PyObject *pSrc=NULL; // input q15_t *pSrc_converted=NULL; // input uint32_t blockSize; // input - q15_t *pResult=NULL; // output + q15_t pResult; // output if (PyArg_ParseTuple(args,"O",&pSrc)) { @@ -475,11 +539,9 @@ cmsis_arm_rms_q15(PyObject *obj, PyObject *args) GETARGUMENT(pSrc,NPY_INT16,int16_t,int16_t); blockSize = arraySizepSrc ; - pResult=PyMem_Malloc(sizeof(q15_t)*1); - - arm_rms_q15(pSrc_converted,blockSize,pResult); - PyObject* pResultOBJ=Py_BuildValue("h",*pResult); + arm_rms_q15(pSrc_converted,blockSize,&pResult); + PyObject* pResultOBJ=Py_BuildValue("h",pResult); PyObject *pythonResult = Py_BuildValue("O",pResultOBJ); @@ -499,7 +561,7 @@ cmsis_arm_std_f32(PyObject *obj, PyObject *args) PyObject *pSrc=NULL; // input float32_t *pSrc_converted=NULL; // input uint32_t blockSize; // input - float32_t *pResult=NULL; // output + float32_t pResult; // output if (PyArg_ParseTuple(args,"O",&pSrc)) { @@ -507,11 +569,40 @@ cmsis_arm_std_f32(PyObject *obj, PyObject *args) GETARGUMENT(pSrc,NPY_DOUBLE,double,float32_t); blockSize = arraySizepSrc ; - pResult=PyMem_Malloc(sizeof(float32_t)*1); - arm_std_f32(pSrc_converted,blockSize,pResult); - PyObject* pResultOBJ=Py_BuildValue("f",*pResult); + arm_std_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_std_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_std_f64(pSrc_converted,blockSize,&pResult); + PyObject* pResultOBJ=Py_BuildValue("d",pResult); PyObject *pythonResult = Py_BuildValue("O",pResultOBJ); @@ -531,7 +622,7 @@ cmsis_arm_std_q31(PyObject *obj, PyObject *args) PyObject *pSrc=NULL; // input q31_t *pSrc_converted=NULL; // input uint32_t blockSize; // input - q31_t *pResult=NULL; // output + q31_t pResult; // output if (PyArg_ParseTuple(args,"O",&pSrc)) { @@ -539,11 +630,8 @@ cmsis_arm_std_q31(PyObject *obj, PyObject *args) GETARGUMENT(pSrc,NPY_INT32,int32_t,int32_t); blockSize = arraySizepSrc ; - pResult=PyMem_Malloc(sizeof(q31_t)*1); - - - arm_std_q31(pSrc_converted,blockSize,pResult); - PyObject* pResultOBJ=Py_BuildValue("i",*pResult); + arm_std_q31(pSrc_converted,blockSize,&pResult); + PyObject* pResultOBJ=Py_BuildValue("i",pResult); PyObject *pythonResult = Py_BuildValue("O",pResultOBJ); @@ -563,7 +651,7 @@ cmsis_arm_std_q15(PyObject *obj, PyObject *args) PyObject *pSrc=NULL; // input q15_t *pSrc_converted=NULL; // input uint32_t blockSize; // input - q15_t *pResult=NULL; // output + q15_t pResult; // output if (PyArg_ParseTuple(args,"O",&pSrc)) { @@ -571,11 +659,8 @@ cmsis_arm_std_q15(PyObject *obj, PyObject *args) GETARGUMENT(pSrc,NPY_INT16,int16_t,int16_t); blockSize = arraySizepSrc ; - pResult=PyMem_Malloc(sizeof(q15_t)*1); - - - arm_std_q15(pSrc_converted,blockSize,pResult); - PyObject* pResultOBJ=Py_BuildValue("h",*pResult); + arm_std_q15(pSrc_converted,blockSize,&pResult); + PyObject* pResultOBJ=Py_BuildValue("h",pResult); PyObject *pythonResult = Py_BuildValue("O",pResultOBJ); @@ -596,8 +681,8 @@ cmsis_arm_min_q7(PyObject *obj, PyObject *args) PyObject *pSrc=NULL; // input q7_t *pSrc_converted=NULL; // input uint32_t blockSize; // input - q7_t *pResult=NULL; // output - uint32_t *pIndex=NULL; // output + q7_t pResult; // output + uint32_t pIndex; // output if (PyArg_ParseTuple(args,"O",&pSrc)) { @@ -605,15 +690,10 @@ cmsis_arm_min_q7(PyObject *obj, PyObject *args) GETARGUMENT(pSrc,NPY_BYTE,int8_t,q7_t); blockSize = arraySizepSrc ; - pResult=PyMem_Malloc(sizeof(q7_t)*1); - - - pIndex=PyMem_Malloc(sizeof(uint32_t)*1); - - arm_min_q7(pSrc_converted,blockSize,pResult,pIndex); - PyObject* pResultOBJ=Py_BuildValue("i",*pResult); - PyObject* pIndexOBJ=Py_BuildValue("i",*pIndex); + arm_min_q7(pSrc_converted,blockSize,&pResult,&pIndex); + PyObject* pResultOBJ=Py_BuildValue("i",pResult); + PyObject* pIndexOBJ=Py_BuildValue("i",pIndex); PyObject *pythonResult = Py_BuildValue("OO",pResultOBJ,pIndexOBJ); @@ -659,8 +739,8 @@ cmsis_arm_absmin_q7(PyObject *obj, PyObject *args) PyObject *pSrc=NULL; // input q7_t *pSrc_converted=NULL; // input uint32_t blockSize; // input - q7_t *pResult=NULL; // output - uint32_t *pIndex=NULL; // output + q7_t pResult; // output + uint32_t pIndex; // output if (PyArg_ParseTuple(args,"O",&pSrc)) { @@ -668,15 +748,10 @@ cmsis_arm_absmin_q7(PyObject *obj, PyObject *args) GETARGUMENT(pSrc,NPY_BYTE,int8_t,q7_t); blockSize = arraySizepSrc ; - pResult=PyMem_Malloc(sizeof(q7_t)*1); - - - pIndex=PyMem_Malloc(sizeof(uint32_t)*1); - - arm_absmin_q7(pSrc_converted,blockSize,pResult,pIndex); - PyObject* pResultOBJ=Py_BuildValue("i",*pResult); - PyObject* pIndexOBJ=Py_BuildValue("i",*pIndex); + arm_absmin_q7(pSrc_converted,blockSize,&pResult,&pIndex); + PyObject* pResultOBJ=Py_BuildValue("i",pResult); + PyObject* pIndexOBJ=Py_BuildValue("i",pIndex); PyObject *pythonResult = Py_BuildValue("OO",pResultOBJ,pIndexOBJ); @@ -726,8 +801,8 @@ cmsis_arm_min_q15(PyObject *obj, PyObject *args) PyObject *pSrc=NULL; // input q15_t *pSrc_converted=NULL; // input uint32_t blockSize; // input - q15_t *pResult=NULL; // output - uint32_t *pIndex=NULL; // output + q15_t pResult; // output + uint32_t pIndex; // output if (PyArg_ParseTuple(args,"O",&pSrc)) { @@ -735,15 +810,10 @@ cmsis_arm_min_q15(PyObject *obj, PyObject *args) GETARGUMENT(pSrc,NPY_INT16,int16_t,int16_t); blockSize = arraySizepSrc ; - pResult=PyMem_Malloc(sizeof(q15_t)*1); - - pIndex=PyMem_Malloc(sizeof(uint32_t)*1); - - - arm_min_q15(pSrc_converted,blockSize,pResult,pIndex); - PyObject* pResultOBJ=Py_BuildValue("h",*pResult); - PyObject* pIndexOBJ=Py_BuildValue("i",*pIndex); + arm_min_q15(pSrc_converted,blockSize,&pResult,&pIndex); + PyObject* pResultOBJ=Py_BuildValue("h",pResult); + PyObject* pIndexOBJ=Py_BuildValue("i",pIndex); PyObject *pythonResult = Py_BuildValue("OO",pResultOBJ,pIndexOBJ); @@ -793,8 +863,8 @@ cmsis_arm_absmin_q15(PyObject *obj, PyObject *args) PyObject *pSrc=NULL; // input q15_t *pSrc_converted=NULL; // input uint32_t blockSize; // input - q15_t *pResult=NULL; // output - uint32_t *pIndex=NULL; // output + q15_t pResult; // output + uint32_t pIndex; // output if (PyArg_ParseTuple(args,"O",&pSrc)) { @@ -802,15 +872,9 @@ cmsis_arm_absmin_q15(PyObject *obj, PyObject *args) GETARGUMENT(pSrc,NPY_INT16,int16_t,int16_t); blockSize = arraySizepSrc ; - pResult=PyMem_Malloc(sizeof(q15_t)*1); - - - pIndex=PyMem_Malloc(sizeof(uint32_t)*1); - - - arm_absmin_q15(pSrc_converted,blockSize,pResult,pIndex); - PyObject* pResultOBJ=Py_BuildValue("h",*pResult); - PyObject* pIndexOBJ=Py_BuildValue("i",*pIndex); + arm_absmin_q15(pSrc_converted,blockSize,&pResult,&pIndex); + PyObject* pResultOBJ=Py_BuildValue("h",pResult); + PyObject* pIndexOBJ=Py_BuildValue("i",pIndex); PyObject *pythonResult = Py_BuildValue("OO",pResultOBJ,pIndexOBJ); @@ -861,8 +925,8 @@ cmsis_arm_min_q31(PyObject *obj, PyObject *args) PyObject *pSrc=NULL; // input q31_t *pSrc_converted=NULL; // input uint32_t blockSize; // input - q31_t *pResult=NULL; // output - uint32_t *pIndex=NULL; // output + q31_t pResult; // output + uint32_t pIndex; // output if (PyArg_ParseTuple(args,"O",&pSrc)) { @@ -870,15 +934,9 @@ cmsis_arm_min_q31(PyObject *obj, PyObject *args) GETARGUMENT(pSrc,NPY_INT32,int32_t,int32_t); blockSize = arraySizepSrc ; - pResult=PyMem_Malloc(sizeof(q31_t)*1); - - - pIndex=PyMem_Malloc(sizeof(uint32_t)*1); - - - arm_min_q31(pSrc_converted,blockSize,pResult,pIndex); - PyObject* pResultOBJ=Py_BuildValue("i",*pResult); - PyObject* pIndexOBJ=Py_BuildValue("i",*pIndex); + arm_min_q31(pSrc_converted,blockSize,&pResult,&pIndex); + PyObject* pResultOBJ=Py_BuildValue("i",pResult); + PyObject* pIndexOBJ=Py_BuildValue("i",pIndex); PyObject *pythonResult = Py_BuildValue("OO",pResultOBJ,pIndexOBJ); @@ -928,8 +986,8 @@ cmsis_arm_absmin_q31(PyObject *obj, PyObject *args) PyObject *pSrc=NULL; // input q31_t *pSrc_converted=NULL; // input uint32_t blockSize; // input - q31_t *pResult=NULL; // output - uint32_t *pIndex=NULL; // output + q31_t pResult; // output + uint32_t pIndex; // output if (PyArg_ParseTuple(args,"O",&pSrc)) { @@ -937,15 +995,10 @@ cmsis_arm_absmin_q31(PyObject *obj, PyObject *args) GETARGUMENT(pSrc,NPY_INT32,int32_t,int32_t); blockSize = arraySizepSrc ; - pResult=PyMem_Malloc(sizeof(q31_t)*1); - - pIndex=PyMem_Malloc(sizeof(uint32_t)*1); - - - arm_absmin_q31(pSrc_converted,blockSize,pResult,pIndex); - PyObject* pResultOBJ=Py_BuildValue("i",*pResult); - PyObject* pIndexOBJ=Py_BuildValue("i",*pIndex); + arm_absmin_q31(pSrc_converted,blockSize,&pResult,&pIndex); + PyObject* pResultOBJ=Py_BuildValue("i",pResult); + PyObject* pIndexOBJ=Py_BuildValue("i",pIndex); PyObject *pythonResult = Py_BuildValue("OO",pResultOBJ,pIndexOBJ); @@ -995,8 +1048,8 @@ cmsis_arm_min_f32(PyObject *obj, PyObject *args) PyObject *pSrc=NULL; // input float32_t *pSrc_converted=NULL; // input uint32_t blockSize; // input - float32_t *pResult=NULL; // output - uint32_t *pIndex=NULL; // output + float32_t pResult; // output + uint32_t pIndex; // output if (PyArg_ParseTuple(args,"O",&pSrc)) { @@ -1004,15 +1057,10 @@ cmsis_arm_min_f32(PyObject *obj, PyObject *args) GETARGUMENT(pSrc,NPY_DOUBLE,double,float32_t); blockSize = arraySizepSrc ; - pResult=PyMem_Malloc(sizeof(float32_t)*1); - - pIndex=PyMem_Malloc(sizeof(uint32_t)*1); - - - arm_min_f32(pSrc_converted,blockSize,pResult,pIndex); - PyObject* pResultOBJ=Py_BuildValue("f",*pResult); - PyObject* pIndexOBJ=Py_BuildValue("i",*pIndex); + arm_min_f32(pSrc_converted,blockSize,&pResult,&pIndex); + PyObject* pResultOBJ=Py_BuildValue("f",pResult); + PyObject* pIndexOBJ=Py_BuildValue("i",pIndex); PyObject *pythonResult = Py_BuildValue("OO",pResultOBJ,pIndexOBJ); @@ -1026,30 +1074,25 @@ cmsis_arm_min_f32(PyObject *obj, PyObject *args) } static PyObject * -cmsis_arm_absmin_f32(PyObject *obj, PyObject *args) +cmsis_arm_min_f64(PyObject *obj, PyObject *args) { PyObject *pSrc=NULL; // input - float32_t *pSrc_converted=NULL; // input + float64_t *pSrc_converted=NULL; // input uint32_t blockSize; // input - float32_t *pResult=NULL; // output - uint32_t *pIndex=NULL; // output + float64_t pResult; // output + uint32_t pIndex; // output if (PyArg_ParseTuple(args,"O",&pSrc)) { - GETARGUMENT(pSrc,NPY_DOUBLE,double,float32_t); + GETARGUMENT(pSrc,NPY_DOUBLE,double,float64_t); blockSize = arraySizepSrc ; - pResult=PyMem_Malloc(sizeof(float32_t)*1); - - - pIndex=PyMem_Malloc(sizeof(uint32_t)*1); - - arm_absmin_f32(pSrc_converted,blockSize,pResult,pIndex); - PyObject* pResultOBJ=Py_BuildValue("f",*pResult); - PyObject* pIndexOBJ=Py_BuildValue("i",*pIndex); + arm_min_f64(pSrc_converted,blockSize,&pResult,&pIndex); + PyObject* pResultOBJ=Py_BuildValue("d",pResult); + PyObject* pIndexOBJ=Py_BuildValue("i",pIndex); PyObject *pythonResult = Py_BuildValue("OO",pResultOBJ,pIndexOBJ); @@ -1062,38 +1105,29 @@ cmsis_arm_absmin_f32(PyObject *obj, PyObject *args) return(NULL); } - static PyObject * -cmsis_arm_max_q7(PyObject *obj, PyObject *args) +cmsis_arm_min_no_idx_f32(PyObject *obj, PyObject *args) { PyObject *pSrc=NULL; // input - q7_t *pSrc_converted=NULL; // input + float32_t *pSrc_converted=NULL; // input uint32_t blockSize; // input - q7_t *pResult=NULL; // output - uint32_t *pIndex=NULL; // output + float32_t pResult; // output if (PyArg_ParseTuple(args,"O",&pSrc)) { - GETARGUMENT(pSrc,NPY_BYTE,int8_t,q7_t); + GETARGUMENT(pSrc,NPY_DOUBLE,double,float32_t); blockSize = arraySizepSrc ; - pResult=PyMem_Malloc(sizeof(q7_t)*1); - - pIndex=PyMem_Malloc(sizeof(uint32_t)*1); + arm_min_no_idx_f32(pSrc_converted,blockSize,&pResult); + PyObject* pResultOBJ=Py_BuildValue("f",pResult); - - arm_max_q7(pSrc_converted,blockSize,pResult,pIndex); - PyObject* pResultOBJ=Py_BuildValue("i",*pResult); - PyObject* pIndexOBJ=Py_BuildValue("i",*pIndex); - - PyObject *pythonResult = Py_BuildValue("OO",pResultOBJ,pIndexOBJ); + PyObject *pythonResult = Py_BuildValue("O",pResultOBJ); FREEARGUMENT(pSrc_converted); Py_DECREF(pResultOBJ); - Py_DECREF(pIndexOBJ); return(pythonResult); } @@ -1101,60 +1135,54 @@ cmsis_arm_max_q7(PyObject *obj, PyObject *args) } static PyObject * -cmsis_arm_max_no_idx_q7(PyObject *obj, PyObject *args) +cmsis_arm_min_no_idx_f64(PyObject *obj, PyObject *args) { PyObject *pSrc=NULL; // input - q7_t *pSrc_converted=NULL; // input + float64_t *pSrc_converted=NULL; // input uint32_t blockSize; // input - q7_t pResult; // output + float64_t pResult; // output if (PyArg_ParseTuple(args,"O",&pSrc)) { - GETARGUMENT(pSrc,NPY_BYTE,int8_t,q7_t); + GETARGUMENT(pSrc,NPY_DOUBLE,double,float64_t); blockSize = arraySizepSrc ; + arm_min_no_idx_f64(pSrc_converted,blockSize,&pResult); + PyObject* pResultOBJ=Py_BuildValue("d",pResult); - - - arm_max_no_idx_q7(pSrc_converted,blockSize,&pResult); - PyObject* pResultOBJ=Py_BuildValue("i",pResult); - + PyObject *pythonResult = Py_BuildValue("O",pResultOBJ); FREEARGUMENT(pSrc_converted); - return(pResultOBJ); + Py_DECREF(pResultOBJ); + return(pythonResult); } return(NULL); } static PyObject * -cmsis_arm_absmax_q7(PyObject *obj, PyObject *args) +cmsis_arm_absmin_f32(PyObject *obj, PyObject *args) { PyObject *pSrc=NULL; // input - q7_t *pSrc_converted=NULL; // input + float32_t *pSrc_converted=NULL; // input uint32_t blockSize; // input - q7_t *pResult=NULL; // output - uint32_t *pIndex=NULL; // output + float32_t pResult; // output + uint32_t pIndex; // output if (PyArg_ParseTuple(args,"O",&pSrc)) { - GETARGUMENT(pSrc,NPY_BYTE,int8_t,q7_t); + GETARGUMENT(pSrc,NPY_DOUBLE,double,float32_t); blockSize = arraySizepSrc ; - pResult=PyMem_Malloc(sizeof(q7_t)*1); - - pIndex=PyMem_Malloc(sizeof(uint32_t)*1); - - - arm_absmax_q7(pSrc_converted,blockSize,pResult,pIndex); - PyObject* pResultOBJ=Py_BuildValue("i",*pResult); - PyObject* pIndexOBJ=Py_BuildValue("i",*pIndex); + arm_absmin_f32(pSrc_converted,blockSize,&pResult,&pIndex); + PyObject* pResultOBJ=Py_BuildValue("f",pResult); + PyObject* pIndexOBJ=Py_BuildValue("i",pIndex); PyObject *pythonResult = Py_BuildValue("OO",pResultOBJ,pIndexOBJ); @@ -1168,67 +1196,59 @@ cmsis_arm_absmax_q7(PyObject *obj, PyObject *args) } static PyObject * -cmsis_arm_absmax_no_idx_q7(PyObject *obj, PyObject *args) +cmsis_arm_absmin_f64(PyObject *obj, PyObject *args) { PyObject *pSrc=NULL; // input - q7_t *pSrc_converted=NULL; // input + float64_t *pSrc_converted=NULL; // input uint32_t blockSize; // input - q7_t pResult; // output + float64_t pResult; // output + uint32_t pIndex; // output if (PyArg_ParseTuple(args,"O",&pSrc)) { - GETARGUMENT(pSrc,NPY_BYTE,int8_t,q7_t); + GETARGUMENT(pSrc,NPY_DOUBLE,double,float64_t); blockSize = arraySizepSrc ; + arm_absmin_f64(pSrc_converted,blockSize,&pResult,&pIndex); + PyObject* pResultOBJ=Py_BuildValue("d",pResult); + PyObject* pIndexOBJ=Py_BuildValue("i",pIndex); - - - arm_absmax_no_idx_q7(pSrc_converted,blockSize,&pResult); - PyObject* pResultOBJ=Py_BuildValue("i",pResult); - + PyObject *pythonResult = Py_BuildValue("OO",pResultOBJ,pIndexOBJ); FREEARGUMENT(pSrc_converted); - return(pResultOBJ); + Py_DECREF(pResultOBJ); + Py_DECREF(pIndexOBJ); + return(pythonResult); } return(NULL); } - static PyObject * -cmsis_arm_max_q15(PyObject *obj, PyObject *args) +cmsis_arm_absmin_no_idx_f32(PyObject *obj, PyObject *args) { PyObject *pSrc=NULL; // input - q15_t *pSrc_converted=NULL; // input + float32_t *pSrc_converted=NULL; // input uint32_t blockSize; // input - q15_t *pResult=NULL; // output - uint32_t *pIndex=NULL; // output + float32_t pResult; // output if (PyArg_ParseTuple(args,"O",&pSrc)) { - GETARGUMENT(pSrc,NPY_INT16,int16_t,int16_t); + GETARGUMENT(pSrc,NPY_DOUBLE,double,float32_t); blockSize = arraySizepSrc ; - pResult=PyMem_Malloc(sizeof(q15_t)*1); - + arm_absmin_no_idx_f32(pSrc_converted,blockSize,&pResult); + PyObject* pResultOBJ=Py_BuildValue("f",pResult); - pIndex=PyMem_Malloc(sizeof(uint32_t)*1); - - - arm_max_q15(pSrc_converted,blockSize,pResult,pIndex); - PyObject* pResultOBJ=Py_BuildValue("h",*pResult); - PyObject* pIndexOBJ=Py_BuildValue("i",*pIndex); - - PyObject *pythonResult = Py_BuildValue("OO",pResultOBJ,pIndexOBJ); + PyObject *pythonResult = Py_BuildValue("O",pResultOBJ); FREEARGUMENT(pSrc_converted); Py_DECREF(pResultOBJ); - Py_DECREF(pIndexOBJ); return(pythonResult); } @@ -1236,60 +1256,54 @@ cmsis_arm_max_q15(PyObject *obj, PyObject *args) } static PyObject * -cmsis_arm_max_no_idx_q15(PyObject *obj, PyObject *args) +cmsis_arm_absmin_no_idx_f64(PyObject *obj, PyObject *args) { PyObject *pSrc=NULL; // input - q15_t *pSrc_converted=NULL; // input + float64_t *pSrc_converted=NULL; // input uint32_t blockSize; // input - q15_t pResult; // output + float64_t pResult; // output if (PyArg_ParseTuple(args,"O",&pSrc)) { - GETARGUMENT(pSrc,NPY_INT16,int16_t,int16_t); + GETARGUMENT(pSrc,NPY_DOUBLE,double,float64_t); blockSize = arraySizepSrc ; + arm_absmin_no_idx_f64(pSrc_converted,blockSize,&pResult); + PyObject* pResultOBJ=Py_BuildValue("d",pResult); - - - - arm_max_no_idx_q15(pSrc_converted,blockSize,&pResult); - PyObject* pResultOBJ=Py_BuildValue("h",pResult); - + PyObject *pythonResult = Py_BuildValue("O",pResultOBJ); FREEARGUMENT(pSrc_converted); - return(pResultOBJ); + Py_DECREF(pResultOBJ); + return(pythonResult); } return(NULL); } + static PyObject * -cmsis_arm_absmax_q15(PyObject *obj, PyObject *args) +cmsis_arm_max_q7(PyObject *obj, PyObject *args) { PyObject *pSrc=NULL; // input - q15_t *pSrc_converted=NULL; // input + q7_t *pSrc_converted=NULL; // input uint32_t blockSize; // input - q15_t *pResult=NULL; // output - uint32_t *pIndex=NULL; // output + q7_t pResult; // output + uint32_t pIndex; // output if (PyArg_ParseTuple(args,"O",&pSrc)) { - GETARGUMENT(pSrc,NPY_INT16,int16_t,int16_t); + GETARGUMENT(pSrc,NPY_BYTE,int8_t,q7_t); blockSize = arraySizepSrc ; - pResult=PyMem_Malloc(sizeof(q15_t)*1); - - pIndex=PyMem_Malloc(sizeof(uint32_t)*1); - - - arm_absmax_q15(pSrc_converted,blockSize,pResult,pIndex); - PyObject* pResultOBJ=Py_BuildValue("h",*pResult); - PyObject* pIndexOBJ=Py_BuildValue("i",*pIndex); + arm_max_q7(pSrc_converted,blockSize,&pResult,&pIndex); + PyObject* pResultOBJ=Py_BuildValue("i",pResult); + PyObject* pIndexOBJ=Py_BuildValue("i",pIndex); PyObject *pythonResult = Py_BuildValue("OO",pResultOBJ,pIndexOBJ); @@ -1303,13 +1317,107 @@ cmsis_arm_absmax_q15(PyObject *obj, PyObject *args) } static PyObject * -cmsis_arm_absmax_no_idx_q15(PyObject *obj, PyObject *args) +cmsis_arm_max_no_idx_q7(PyObject *obj, PyObject *args) { PyObject *pSrc=NULL; // input - q15_t *pSrc_converted=NULL; // input + q7_t *pSrc_converted=NULL; // input + uint32_t blockSize; // input + q7_t pResult; // output + + if (PyArg_ParseTuple(args,"O",&pSrc)) + { + + GETARGUMENT(pSrc,NPY_BYTE,int8_t,q7_t); + blockSize = arraySizepSrc ; + + + + + + arm_max_no_idx_q7(pSrc_converted,blockSize,&pResult); + PyObject* pResultOBJ=Py_BuildValue("i",pResult); + + + FREEARGUMENT(pSrc_converted); + return(pResultOBJ); + + } + return(NULL); +} + +static PyObject * +cmsis_arm_absmax_q7(PyObject *obj, PyObject *args) +{ + + PyObject *pSrc=NULL; // input + q7_t *pSrc_converted=NULL; // input + uint32_t blockSize; // input + q7_t pResult; // output + uint32_t pIndex; // output + + if (PyArg_ParseTuple(args,"O",&pSrc)) + { + + GETARGUMENT(pSrc,NPY_BYTE,int8_t,q7_t); + blockSize = arraySizepSrc ; + + + arm_absmax_q7(pSrc_converted,blockSize,&pResult,&pIndex); + PyObject* pResultOBJ=Py_BuildValue("i",pResult); + PyObject* pIndexOBJ=Py_BuildValue("i",pIndex); + + PyObject *pythonResult = Py_BuildValue("OO",pResultOBJ,pIndexOBJ); + + FREEARGUMENT(pSrc_converted); + Py_DECREF(pResultOBJ); + Py_DECREF(pIndexOBJ); + return(pythonResult); + + } + return(NULL); +} + +static PyObject * +cmsis_arm_absmax_no_idx_q7(PyObject *obj, PyObject *args) +{ + + PyObject *pSrc=NULL; // input + q7_t *pSrc_converted=NULL; // input + uint32_t blockSize; // input + q7_t pResult; // output + + if (PyArg_ParseTuple(args,"O",&pSrc)) + { + + GETARGUMENT(pSrc,NPY_BYTE,int8_t,q7_t); + blockSize = arraySizepSrc ; + + + + + + arm_absmax_no_idx_q7(pSrc_converted,blockSize,&pResult); + PyObject* pResultOBJ=Py_BuildValue("i",pResult); + + + FREEARGUMENT(pSrc_converted); + return(pResultOBJ); + + } + return(NULL); +} + + +static PyObject * +cmsis_arm_max_q15(PyObject *obj, PyObject *args) +{ + + PyObject *pSrc=NULL; // input + q15_t *pSrc_converted=NULL; // input uint32_t blockSize; // input q15_t pResult; // output + uint32_t pIndex; // output if (PyArg_ParseTuple(args,"O",&pSrc)) { @@ -1318,9 +1426,41 @@ cmsis_arm_absmax_no_idx_q15(PyObject *obj, PyObject *args) blockSize = arraySizepSrc ; + arm_max_q15(pSrc_converted,blockSize,&pResult,&pIndex); + PyObject* pResultOBJ=Py_BuildValue("h",pResult); + PyObject* pIndexOBJ=Py_BuildValue("i",pIndex); + + PyObject *pythonResult = Py_BuildValue("OO",pResultOBJ,pIndexOBJ); + FREEARGUMENT(pSrc_converted); + Py_DECREF(pResultOBJ); + Py_DECREF(pIndexOBJ); + return(pythonResult); - arm_absmax_no_idx_q15(pSrc_converted,blockSize,&pResult); + } + return(NULL); +} + +static PyObject * +cmsis_arm_max_no_idx_q15(PyObject *obj, PyObject *args) +{ + + PyObject *pSrc=NULL; // input + q15_t *pSrc_converted=NULL; // input + uint32_t blockSize; // input + q15_t pResult; // output + + if (PyArg_ParseTuple(args,"O",&pSrc)) + { + + GETARGUMENT(pSrc,NPY_INT16,int16_t,int16_t); + blockSize = arraySizepSrc ; + + + + + + arm_max_no_idx_q15(pSrc_converted,blockSize,&pResult); PyObject* pResultOBJ=Py_BuildValue("h",pResult); @@ -1331,32 +1471,86 @@ cmsis_arm_absmax_no_idx_q15(PyObject *obj, PyObject *args) return(NULL); } +static PyObject * +cmsis_arm_absmax_q15(PyObject *obj, PyObject *args) +{ + + PyObject *pSrc=NULL; // input + q15_t *pSrc_converted=NULL; // input + uint32_t blockSize; // input + q15_t pResult; // output + uint32_t pIndex; // output + + if (PyArg_ParseTuple(args,"O",&pSrc)) + { + + GETARGUMENT(pSrc,NPY_INT16,int16_t,int16_t); + blockSize = arraySizepSrc ; + + arm_absmax_q15(pSrc_converted,blockSize,&pResult,&pIndex); + PyObject* pResultOBJ=Py_BuildValue("h",pResult); + PyObject* pIndexOBJ=Py_BuildValue("i",pIndex); + + PyObject *pythonResult = Py_BuildValue("OO",pResultOBJ,pIndexOBJ); + + FREEARGUMENT(pSrc_converted); + Py_DECREF(pResultOBJ); + Py_DECREF(pIndexOBJ); + return(pythonResult); + + } + return(NULL); +} static PyObject * -cmsis_arm_max_q31(PyObject *obj, PyObject *args) +cmsis_arm_absmax_no_idx_q15(PyObject *obj, PyObject *args) { PyObject *pSrc=NULL; // input - q31_t *pSrc_converted=NULL; // input + q15_t *pSrc_converted=NULL; // input uint32_t blockSize; // input - q31_t *pResult=NULL; // output - uint32_t *pIndex=NULL; // output + q15_t pResult; // output if (PyArg_ParseTuple(args,"O",&pSrc)) { - GETARGUMENT(pSrc,NPY_INT32,int32_t,int32_t); + GETARGUMENT(pSrc,NPY_INT16,int16_t,int16_t); blockSize = arraySizepSrc ; - pResult=PyMem_Malloc(sizeof(q31_t)*1); - pIndex=PyMem_Malloc(sizeof(uint32_t)*1); + arm_absmax_no_idx_q15(pSrc_converted,blockSize,&pResult); + PyObject* pResultOBJ=Py_BuildValue("h",pResult); + + + FREEARGUMENT(pSrc_converted); + return(pResultOBJ); + + } + return(NULL); +} + + +static PyObject * +cmsis_arm_max_q31(PyObject *obj, PyObject *args) +{ + + PyObject *pSrc=NULL; // input + q31_t *pSrc_converted=NULL; // input + uint32_t blockSize; // input + q31_t pResult; // output + uint32_t pIndex; // output + + if (PyArg_ParseTuple(args,"O",&pSrc)) + { + + GETARGUMENT(pSrc,NPY_INT32,int32_t,int32_t); + blockSize = arraySizepSrc ; - arm_max_q31(pSrc_converted,blockSize,pResult,pIndex); - PyObject* pResultOBJ=Py_BuildValue("i",*pResult); - PyObject* pIndexOBJ=Py_BuildValue("i",*pIndex); + arm_max_q31(pSrc_converted,blockSize,&pResult,&pIndex); + PyObject* pResultOBJ=Py_BuildValue("i",pResult); + PyObject* pIndexOBJ=Py_BuildValue("i",pIndex); PyObject *pythonResult = Py_BuildValue("OO",pResultOBJ,pIndexOBJ); @@ -1406,8 +1600,8 @@ cmsis_arm_absmax_q31(PyObject *obj, PyObject *args) PyObject *pSrc=NULL; // input q31_t *pSrc_converted=NULL; // input uint32_t blockSize; // input - q31_t *pResult=NULL; // output - uint32_t *pIndex=NULL; // output + q31_t pResult; // output + uint32_t pIndex; // output if (PyArg_ParseTuple(args,"O",&pSrc)) { @@ -1415,15 +1609,9 @@ cmsis_arm_absmax_q31(PyObject *obj, PyObject *args) GETARGUMENT(pSrc,NPY_INT32,int32_t,int32_t); blockSize = arraySizepSrc ; - pResult=PyMem_Malloc(sizeof(q31_t)*1); - - - pIndex=PyMem_Malloc(sizeof(uint32_t)*1); - - - arm_absmax_q31(pSrc_converted,blockSize,pResult,pIndex); - PyObject* pResultOBJ=Py_BuildValue("i",*pResult); - PyObject* pIndexOBJ=Py_BuildValue("i",*pIndex); + arm_absmax_q31(pSrc_converted,blockSize,&pResult,&pIndex); + PyObject* pResultOBJ=Py_BuildValue("i",pResult); + PyObject* pIndexOBJ=Py_BuildValue("i",pIndex); PyObject *pythonResult = Py_BuildValue("OO",pResultOBJ,pIndexOBJ); @@ -1473,8 +1661,8 @@ cmsis_arm_max_f32(PyObject *obj, PyObject *args) PyObject *pSrc=NULL; // input float32_t *pSrc_converted=NULL; // input uint32_t blockSize; // input - float32_t *pResult=NULL; // output - uint32_t *pIndex=NULL; // output + float32_t pResult; // output + uint32_t pIndex; // output if (PyArg_ParseTuple(args,"O",&pSrc)) { @@ -1482,15 +1670,42 @@ cmsis_arm_max_f32(PyObject *obj, PyObject *args) GETARGUMENT(pSrc,NPY_DOUBLE,double,float32_t); blockSize = arraySizepSrc ; - pResult=PyMem_Malloc(sizeof(float32_t)*1); + arm_max_f32(pSrc_converted,blockSize,&pResult,&pIndex); + PyObject* pResultOBJ=Py_BuildValue("f",pResult); + PyObject* pIndexOBJ=Py_BuildValue("i",pIndex); + + PyObject *pythonResult = Py_BuildValue("OO",pResultOBJ,pIndexOBJ); + + FREEARGUMENT(pSrc_converted); + Py_DECREF(pResultOBJ); + Py_DECREF(pIndexOBJ); + return(pythonResult); + + } + return(NULL); +} + +static PyObject * +cmsis_arm_max_f64(PyObject *obj, PyObject *args) +{ + + PyObject *pSrc=NULL; // input + float64_t *pSrc_converted=NULL; // input + uint32_t blockSize; // input + float64_t pResult; // output + uint32_t pIndex; // output + + if (PyArg_ParseTuple(args,"O",&pSrc)) + { - pIndex=PyMem_Malloc(sizeof(uint32_t)*1); + GETARGUMENT(pSrc,NPY_DOUBLE,double,float64_t); + blockSize = arraySizepSrc ; - arm_max_f32(pSrc_converted,blockSize,pResult,pIndex); - PyObject* pResultOBJ=Py_BuildValue("f",*pResult); - PyObject* pIndexOBJ=Py_BuildValue("i",*pIndex); + arm_max_f64(pSrc_converted,blockSize,&pResult,&pIndex); + PyObject* pResultOBJ=Py_BuildValue("d",pResult); + PyObject* pIndexOBJ=Py_BuildValue("i",pIndex); PyObject *pythonResult = Py_BuildValue("OO",pResultOBJ,pIndexOBJ); @@ -1503,6 +1718,64 @@ cmsis_arm_max_f32(PyObject *obj, PyObject *args) return(NULL); } +static PyObject * +cmsis_arm_max_no_idx_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_max_no_idx_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_max_no_idx_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_max_no_idx_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_absmax_f32(PyObject *obj, PyObject *args) { @@ -1510,8 +1783,8 @@ cmsis_arm_absmax_f32(PyObject *obj, PyObject *args) PyObject *pSrc=NULL; // input float32_t *pSrc_converted=NULL; // input uint32_t blockSize; // input - float32_t *pResult=NULL; // output - uint32_t *pIndex=NULL; // output + float32_t pResult; // output + uint32_t pIndex; // output if (PyArg_ParseTuple(args,"O",&pSrc)) { @@ -1519,15 +1792,40 @@ cmsis_arm_absmax_f32(PyObject *obj, PyObject *args) GETARGUMENT(pSrc,NPY_DOUBLE,double,float32_t); blockSize = arraySizepSrc ; - pResult=PyMem_Malloc(sizeof(float32_t)*1); + arm_absmax_f32(pSrc_converted,blockSize,&pResult,&pIndex); + PyObject* pResultOBJ=Py_BuildValue("f",pResult); + PyObject* pIndexOBJ=Py_BuildValue("i",pIndex); + + PyObject *pythonResult = Py_BuildValue("OO",pResultOBJ,pIndexOBJ); + + FREEARGUMENT(pSrc_converted); + Py_DECREF(pResultOBJ); + Py_DECREF(pIndexOBJ); + return(pythonResult); + + } + return(NULL); +} + +static PyObject * +cmsis_arm_absmax_f64(PyObject *obj, PyObject *args) +{ + PyObject *pSrc=NULL; // input + float64_t *pSrc_converted=NULL; // input + uint32_t blockSize; // input + float64_t pResult; // output + uint32_t pIndex; // output - pIndex=PyMem_Malloc(sizeof(uint32_t)*1); + if (PyArg_ParseTuple(args,"O",&pSrc)) + { + GETARGUMENT(pSrc,NPY_DOUBLE,double,float64_t); + blockSize = arraySizepSrc ; - arm_absmax_f32(pSrc_converted,blockSize,pResult,pIndex); - PyObject* pResultOBJ=Py_BuildValue("f",*pResult); - PyObject* pIndexOBJ=Py_BuildValue("i",*pIndex); + arm_absmax_f64(pSrc_converted,blockSize,&pResult,&pIndex); + PyObject* pResultOBJ=Py_BuildValue("d",pResult); + PyObject* pIndexOBJ=Py_BuildValue("i",pIndex); PyObject *pythonResult = Py_BuildValue("OO",pResultOBJ,pIndexOBJ); @@ -1540,30 +1838,273 @@ cmsis_arm_absmax_f32(PyObject *obj, PyObject *args) return(NULL); } +static PyObject * +cmsis_arm_absmax_no_idx_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_absmax_no_idx_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_absmax_no_idx_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_absmax_no_idx_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_entropy_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 ; + + pResult=arm_entropy_f32(pSrc_converted,blockSize); + 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) +{ + + 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 ; + + pResult=arm_entropy_f64(pSrc_converted,blockSize); + 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) +{ + + PyObject *pSrcA=NULL; // input + float32_t *pSrcA_converted=NULL; // input + PyObject *pSrcB=NULL; // input + float32_t *pSrcB_converted=NULL; // input + uint32_t blockSize; // input + float32_t result; // output + + if (PyArg_ParseTuple(args,"OO",&pSrcA,&pSrcB)) + { + + GETARGUMENT(pSrcA,NPY_DOUBLE,double,float32_t); + GETARGUMENT(pSrcB,NPY_DOUBLE,double,float32_t); + blockSize = arraySizepSrcA ; + + + + result=arm_kullback_leibler_f32(pSrcA_converted,pSrcB_converted,blockSize); + PyObject* resultOBJ=Py_BuildValue("f",result); + + PyObject *pythonResult = Py_BuildValue("O",resultOBJ); + + FREEARGUMENT(pSrcA_converted); + FREEARGUMENT(pSrcB_converted); + Py_DECREF(resultOBJ); + return(pythonResult); + + } + return(NULL); +} + +static PyObject * +cmsis_arm_kullback_leibler_f64(PyObject *obj, PyObject *args) +{ + + PyObject *pSrcA=NULL; // input + float64_t *pSrcA_converted=NULL; // input + PyObject *pSrcB=NULL; // input + float64_t *pSrcB_converted=NULL; // input + uint32_t blockSize; // input + float64_t result; // output + + if (PyArg_ParseTuple(args,"OO",&pSrcA,&pSrcB)) + { + + GETARGUMENT(pSrcA,NPY_DOUBLE,double,float64_t); + GETARGUMENT(pSrcB,NPY_DOUBLE,double,float64_t); + blockSize = arraySizepSrcA ; + + + + result=arm_kullback_leibler_f64(pSrcA_converted,pSrcB_converted,blockSize); + PyObject* resultOBJ=Py_BuildValue("d",result); + + PyObject *pythonResult = Py_BuildValue("O",resultOBJ); + + FREEARGUMENT(pSrcA_converted); + FREEARGUMENT(pSrcB_converted); + Py_DECREF(resultOBJ); + return(pythonResult); + + } + return(NULL); +} + +static PyObject * +cmsis_arm_logsumexp_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 ; + + pResult=arm_logsumexp_f32(pSrc_converted,blockSize); + 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_logsumexp_dot_prod_f32(PyObject *obj, PyObject *args) +{ + + PyObject *pSrcA=NULL; // input + float32_t *pSrcA_converted=NULL; // input + PyObject *pSrcB=NULL; // input + float32_t *pSrcB_converted=NULL; // input + uint32_t blockSize; // input + float32_t result; // output + + if (PyArg_ParseTuple(args,"OO",&pSrcA,&pSrcB)) + { + + GETARGUMENT(pSrcA,NPY_DOUBLE,double,float32_t); + GETARGUMENT(pSrcB,NPY_DOUBLE,double,float32_t); + blockSize = arraySizepSrcA ; + float32_t *tmp=PyMem_Malloc(sizeof(float32_t)*blockSize); + result=arm_logsumexp_dot_prod_f32(pSrcA_converted,pSrcB_converted,blockSize,tmp); + PyMem_Free(tmp); + PyObject* resultOBJ=Py_BuildValue("f",result); + PyObject *pythonResult = Py_BuildValue("O",resultOBJ); + FREEARGUMENT(pSrcA_converted); + FREEARGUMENT(pSrcB_converted); + Py_DECREF(resultOBJ); + return(pythonResult); + + } + return(NULL); +} static PyMethodDef CMSISDSPMethods[] = { {"arm_power_q31", cmsis_arm_power_q31, METH_VARARGS,""}, {"arm_power_f32", cmsis_arm_power_f32, METH_VARARGS,""}, +{"arm_power_f64", cmsis_arm_power_f64, METH_VARARGS,""}, {"arm_power_q15", cmsis_arm_power_q15, METH_VARARGS,""}, {"arm_power_q7", cmsis_arm_power_q7, METH_VARARGS,""}, {"arm_mean_q7", cmsis_arm_mean_q7, METH_VARARGS,""}, {"arm_mean_q15", cmsis_arm_mean_q15, METH_VARARGS,""}, {"arm_mean_q31", cmsis_arm_mean_q31, METH_VARARGS,""}, {"arm_mean_f32", cmsis_arm_mean_f32, METH_VARARGS,""}, +{"arm_mean_f64", cmsis_arm_mean_f64, METH_VARARGS,""}, {"arm_var_f32", cmsis_arm_var_f32, METH_VARARGS,""}, +{"arm_var_f64", cmsis_arm_var_f64, METH_VARARGS,""}, {"arm_var_q31", cmsis_arm_var_q31, METH_VARARGS,""}, {"arm_var_q15", cmsis_arm_var_q15, METH_VARARGS,""}, {"arm_rms_f32", cmsis_arm_rms_f32, METH_VARARGS,""}, {"arm_rms_q31", cmsis_arm_rms_q31, METH_VARARGS,""}, {"arm_rms_q15", cmsis_arm_rms_q15, METH_VARARGS,""}, {"arm_std_f32", cmsis_arm_std_f32, METH_VARARGS,""}, +{"arm_std_f64", cmsis_arm_std_f64, METH_VARARGS,""}, + {"arm_std_q31", cmsis_arm_std_q31, METH_VARARGS,""}, {"arm_std_q15", cmsis_arm_std_q15, METH_VARARGS,""}, @@ -1574,6 +2115,10 @@ static PyMethodDef CMSISDSPMethods[] = { {"arm_min_q15", cmsis_arm_min_q15, METH_VARARGS,""}, {"arm_min_q31", cmsis_arm_min_q31, METH_VARARGS,""}, {"arm_min_f32", cmsis_arm_min_f32, METH_VARARGS,""}, +{"arm_min_f64", cmsis_arm_min_f64, METH_VARARGS,""}, +{"arm_min_no_idx_f32", cmsis_arm_min_no_idx_f32, METH_VARARGS,""}, +{"arm_min_no_idx_f64", cmsis_arm_min_no_idx_f64, METH_VARARGS,""}, + {"arm_absmin_q7", cmsis_arm_absmin_q7, METH_VARARGS,""}, {"arm_absmin_q15", cmsis_arm_absmin_q15, METH_VARARGS,""}, {"arm_absmin_q31", cmsis_arm_absmin_q31, METH_VARARGS,""}, @@ -1581,6 +2126,9 @@ static PyMethodDef CMSISDSPMethods[] = { {"arm_absmin_no_idx_q15", cmsis_arm_absmin_no_idx_q15, METH_VARARGS,""}, {"arm_absmin_no_idx_q31", cmsis_arm_absmin_no_idx_q31, METH_VARARGS,""}, {"arm_absmin_f32", cmsis_arm_absmin_f32, METH_VARARGS,""}, +{"arm_absmin_f64", cmsis_arm_absmin_f64, METH_VARARGS,""}, +{"arm_absmin_no_idx_f64", cmsis_arm_absmin_no_idx_f64, METH_VARARGS,""}, +{"arm_absmin_no_idx_f32", cmsis_arm_absmin_no_idx_f32, METH_VARARGS,""}, {"arm_max_q7", cmsis_arm_max_q7, METH_VARARGS,""}, {"arm_max_q15", cmsis_arm_max_q15, METH_VARARGS,""}, {"arm_max_q31", cmsis_arm_max_q31, METH_VARARGS,""}, @@ -1588,13 +2136,31 @@ static PyMethodDef CMSISDSPMethods[] = { {"arm_absmax_q15", cmsis_arm_absmax_q15, METH_VARARGS,""}, {"arm_absmax_q31", cmsis_arm_absmax_q31, METH_VARARGS,""}, {"arm_max_f32", cmsis_arm_max_f32, METH_VARARGS,""}, +{"arm_max_f64", cmsis_arm_max_f64, METH_VARARGS,""}, + +{"arm_max_no_idx_f32", cmsis_arm_max_no_idx_f32, METH_VARARGS,""}, +{"arm_max_no_idx_f64", cmsis_arm_max_no_idx_f64, METH_VARARGS,""}, + {"arm_absmax_f32", cmsis_arm_absmax_f32, METH_VARARGS,""}, +{"arm_absmax_f64", cmsis_arm_absmax_f64, METH_VARARGS,""}, + +{"arm_absmax_no_idx_f32", cmsis_arm_absmax_no_idx_f32, METH_VARARGS,""}, +{"arm_absmax_no_idx_f64", cmsis_arm_absmax_no_idx_f64, METH_VARARGS,""}, + {"arm_max_no_idx_q7", cmsis_arm_max_no_idx_q7, METH_VARARGS,""}, {"arm_max_no_idx_q15", cmsis_arm_max_no_idx_q15, METH_VARARGS,""}, {"arm_max_no_idx_q31", cmsis_arm_max_no_idx_q31, METH_VARARGS,""}, {"arm_absmax_no_idx_q7", cmsis_arm_absmax_no_idx_q7, METH_VARARGS,""}, {"arm_absmax_no_idx_q15", cmsis_arm_absmax_no_idx_q15, METH_VARARGS,""}, {"arm_absmax_no_idx_q31", cmsis_arm_absmax_no_idx_q31, METH_VARARGS,""}, +{"arm_entropy_f32", cmsis_arm_entropy_f32, METH_VARARGS,""}, +{"arm_entropy_f64", cmsis_arm_entropy_f64, METH_VARARGS,""}, +{"arm_kullback_leibler_f32", cmsis_arm_kullback_leibler_f32, METH_VARARGS,""}, +{"arm_kullback_leibler_f64", cmsis_arm_kullback_leibler_f64, METH_VARARGS,""}, + +{"arm_logsumexp_f32", cmsis_arm_logsumexp_f32, METH_VARARGS,""}, +{"arm_logsumexp_dot_prod_f32", cmsis_arm_logsumexp_dot_prod_f32, METH_VARARGS,""}, + {"error_out", (PyCFunction)error_out, METH_NOARGS, NULL}, {NULL, NULL, 0, NULL} /* Sentinel */ diff --git a/PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_support.c b/PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_support.c index e4a19611..0f39bddb 100755 --- a/PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_support.c +++ b/PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_support.c @@ -31,17 +31,146 @@ #include "cmsisdsp_module.h" +NUMPYVECTORFROMBUFFER(f32,float32_t,NPY_FLOAT); -NUMPYVECTORFROMBUFFER(f32,float32_t,NPY_FLOAT); +typedef struct { + PyObject_HEAD + arm_sort_instance_f32 *instance; +} dsp_arm_sort_instance_f32Object; + +static void +arm_sort_instance_f32_dealloc(dsp_arm_sort_instance_f32Object* self) +{ + //printf("Dealloc called\n"); + if (self->instance) + { + + PyMem_Free(self->instance); + } + + Py_TYPE(self)->tp_free((PyObject*)self); +} + +static PyObject * +arm_sort_instance_f32_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + dsp_arm_sort_instance_f32Object *self; + //printf("New called\n"); + + self = (dsp_arm_sort_instance_f32Object *)type->tp_alloc(type, 0); + //printf("alloc called\n"); + + if (self != NULL) { + + self->instance = PyMem_Malloc(sizeof(arm_sort_instance_f32)); + + } + + + return (PyObject *)self; +} + +static int +arm_sort_instance_f32_init(dsp_arm_sort_instance_f32Object *self, PyObject *args, PyObject *kwds) +{ + + PyObject *pState=NULL; + PyObject *pCoeffs=NULL; +char *kwlist[] = { +"arm_sort_alg","arm_sort_dir",NULL +}; + +uint16_t alg,dir; +if (PyArg_ParseTupleAndKeywords(args, kwds, "|hh", kwlist,&alg,&dir +)) + { + + self->instance->alg=alg; + self->instance->dir=dir; + } + return 0; +} + +static PyObject * +Method_arm_sort_instance_f32_alg(dsp_arm_sort_instance_f32Object *self, PyObject *ignored) +{ + return(Py_BuildValue("i",(int)self->instance->alg)); +} + +static PyObject * +Method_arm_sort_instance_f32_dir(dsp_arm_sort_instance_f32Object *self, PyObject *ignored) +{ + return(Py_BuildValue("i",(int)self->instance->dir)); +} + +static PyMethodDef arm_sort_instance_f32_methods[] = { + + {"alg", (PyCFunction) Method_arm_sort_instance_f32_alg,METH_NOARGS,"alg"}, + {"dir", (PyCFunction) Method_arm_sort_instance_f32_dir,METH_NOARGS,"dir"}, + + {NULL} /* Sentinel */ +}; + +DSPType(arm_sort_instance_f32,arm_sort_instance_f32_new,arm_sort_instance_f32_dealloc,arm_sort_instance_f32_init,arm_sort_instance_f32_methods); void typeRegistration(PyObject *module) { - + ADDTYPE(arm_sort_instance_f32); } +static PyObject * +cmsis_arm_sort_init_f32(PyObject *obj, PyObject *args) +{ + + PyObject *S=NULL; // input + uint16_t alg,dir; // input + + if (PyArg_ParseTuple(args,"Ohh",&S,&alg,&dir)) + { + + dsp_arm_sort_instance_f32Object *selfS = (dsp_arm_sort_instance_f32Object *)S; + arm_sort_init_f32(selfS->instance,alg,dir); + Py_RETURN_NONE; + + } + return(NULL); +} + +static PyObject * +cmsis_arm_sort_f32(PyObject *obj, PyObject *args) +{ + + PyObject *S=NULL; // input + PyObject *pSrc=NULL; // input + float32_t *pSrc_converted=NULL; // input + float32_t *pDst=NULL; // output + uint32_t blockSize; // input + + if (PyArg_ParseTuple(args,"OO",&S,&pSrc)) + { + + dsp_arm_sort_instance_f32Object *selfS = (dsp_arm_sort_instance_f32Object *)S; + GETARGUMENT(pSrc,NPY_DOUBLE,double,float32_t); + blockSize = arraySizepSrc ; + + pDst=PyMem_Malloc(sizeof(float32_t)*blockSize); + + + arm_sort_f32(selfS->instance,pSrc_converted,pDst,blockSize); + FLOATARRAY1(pDstOBJ,blockSize,pDst); + + PyObject *pythonResult = Py_BuildValue("O",pDstOBJ); + + FREEARGUMENT(pSrc_converted); + Py_DECREF(pDstOBJ); + return(pythonResult); + + } + return(NULL); +} static PyObject * @@ -70,6 +199,32 @@ cmsis_arm_fill_f32(PyObject *obj, PyObject *args) return(NULL); } +static PyObject * +cmsis_arm_fill_f64(PyObject *obj, PyObject *args) +{ + + float64_t value; // input + float64_t *pDst=NULL; // output + uint32_t blockSize; // input + + if (PyArg_ParseTuple(args,"di",&value,&blockSize)) + { + + pDst=PyMem_Malloc(sizeof(float64_t)*blockSize); + + + arm_fill_f64(value,pDst,blockSize); + FLOAT64ARRAY1(pDstOBJ,blockSize,pDst); + + PyObject *pythonResult = Py_BuildValue("O",pDstOBJ); + + Py_DECREF(pDstOBJ); + return(pythonResult); + + } + return(NULL); +} + static PyObject * cmsis_arm_fill_q31(PyObject *obj, PyObject *args) { @@ -181,6 +336,37 @@ cmsis_arm_copy_f32(PyObject *obj, PyObject *args) return(NULL); } +static PyObject * +cmsis_arm_copy_f64(PyObject *obj, PyObject *args) +{ + + PyObject *pSrc=NULL; // input + float64_t *pSrc_converted=NULL; // input + float64_t *pDst=NULL; // output + uint32_t blockSize; // input + + if (PyArg_ParseTuple(args,"O",&pSrc)) + { + + GETARGUMENT(pSrc,NPY_DOUBLE,double,float64_t); + blockSize = arraySizepSrc ; + + pDst=PyMem_Malloc(sizeof(float64_t)*blockSize); + + + arm_copy_f64(pSrc_converted,pDst,blockSize); + FLOAT64ARRAY1(pDstOBJ,blockSize,pDst); + + PyObject *pythonResult = Py_BuildValue("O",pDstOBJ); + + FREEARGUMENT(pSrc_converted); + Py_DECREF(pDstOBJ); + return(pythonResult); + + } + return(NULL); +} + static PyObject * cmsis_arm_copy_q7(PyObject *obj, PyObject *args) @@ -681,11 +867,103 @@ cmsis_arm_q15_to_q7(PyObject *obj, PyObject *args) } +static PyObject * +cmsis_arm_barycenter_f32(PyObject *obj, PyObject *args) +{ + PyObject *pSrcA=NULL; // input + float32_t *pSrcA_converted=NULL; // input + PyObject *pSrcB=NULL; // input + float32_t *pSrcB_converted=NULL; // input + float32_t *pDst=NULL; // output + uint32_t nbVectors,vecDim; -static PyMethodDef CMSISDSPMethods[] = { + if (PyArg_ParseTuple(args,"OOkk",&pSrcA,&pSrcB,&nbVectors,&vecDim)) + { + + GETARGUMENT(pSrcA,NPY_DOUBLE,double,float32_t); + GETARGUMENT(pSrcB,NPY_DOUBLE,double,float32_t); + + pDst=PyMem_Malloc(sizeof(float32_t)*vecDim); + + + arm_barycenter_f32(pSrcA_converted,pSrcB_converted,pDst,nbVectors,vecDim); + FLOATARRAY1(pDstOBJ,vecDim,pDst); + + PyObject *pythonResult = Py_BuildValue("O",pDstOBJ); + + FREEARGUMENT(pSrcA_converted); + FREEARGUMENT(pSrcB_converted); + Py_DECREF(pDstOBJ); + return(pythonResult); + + } + return(NULL); +} + +static PyObject * +cmsis_arm_weighted_sum_f32(PyObject *obj, PyObject *args) +{ + + PyObject *pSrcA=NULL; // input + float32_t *pSrcA_converted=NULL; // input + PyObject *pSrcB=NULL; // input + float32_t *pSrcB_converted=NULL; // input + float32_t dst; // output + uint32_t blockSize; + + if (PyArg_ParseTuple(args,"OO",&pSrcA,&pSrcB)) + { + + GETARGUMENT(pSrcA,NPY_DOUBLE,double,float32_t); + GETARGUMENT(pSrcB,NPY_DOUBLE,double,float32_t); + blockSize = arraySizepSrcA ; + + + dst=arm_weighted_sum_f32(pSrcA_converted,pSrcB_converted,blockSize); + PyObject* pDstOBJ=Py_BuildValue("f",dst); + PyObject *pythonResult = Py_BuildValue("O",pDstOBJ); + + FREEARGUMENT(pSrcA_converted); + FREEARGUMENT(pSrcB_converted); + Py_DECREF(pDstOBJ); + return(pythonResult); + + } + return(NULL); +} + +static PyObject * +cmsis_arm_div_q63_to_q31(PyObject *obj, PyObject *args) +{ + + PyObject *pSrc=NULL; // input + q63_t num; + q31_t den; + q31_t result; + + if (PyArg_ParseTuple(args,"Ll",&num,&den)) + { + + + result=arm_div_q63_to_q31(num,den); + + PyObject* resultOBJ=Py_BuildValue("l",result); + PyObject *pythonResult = Py_BuildValue("O",resultOBJ); + Py_DECREF(resultOBJ); + + return(pythonResult); + + } + return(NULL); +} + +static PyMethodDef CMSISDSPMethods[] = { + +{"arm_div_q63_to_q31", cmsis_arm_div_q63_to_q31, METH_VARARGS,""}, +{"arm_copy_f64", cmsis_arm_copy_f64, METH_VARARGS,""}, {"arm_copy_f32", cmsis_arm_copy_f32, METH_VARARGS,""}, {"arm_copy_q7", cmsis_arm_copy_q7, METH_VARARGS,""}, {"arm_copy_q15", cmsis_arm_copy_q15, METH_VARARGS,""}, @@ -708,11 +986,15 @@ static PyMethodDef CMSISDSPMethods[] = { {"arm_q15_to_q31", cmsis_arm_q15_to_q31, METH_VARARGS,""}, {"arm_q15_to_q7", cmsis_arm_q15_to_q7, METH_VARARGS,""}, - +{"arm_fill_f64", cmsis_arm_fill_f64, METH_VARARGS,""}, {"arm_fill_f32", cmsis_arm_fill_f32, METH_VARARGS,""}, {"arm_fill_q31", cmsis_arm_fill_q31, METH_VARARGS,""}, {"arm_fill_q15", cmsis_arm_fill_q15, METH_VARARGS,""}, {"arm_fill_q7", cmsis_arm_fill_q7, METH_VARARGS,""}, +{"arm_sort_f32", cmsis_arm_sort_f32, METH_VARARGS,""}, +{"arm_sort_init_f32", cmsis_arm_sort_init_f32, METH_VARARGS,""}, +{"arm_barycenter_f32", cmsis_arm_barycenter_f32, METH_VARARGS,""}, +{"arm_weighted_sum_f32", cmsis_arm_weighted_sum_f32, METH_VARARGS,""}, {"error_out", (PyCFunction)error_out, METH_NOARGS, NULL}, {NULL, NULL, 0, NULL} /* Sentinel */ diff --git a/PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_svm.c b/PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_svm.c new file mode 100755 index 00000000..995850be --- /dev/null +++ b/PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_svm.c @@ -0,0 +1,695 @@ +/* ---------------------------------------------------------------------- + * Project: CMSIS DSP Python Wrapper + * Title: cmsismodule.h + * Description: C code for the CMSIS-DSP Python wrapper + * + * $Date: 27 April 2021 + * $Revision: V1.0 + * + * Target Processor: Cortex-M cores + * -------------------------------------------------------------------- */ +/* + * Copyright (C) 2010-2021 ARM Limited or its affiliates. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define MODNAME "cmsisdsp_svm" +#define MODINITNAME cmsisdsp_svm + +#include "cmsisdsp_module.h" + + + +NUMPYVECTORFROMBUFFER(f32,float32_t,NPY_FLOAT); + + +#define SVMTYPE(NAME) \ +typedef struct { \ + PyObject_HEAD \ + arm_svm_##NAME##_instance_f32 *instance;\ +} dsp_arm_svm_##NAME##_instance_f32Object; + +SVMTYPE(linear); +SVMTYPE(polynomial); +SVMTYPE(rbf); +SVMTYPE(sigmoid); + +#define SVMTYPEDEALLOC(NAME) \ +static void \ +arm_svm_##NAME##_instance_f32_dealloc(dsp_arm_svm_##NAME##_instance_f32Object* self)\ +{ \ + if (self->instance) \ + { \ + \ + if (self->instance->dualCoefficients) \ + { \ + PyMem_Free((float32_t*)self->instance->dualCoefficients); \ + } \ + \ + if (self->instance->supportVectors) \ + { \ + PyMem_Free((float32_t*)self->instance->supportVectors); \ + } \ + \ + if (self->instance->classes) \ + { \ + PyMem_Free((float32_t*)self->instance->classes); \ + } \ + \ + PyMem_Free(self->instance); \ + } \ + \ + Py_TYPE(self)->tp_free((PyObject*)self); \ +} + +SVMTYPEDEALLOC(linear); +SVMTYPEDEALLOC(polynomial); +SVMTYPEDEALLOC(rbf); +SVMTYPEDEALLOC(sigmoid); + +#define SVMTYPENEW(NAME) \ +static PyObject * \ +arm_svm_##NAME##_instance_f32_new(PyTypeObject *type, PyObject *args, PyObject *kwds)\ +{ \ + dsp_arm_svm_##NAME##_instance_f32Object *self; \ + \ + self = (dsp_arm_svm_##NAME##_instance_f32Object *)type->tp_alloc(type, 0); \ + \ + if (self != NULL) { \ + \ + self->instance = PyMem_Malloc(sizeof(arm_svm_##NAME##_instance_f32)); \ + self->instance->dualCoefficients=NULL; \ + self->instance->supportVectors=NULL; \ + self->instance->classes=NULL; \ + \ + } \ + \ + \ + return (PyObject *)self; \ +} + +SVMTYPENEW(linear); +SVMTYPENEW(polynomial); +SVMTYPENEW(rbf); +SVMTYPENEW(sigmoid); + +/* + +LINEAR INIT + +*/ + +static int +arm_svm_linear_instance_f32_init(dsp_arm_svm_linear_instance_f32Object *self, PyObject *args, PyObject *kwds) +{ + +PyObject *dualCoefficients=NULL; +PyObject *supportVectors=NULL; +PyObject *classes=NULL; + +char *kwlist[] = { +"nbOfSupportVectors", +"vectorDimension", +"intercept", +"dualCoefficients", +"supportVectors", +"classes", +NULL +}; + +if (PyArg_ParseTupleAndKeywords(args, kwds, "|kkfOOO", kwlist, + &self->instance->nbOfSupportVectors +,&self->instance->vectorDimension +,&self->instance->intercept +,&dualCoefficients +,&supportVectors +,&classes +)) + { + + INITARRAYFIELD(dualCoefficients,NPY_DOUBLE,double,float32_t); + INITARRAYFIELD(supportVectors,NPY_DOUBLE,double,float32_t); + INITARRAYFIELD(classes,NPY_INT32,int32_t,int32_t); + } + return 0; +} + +GETFIELD(arm_svm_linear_instance_f32,nbOfSupportVectors,"k"); +GETFIELD(arm_svm_linear_instance_f32,vectorDimension,"k"); +GETFIELD(arm_svm_linear_instance_f32,intercept,"f"); + + +static PyMethodDef arm_svm_linear_instance_f32_methods[] = { + + {"nbOfSupportVectors", (PyCFunction) Method_arm_svm_linear_instance_f32_nbOfSupportVectors,METH_NOARGS,"nbOfSupportVectors"}, + {"vectorDimension", (PyCFunction) Method_arm_svm_linear_instance_f32_vectorDimension,METH_NOARGS,"vectorDimension"}, + {"intercept", (PyCFunction) Method_arm_svm_linear_instance_f32_intercept,METH_NOARGS,"intercept"}, + + {NULL} /* Sentinel */ +}; + +/* + +POLYNOMIAl INIT + +*/ + +static int +arm_svm_polynomial_instance_f32_init(dsp_arm_svm_polynomial_instance_f32Object *self, PyObject *args, PyObject *kwds) +{ + +PyObject *dualCoefficients=NULL; +PyObject *supportVectors=NULL; +PyObject *classes=NULL; + +char *kwlist[] = { +"nbOfSupportVectors", +"vectorDimension", +"intercept", +"dualCoefficients", +"supportVectors", +"classes", +"degree", +"coef0", +"gamma", +NULL +}; + +if (PyArg_ParseTupleAndKeywords(args, kwds, "|kkfOOOiff", kwlist, + &self->instance->nbOfSupportVectors +,&self->instance->vectorDimension +,&self->instance->intercept +,&dualCoefficients +,&supportVectors +,&classes +,&self->instance->degree +,&self->instance->coef0 +,&self->instance->gamma +)) + { + + INITARRAYFIELD(dualCoefficients,NPY_DOUBLE,double,float32_t); + INITARRAYFIELD(supportVectors,NPY_DOUBLE,double,float32_t); + INITARRAYFIELD(classes,NPY_INT32,int32_t,int32_t); + } + return 0; +} + +GETFIELD(arm_svm_polynomial_instance_f32,nbOfSupportVectors,"k"); +GETFIELD(arm_svm_polynomial_instance_f32,vectorDimension,"k"); +GETFIELD(arm_svm_polynomial_instance_f32,intercept,"f"); +GETFIELD(arm_svm_polynomial_instance_f32,degree,"i"); +GETFIELD(arm_svm_polynomial_instance_f32,coef0,"f"); +GETFIELD(arm_svm_polynomial_instance_f32,gamma,"f"); + + +static PyMethodDef arm_svm_polynomial_instance_f32_methods[] = { + + {"nbOfSupportVectors", (PyCFunction) Method_arm_svm_polynomial_instance_f32_nbOfSupportVectors,METH_NOARGS,"nbOfSupportVectors"}, + {"vectorDimension", (PyCFunction) Method_arm_svm_polynomial_instance_f32_vectorDimension,METH_NOARGS,"vectorDimension"}, + {"intercept", (PyCFunction) Method_arm_svm_polynomial_instance_f32_intercept,METH_NOARGS,"intercept"}, + {"degree", (PyCFunction) Method_arm_svm_polynomial_instance_f32_degree,METH_NOARGS,"degree"}, + {"coef0", (PyCFunction) Method_arm_svm_polynomial_instance_f32_coef0,METH_NOARGS,"coef0"}, + {"gamma", (PyCFunction) Method_arm_svm_polynomial_instance_f32_gamma,METH_NOARGS,"gamma"}, + + {NULL} /* Sentinel */ +}; + +/* + +RBF INIT + +*/ + + +static int +arm_svm_rbf_instance_f32_init(dsp_arm_svm_rbf_instance_f32Object *self, PyObject *args, PyObject *kwds) +{ + +PyObject *dualCoefficients=NULL; +PyObject *supportVectors=NULL; +PyObject *classes=NULL; + +char *kwlist[] = { +"nbOfSupportVectors", +"vectorDimension", +"intercept", +"dualCoefficients", +"supportVectors", +"classes", +"gamma", +NULL +}; + +if (PyArg_ParseTupleAndKeywords(args, kwds, "|kkfOOOf", kwlist, + &self->instance->nbOfSupportVectors +,&self->instance->vectorDimension +,&self->instance->intercept +,&dualCoefficients +,&supportVectors +,&classes +,&self->instance->gamma +)) + { + + INITARRAYFIELD(dualCoefficients,NPY_DOUBLE,double,float32_t); + INITARRAYFIELD(supportVectors,NPY_DOUBLE,double,float32_t); + INITARRAYFIELD(classes,NPY_INT32,int32_t,int32_t); + } + return 0; +} + +GETFIELD(arm_svm_rbf_instance_f32,nbOfSupportVectors,"k"); +GETFIELD(arm_svm_rbf_instance_f32,vectorDimension,"k"); +GETFIELD(arm_svm_rbf_instance_f32,intercept,"f"); +GETFIELD(arm_svm_rbf_instance_f32,gamma,"f"); + + +static PyMethodDef arm_svm_rbf_instance_f32_methods[] = { + + {"nbOfSupportVectors", (PyCFunction) Method_arm_svm_rbf_instance_f32_nbOfSupportVectors,METH_NOARGS,"nbOfSupportVectors"}, + {"vectorDimension", (PyCFunction) Method_arm_svm_rbf_instance_f32_vectorDimension,METH_NOARGS,"vectorDimension"}, + {"intercept", (PyCFunction) Method_arm_svm_rbf_instance_f32_intercept,METH_NOARGS,"intercept"}, + {"gamma", (PyCFunction) Method_arm_svm_rbf_instance_f32_gamma,METH_NOARGS,"gamma"}, + + {NULL} /* Sentinel */ +}; + +/* + +SIGMOID INIT + +*/ + +static int +arm_svm_sigmoid_instance_f32_init(dsp_arm_svm_sigmoid_instance_f32Object *self, PyObject *args, PyObject *kwds) +{ + +PyObject *dualCoefficients=NULL; +PyObject *supportVectors=NULL; +PyObject *classes=NULL; + +char *kwlist[] = { +"nbOfSupportVectors", +"vectorDimension", +"intercept", +"dualCoefficients", +"supportVectors", +"classes", +"coef0", +"gamma", +NULL +}; + +if (PyArg_ParseTupleAndKeywords(args, kwds, "|kkfOOOff", kwlist, + &self->instance->nbOfSupportVectors +,&self->instance->vectorDimension +,&self->instance->intercept +,&dualCoefficients +,&supportVectors +,&classes +,&self->instance->coef0 +,&self->instance->gamma +)) + { + + INITARRAYFIELD(dualCoefficients,NPY_DOUBLE,double,float32_t); + INITARRAYFIELD(supportVectors,NPY_DOUBLE,double,float32_t); + INITARRAYFIELD(classes,NPY_INT32,int32_t,int32_t); + } + return 0; +} + +GETFIELD(arm_svm_sigmoid_instance_f32,nbOfSupportVectors,"k"); +GETFIELD(arm_svm_sigmoid_instance_f32,vectorDimension,"k"); +GETFIELD(arm_svm_sigmoid_instance_f32,intercept,"f"); +GETFIELD(arm_svm_sigmoid_instance_f32,coef0,"f"); +GETFIELD(arm_svm_sigmoid_instance_f32,gamma,"f"); + + +static PyMethodDef arm_svm_sigmoid_instance_f32_methods[] = { + + {"nbOfSupportVectors", (PyCFunction) Method_arm_svm_sigmoid_instance_f32_nbOfSupportVectors,METH_NOARGS,"nbOfSupportVectors"}, + {"vectorDimension", (PyCFunction) Method_arm_svm_sigmoid_instance_f32_vectorDimension,METH_NOARGS,"vectorDimension"}, + {"intercept", (PyCFunction) Method_arm_svm_sigmoid_instance_f32_intercept,METH_NOARGS,"intercept"}, + {"coef0", (PyCFunction) Method_arm_svm_sigmoid_instance_f32_coef0,METH_NOARGS,"coef0"}, + {"gamma", (PyCFunction) Method_arm_svm_sigmoid_instance_f32_gamma,METH_NOARGS,"gamma"}, + + {NULL} /* Sentinel */ +}; + +DSPType(arm_svm_linear_instance_f32,arm_svm_linear_instance_f32_new,arm_svm_linear_instance_f32_dealloc,arm_svm_linear_instance_f32_init,arm_svm_linear_instance_f32_methods); +DSPType(arm_svm_polynomial_instance_f32,arm_svm_polynomial_instance_f32_new,arm_svm_polynomial_instance_f32_dealloc,arm_svm_polynomial_instance_f32_init,arm_svm_polynomial_instance_f32_methods); +DSPType(arm_svm_rbf_instance_f32,arm_svm_rbf_instance_f32_new,arm_svm_rbf_instance_f32_dealloc,arm_svm_rbf_instance_f32_init,arm_svm_rbf_instance_f32_methods); +DSPType(arm_svm_sigmoid_instance_f32,arm_svm_sigmoid_instance_f32_new,arm_svm_sigmoid_instance_f32_dealloc,arm_svm_sigmoid_instance_f32_init,arm_svm_sigmoid_instance_f32_methods); + + + + +void typeRegistration(PyObject *module) { + + + + ADDTYPE(arm_svm_linear_instance_f32); + ADDTYPE(arm_svm_polynomial_instance_f32); + ADDTYPE(arm_svm_rbf_instance_f32); + ADDTYPE(arm_svm_sigmoid_instance_f32); + + +} + +static PyObject * +cmsis_arm_svm_linear_init_f32(PyObject *obj, PyObject *args) +{ + + PyObject *S=NULL; // input + uint16_t numTaps; // input + PyObject *pdualCoefficients=NULL; // input + float32_t *pdualCoefficients_converted=NULL; // input + PyObject *psupportVectors=NULL; // input + float32_t *psupportVectors_converted=NULL; // input + PyObject *pclasses=NULL; // input + int32_t *pclasses_converted=NULL; // input + uint32_t blockSize; // input + + uint32_t nbOfSupportVectors; + uint32_t vectorDimension; + float32_t intercept; + + if (PyArg_ParseTuple(args,"OkkfOOO",&S, + &nbOfSupportVectors, + &vectorDimension, + &intercept, + &pdualCoefficients, + &psupportVectors, + &pclasses + )) + { + + dsp_arm_svm_linear_instance_f32Object *selfS = (dsp_arm_svm_linear_instance_f32Object *)S; + GETARGUMENT(pdualCoefficients,NPY_DOUBLE,double,float32_t); + GETARGUMENT(psupportVectors,NPY_DOUBLE,double,float32_t); + GETARGUMENT(pclasses,NPY_INT32,int32_t,int32_t); + + arm_svm_linear_init_f32(selfS->instance, + nbOfSupportVectors, + vectorDimension, + intercept, + pdualCoefficients_converted, + psupportVectors_converted, + pclasses_converted); + Py_RETURN_NONE; + + } + return(NULL); +} + +static PyObject * +cmsis_arm_svm_polynomial_init_f32(PyObject *obj, PyObject *args) +{ + + PyObject *S=NULL; // input + uint16_t numTaps; // input + PyObject *pdualCoefficients=NULL; // input + float32_t *pdualCoefficients_converted=NULL; // input + PyObject *psupportVectors=NULL; // input + float32_t *psupportVectors_converted=NULL; // input + PyObject *pclasses=NULL; // input + int32_t *pclasses_converted=NULL; // input + uint32_t blockSize; // input + + uint32_t nbOfSupportVectors; + uint32_t vectorDimension; + float32_t intercept; + int32_t degree; + float32_t coef0; + float32_t gamma; + + if (PyArg_ParseTuple(args,"OkkfOOOiff",&S, + &nbOfSupportVectors, + &vectorDimension, + &intercept, + &pdualCoefficients, + &psupportVectors, + &pclasses, + °ree, + &coef0, + &gamma + )) + { + + dsp_arm_svm_polynomial_instance_f32Object *selfS = (dsp_arm_svm_polynomial_instance_f32Object *)S; + GETARGUMENT(pdualCoefficients,NPY_DOUBLE,double,float32_t); + GETARGUMENT(psupportVectors,NPY_DOUBLE,double,float32_t); + GETARGUMENT(pclasses,NPY_INT32,int32_t,int32_t); + + arm_svm_polynomial_init_f32(selfS->instance, + nbOfSupportVectors, + vectorDimension, + intercept, + pdualCoefficients_converted, + psupportVectors_converted, + pclasses_converted, + degree, + coef0, + gamma + ); + Py_RETURN_NONE; + + } + return(NULL); +} + +static PyObject * +cmsis_arm_svm_rbf_init_f32(PyObject *obj, PyObject *args) +{ + + PyObject *S=NULL; // input + uint16_t numTaps; // input + PyObject *pdualCoefficients=NULL; // input + float32_t *pdualCoefficients_converted=NULL; // input + PyObject *psupportVectors=NULL; // input + float32_t *psupportVectors_converted=NULL; // input + PyObject *pclasses=NULL; // input + int32_t *pclasses_converted=NULL; // input + uint32_t blockSize; // input + + uint32_t nbOfSupportVectors; + uint32_t vectorDimension; + float32_t intercept; + float32_t gamma; + + if (PyArg_ParseTuple(args,"OkkfOOOf",&S, + &nbOfSupportVectors, + &vectorDimension, + &intercept, + &pdualCoefficients, + &psupportVectors, + &pclasses, + &gamma + )) + { + + dsp_arm_svm_rbf_instance_f32Object *selfS = (dsp_arm_svm_rbf_instance_f32Object *)S; + GETARGUMENT(pdualCoefficients,NPY_DOUBLE,double,float32_t); + GETARGUMENT(psupportVectors,NPY_DOUBLE,double,float32_t); + GETARGUMENT(pclasses,NPY_INT32,int32_t,int32_t); + + arm_svm_rbf_init_f32(selfS->instance, + nbOfSupportVectors, + vectorDimension, + intercept, + pdualCoefficients_converted, + psupportVectors_converted, + pclasses_converted, + gamma + ); + Py_RETURN_NONE; + + } + return(NULL); +} + +static PyObject * +cmsis_arm_svm_sigmoid_init_f32(PyObject *obj, PyObject *args) +{ + + PyObject *S=NULL; // input + uint16_t numTaps; // input + PyObject *pdualCoefficients=NULL; // input + float32_t *pdualCoefficients_converted=NULL; // input + PyObject *psupportVectors=NULL; // input + float32_t *psupportVectors_converted=NULL; // input + PyObject *pclasses=NULL; // input + int32_t *pclasses_converted=NULL; // input + uint32_t blockSize; // input + + uint32_t nbOfSupportVectors; + uint32_t vectorDimension; + float32_t intercept; + float32_t coef0; + float32_t gamma; + + if (PyArg_ParseTuple(args,"OkkfOOOff",&S, + &nbOfSupportVectors, + &vectorDimension, + &intercept, + &pdualCoefficients, + &psupportVectors, + &pclasses, + &coef0, + &gamma + )) + { + + dsp_arm_svm_sigmoid_instance_f32Object *selfS = (dsp_arm_svm_sigmoid_instance_f32Object *)S; + GETARGUMENT(pdualCoefficients,NPY_DOUBLE,double,float32_t); + GETARGUMENT(psupportVectors,NPY_DOUBLE,double,float32_t); + GETARGUMENT(pclasses,NPY_INT32,int32_t,int32_t); + + arm_svm_sigmoid_init_f32(selfS->instance, + nbOfSupportVectors, + vectorDimension, + intercept, + pdualCoefficients_converted, + psupportVectors_converted, + pclasses_converted, + coef0, + gamma + ); + Py_RETURN_NONE; + + } + return(NULL); +} + + +#define SVMPREDICT(NAME) \ +static PyObject * \ +cmsis_arm_svm_##NAME##_predict_f32(PyObject *obj, PyObject *args) \ +{ \ + \ + PyObject *S=NULL; \ + PyObject *pSrc=NULL; \ + float32_t *pSrc_converted=NULL; \ + int32_t dst; \ + uint32_t blockSize; \ + \ + if (PyArg_ParseTuple(args,"OO",&S,&pSrc)) \ + { \ + \ + dsp_arm_svm_##NAME##_instance_f32Object *selfS = (dsp_arm_svm_##NAME##_instance_f32Object *)S;\ + GETARGUMENT(pSrc,NPY_DOUBLE,double,float32_t); \ + \ + \ + \ + arm_svm_##NAME##_predict_f32(selfS->instance,pSrc_converted,&dst); \ + PyObject* resultOBJ=Py_BuildValue("i",dst); \ + PyObject *pythonResult = Py_BuildValue("O",resultOBJ); \ + \ + FREEARGUMENT(pSrc_converted); \ + Py_DECREF(resultOBJ); \ + return(pythonResult); \ + \ + } \ + return(NULL); \ +} + +SVMPREDICT(linear); +SVMPREDICT(polynomial); +SVMPREDICT(rbf); +SVMPREDICT(sigmoid); + +static PyMethodDef CMSISDSPMethods[] = { + + +{"arm_svm_linear_init_f32", cmsis_arm_svm_linear_init_f32, METH_VARARGS,""}, +{"arm_svm_linear_predict_f32", cmsis_arm_svm_linear_predict_f32, METH_VARARGS,""}, + +{"arm_svm_polynomial_init_f32", cmsis_arm_svm_polynomial_init_f32, METH_VARARGS,""}, +{"arm_svm_polynomial_predict_f32", cmsis_arm_svm_polynomial_predict_f32, METH_VARARGS,""}, + +{"arm_svm_rbf_init_f32", cmsis_arm_svm_rbf_init_f32, METH_VARARGS,""}, +{"arm_svm_rbf_predict_f32", cmsis_arm_svm_rbf_predict_f32, METH_VARARGS,""}, + +{"arm_svm_sigmoid_init_f32", cmsis_arm_svm_sigmoid_init_f32, METH_VARARGS,""}, +{"arm_svm_sigmoid_predict_f32", cmsis_arm_svm_sigmoid_predict_f32, METH_VARARGS,""}, + + {"error_out", (PyCFunction)error_out, METH_NOARGS, NULL}, + {NULL, NULL, 0, NULL} /* Sentinel */ +}; + +#ifdef IS_PY3K +static int cmsisdsp_traverse(PyObject *m, visitproc visit, void *arg) { + Py_VISIT(GETSTATE(m)->error); + return 0; +} + +static int cmsisdsp_clear(PyObject *m) { + Py_CLEAR(GETSTATE(m)->error); + return 0; +} + + +static struct PyModuleDef moduledef = { + PyModuleDef_HEAD_INIT, + MODNAME, + NULL, + sizeof(struct module_state), + CMSISDSPMethods, + NULL, + cmsisdsp_traverse, + cmsisdsp_clear, + NULL +}; + +#define INITERROR return NULL + +PyMODINIT_FUNC +CAT(PyInit_,MODINITNAME)(void) + + +#else +#define INITERROR return + +void CAT(init,MODINITNAME)(void) +#endif +{ + import_array(); + + #ifdef IS_PY3K + PyObject *module = PyModule_Create(&moduledef); + #else + PyObject *module = Py_InitModule(MODNAME, CMSISDSPMethods); + #endif + + if (module == NULL) + INITERROR; + struct module_state *st = GETSTATE(module); + + st->error = PyErr_NewException(MODNAME".Error", NULL, NULL); + if (st->error == NULL) { + Py_DECREF(module); + INITERROR; + } + + + typeRegistration(module); + + #ifdef IS_PY3K + return module; + #endif +} \ No newline at end of file diff --git a/PythonWrapper/examples/testdistance.py b/PythonWrapper/examples/testdistance.py new file mode 100755 index 00000000..d6e40666 --- /dev/null +++ b/PythonWrapper/examples/testdistance.py @@ -0,0 +1,185 @@ +import cmsisdsp as dsp +import numpy as np +import scipy.spatial.distance as d +from numpy.testing import assert_allclose + +a=[1,2,3] +b=[1,5,2] + +print("\nBray-Curtis") +ref=d.braycurtis(a,b) +res=dsp.arm_braycurtis_distance_f32(a,b) +print(ref) +print(res) +assert_allclose(ref,res,1e-6) + + +print("\nCanberra") +ref=d.canberra(a,b) +res=dsp.arm_canberra_distance_f32(a,b) +print(ref) +print(res) +assert_allclose(ref,res,1e-6) + +print("\nChebyshev") +ref=d.chebyshev(a,b) +res=dsp.arm_chebyshev_distance_f32(a,b) +print(ref) +print(res) +assert_allclose(ref,res,1e-6) + +res=dsp.arm_chebyshev_distance_f64(a,b) +print(res) +assert_allclose(ref,res,1e-10) + +print("\nCity Block") +ref=d.cityblock(a,b) +res=dsp.arm_cityblock_distance_f32(a,b) +print(ref) +print(res) +assert_allclose(ref,res,1e-6) + +res=dsp.arm_cityblock_distance_f64(a,b) +print(res) +assert_allclose(ref,res,1e-10) + +print("\nCorrelation") +ref=d.correlation(a,b) +res=dsp.arm_correlation_distance_f32(a,b) +print(ref) +print(res) +assert_allclose(ref,res,1e-6) + +print("\nCosine") +ref=d.cosine(a,b) +res=dsp.arm_cosine_distance_f32(a,b) +print(ref) +print(res) +assert_allclose(ref,res,1e-6) + +res=dsp.arm_cosine_distance_f64(a,b) +print(res) +assert_allclose(ref,res,1e-10) + +print("\nEuclidean") +ref=d.euclidean(a,b) +res=dsp.arm_euclidean_distance_f32(a,b) +print(ref) +print(res) +assert_allclose(ref,res,1e-6) + +res=dsp.arm_euclidean_distance_f64(a,b) +print(res) +assert_allclose(ref,res,1e-10) + +print("\nJensen-Shannon") +pa=a/np.sum(a) +pb=b/np.sum(b) +ref=d.jensenshannon(pa,pb) +res=dsp.arm_jensenshannon_distance_f32(pa,pb) +print(ref) +print(res) +assert_allclose(ref,res,1e-6) + +print("\nMinkowski") +w=3 +ref=d.minkowski(a,b,w) +res=dsp.arm_minkowski_distance_f32(a,b,w) +print(ref) +print(res) +assert_allclose(ref,res,1e-6) + +# Int distance +# For CMSIS-DSP the bool must be packed as bit arrays + +# Pack an array of boolean into uint32 +def packset(a): + b = np.packbits(a) + newSize = int(np.ceil(b.shape[0] / 4.0)) * 4 + c = np.copy(b) + c.resize(newSize) + #print(c) + vecSize = round(newSize/4) + c=c.reshape(vecSize,4) + #print(c) + r = np.zeros(vecSize) + result = [] + for i in range(0,vecSize): + #print(c[i,:]) + #print("%X %X %X %X" % (c[i,0],c[i,1],c[i,2],c[i,3])) + d = (c[i,0] << 24) | (c[i,1] << 16) | (c[i,2] << 8) | c[i,3] + result.append(np.uint32(d)) + return(result) + +nb = 34 +va = np.random.choice([0,1],nb) +# Array of word32 containing all of our bits +pva = packset(va) + + +vb = np.random.choice([0,1],nb) +# Array of word32 containing all of our bits +pvb = packset(vb) + +print("\nDice") +ref=d.dice(va,vb) +res=dsp.arm_dice_distance(pva,pvb,nb) +print(ref) +print(res) +assert_allclose(ref,res,1e-6) + +print("\nHamming") +ref=d.hamming(va,vb) +res=dsp.arm_hamming_distance(pva,pvb,nb) +print(ref) +print(res) +assert_allclose(ref,res,1e-6) + +print("\nJaccard-Needham") +ref=d.jaccard(va,vb) +res=dsp.arm_jaccard_distance(pva,pvb,nb) +print(ref) +print(res) +assert_allclose(ref,res,1e-6) + +print("\nKulsinski") +ref=d.kulsinski(va,vb) +res=dsp.arm_kulsinski_distance(pva,pvb,nb) +print(ref) +print(res) +assert_allclose(ref,res,1e-6) + +print("\nRogers-Tanimoto") +ref=d.rogerstanimoto(va,vb) +res=dsp.arm_rogerstanimoto_distance(pva,pvb,nb) +print(ref) +print(res) +assert_allclose(ref,res,1e-6) + +print("\nRussell-Rao") +ref=d.russellrao(va,vb) +res=dsp.arm_russellrao_distance(pva,pvb,nb) +print(ref) +print(res) +assert_allclose(ref,res,1e-6) + +print("\nSokal-Michener") +ref=d.sokalmichener(va,vb) +res=dsp.arm_sokalmichener_distance(pva,pvb,nb) +print(ref) +print(res) +assert_allclose(ref,res,1e-6) + +print("\nSokal-Sneath") +ref=d.sokalsneath(va,vb) +res=dsp.arm_sokalsneath_distance(pva,pvb,nb) +print(ref) +print(res) +assert_allclose(ref,res,1e-6) + +print("\nYule") +ref=d.yule(va,vb) +res=dsp.arm_yule_distance(pva,pvb,nb) +print(ref) +print(res) +assert_allclose(ref,res,1e-6) diff --git a/PythonWrapper/examples/testdsp5.py b/PythonWrapper/examples/testdsp5.py new file mode 100755 index 00000000..253a8fed --- /dev/null +++ b/PythonWrapper/examples/testdsp5.py @@ -0,0 +1,490 @@ +import cmsisdsp as dsp +import numpy as np +from numpy.testing import assert_allclose +from scipy.stats import entropy,tstd, tvar +from scipy.special import logsumexp +from scipy.linalg import cholesky,ldl,solve_triangular +from scipy import signal + +def imToReal1D(a): + ar=np.zeros(np.array(a.shape) * 2) + ar[0::2]=a.real + ar[1::2]=a.imag + return(ar) + +def realToIm1D(ar): + return(ar[0::2] + 1j * ar[1::2]) + +print("Max and AbsMax") +a=np.array([1.,-3.,4.,0.,-10.,8.]) + +i=dsp.arm_absmax_no_idx_f32(a) +print(i) +assert i==10.0 + +i=dsp.arm_absmax_no_idx_f64(a) +print(i) +assert i==10.0 + +r,i=dsp.arm_absmax_f64(a) +assert i==4 +assert r==10.0 + +r,i=dsp.arm_max_f64(a) +assert i==5 +assert r==8.0 + +i=dsp.arm_max_no_idx_f32(a) +print(i) +assert i==8 + +i=dsp.arm_max_no_idx_f64(a) +print(i) +assert i==8 + +print("Min and AbsMin") +a=np.array([1.,-3.,4.,0.5,-10.,8.]) + +i=dsp.arm_absmin_no_idx_f32(a) +print(i) +assert i==0.5 + +i=dsp.arm_absmin_no_idx_f64(a) +print(i) +assert i==0.5 + +r,i=dsp.arm_absmin_f64(a) +assert i==3 +assert r==0.5 + +r,i=dsp.arm_min_f64(a) +assert i==4 +assert r==-10 + +i=dsp.arm_min_no_idx_f32(a) +print(i) +assert i==-10 + +i=dsp.arm_min_no_idx_f64(a) +print(i) +assert i==-10 + +print("Barycenter") + +a=[0] * 12 +w=np.array([[2] * 12]) +w[0,11]=3 +a[0] =[0., 0., -0.951057] +a[1] =[0., 0., 0.951057] +a[2] =[-0.850651, 0., -0.425325] +a[3] =[0.850651, 0., 0.425325] +a[4] =[0.688191, -0.5, -0.425325] +a[5] =[0.688191, 0.5, -0.425325] +a[6] =[-0.688191, -0.5, 0.425325] +a[7] =[-0.688191, 0.5, 0.425325] +a[8] =[-0.262866, -0.809017, -0.425325] +a[9] =[-0.262866, 0.809017, -0.425325] +a[10]=[0.262866, -0.809017, 0.425325] +a[11]=[0.262866, 0.809017, 0.425325] + +scaled=a * w.T +ref=np.sum(scaled,axis=0)/np.sum(w) +print(ref) + +result=dsp.arm_barycenter_f32(np.array(a).reshape(12*3),w.reshape(12),12,3) +print(result) + +assert_allclose(ref,result,1e-6) + +print("Weighted sum") + +nb=10 +s = np.random.randn(nb) +w = np.random.randn(nb) + +ref=np.dot(s,w)/np.sum(w) +print(ref) + +res=dsp.arm_weighted_sum_f32(s,w) +print(res) + +assert_allclose(ref,res,2e-5) + +print("Entropy") +s = np.abs(np.random.randn(nb)) +s = s / np.sum(s) + +ref=entropy(s) +print(ref) +res=dsp.arm_entropy_f32(s) +print(res) +assert_allclose(ref,res,1e-6) + +res=dsp.arm_entropy_f64(s) +print(res) +assert_allclose(ref,res,1e-10) + +print("Kullback-Leibler") +sa = np.abs(np.random.randn(nb)) +sa = sa / np.sum(sa) + +sb = np.abs(np.random.randn(nb)) +sb = sb / np.sum(sb) + +ref=entropy(sa,sb) +print(ref) +res=dsp.arm_kullback_leibler_f32(sa,sb) +print(res) +assert_allclose(ref,res,1e-6) + +res=dsp.arm_kullback_leibler_f64(sa,sb) +print(res) +assert_allclose(ref,res,1e-10) + +print("Logsumexp") +s = np.abs(np.random.randn(nb)) +s = s / np.sum(s) + +ref=logsumexp(s) +print(ref) +res=dsp.arm_logsumexp_f32(s) +print(res) +assert_allclose(ref,res,1e-6) + +print("Logsumexp dot prod") +sa = np.abs(np.random.randn(nb)) +sa = sa / np.sum(sa) + +sb = np.abs(np.random.randn(nb)) +sb = sb / np.sum(sb) + +d = 0.001 +# It is a proba so must be in [0,1] +# But restricted to ]d,1] so that the log exists +sa = (1-d)*sa + d +sb = (1-d)*sb + d + +ref=np.log(np.dot(sa,sb)) +print(ref) + +sa = np.log(sa) +sb = np.log(sb) + +res=dsp.arm_logsumexp_dot_prod_f32(sa,sb) +print(res) +assert_allclose(ref,res,3e-6) + +print("vexp") +sa = np.random.randn(nb) + +ref = np.exp(sa) +print(ref) + +res=dsp.arm_vexp_f32(sa) +print(res) +assert_allclose(ref,res,1e-6) + +res=dsp.arm_vexp_f64(sa) +print(res) +assert_allclose(ref,res,1e-10) + + +print("vlog") +sa = np.abs(np.random.randn(nb)) + 0.001 + +ref = np.log(sa) +print(ref) + +res=dsp.arm_vlog_f32(sa) +print(res) +assert_allclose(ref,res,2e-5,1e-5) + +res=dsp.arm_vlog_f64(sa) +print(res) +assert_allclose(ref,res,2e-9,1e-9) + +print("Cholesky") + +a=np.array([[4,12,-16],[12,37,-43],[-16,-43,98]]) +ref=cholesky(a,lower=True) +print(ref) + +status,res=dsp.arm_mat_cholesky_f32(a) +print(res) +assert_allclose(ref,res,1e-6,1e-6) + +status,res=dsp.arm_mat_cholesky_f64(a) +print(res) +assert_allclose(ref,res,1e-10,1e-10) + +print("LDLT") + +def swaprow(m,k,j): + tmp = np.copy(m[j,:]) + m[j,:] = np.copy(m[k,:]) + m[k,:] = tmp + return(m) + +# F32 test +status,resl,resd,resperm=dsp.arm_mat_ldlt_f32(a) +n=3 +p=np.identity(n) +for k in range(0,n): + p = swaprow(p,k,resperm[k]) + +res=resl.dot(resd).dot(resl.T) + +permutedSrc=p.dot(a).dot(p.T) +print(res) +print(permutedSrc) + +assert_allclose(permutedSrc,res,1e-5,1e-5) + +# F64 test +print("LDLT F64") +status,resl,resd,resperm=dsp.arm_mat_ldlt_f64(a) +n=3 +p=np.identity(n) +for k in range(0,n): + p = swaprow(p,k,resperm[k]) + +res=resl.dot(resd).dot(resl.T) + +permutedSrc=p.dot(a).dot(p.T) +print(res) +print(permutedSrc) + +assert_allclose(permutedSrc,res,1e-9,1e-9) + +print("Solve lower triangular") +a = np.array([[3, 0, 0, 0], [2, 1, 0, 0], [1, 0, 1, 0], [1, 1, 1, 1]]) +b = np.array([[4,2,4,2],[8,4,8,4]]).T +x = solve_triangular(a, b,lower=True) +print(a) +print(b) +print(x) + +b = np.array([[4,2,4,2],[8,4,8,4]]).T +status,res=dsp.arm_mat_solve_lower_triangular_f32(a,b) +print(res) +assert_allclose(x,res,1e-5,1e-5) + + +b = np.array([[4,2,4,2],[8,4,8,4]]).T +status,res=dsp.arm_mat_solve_lower_triangular_f64(a,b) +print(res) +assert_allclose(x,res,1e-9,1e-9) + + +print("Solve upper triangular") +a = np.array([[3, 0, 0, 0], [2, 1, 0, 0], [1, 0, 1, 0], [1, 1, 1, 1]]) +b = np.array([[4,2,4,2],[8,4,8,4]]).T +x = solve_triangular(a.T, b,lower=False) +print(a.T) +print(b) +print(x) + +b = np.array([[4,2,4,2],[8,4,8,4]]).T +status,res=dsp.arm_mat_solve_upper_triangular_f32(a.T,b) +print(res) +assert_allclose(x,res,1e-5,1e-5) + + +b = np.array([[4,2,4,2],[8,4,8,4]]).T +status,res=dsp.arm_mat_solve_upper_triangular_f64(a.T,b) +print(res) +assert_allclose(x,res,1e-9,1e-9) + + +print("Mat mult f64") +a = np.array([[3, 0, 0, 0], [2, 1, 0, 0], [1, 0, 1, 0], [1, 1, 1, 1]]) +b = np.array([[4,2,4,2],[8,4,8,4]]).T + +ref =a.dot(b) +print(ref) + +status,res = dsp.arm_mat_mult_f64(a,b) +print(res) +assert_allclose(ref,res,1e-10,1e-10) + +print("mat sub f64") +a = np.array([[3, 0, 0, 0], [2, 1, 0, 0], [1, 0, 1, 0], [1, 1, 1, 1]]) +b = a.T + +ref = a - b +print(ref) + +status,res = dsp.arm_mat_sub_f64(a,b) +print(res) +assert_allclose(ref,res,1e-10,1e-10) + +print("abs f64") +s = np.random.randn(nb) +ref = np.abs(s) +res=dsp.arm_abs_f64(s) +print(ref) +print(res) +assert_allclose(ref,res,1e-10,1e-10) + +print("add f64") +sa = np.random.randn(nb) +sb = np.random.randn(nb) +ref = sa + sb +res=dsp.arm_add_f64(sa,sb) +print(ref) +print(res) +assert_allclose(ref,res,1e-10,1e-10) + +print("sub f64") +sa = np.random.randn(nb) +sb = np.random.randn(nb) +ref = sa - sb +res=dsp.arm_sub_f64(sa,sb) +print(ref) +print(res) +assert_allclose(ref,res,1e-10,1e-10) + +print("dot prod f64") +sa = np.random.randn(nb) +sb = np.random.randn(nb) +ref = sa.dot(sb) +res=dsp.arm_dot_prod_f64(sa,sb) +print(ref) +print(res) +assert_allclose(ref,res,1e-10,1e-10) + +print("mult f64") +sa = np.random.randn(nb) +sb = np.random.randn(nb) +ref = sa * sb +res=dsp.arm_mult_f64(sa,sb) +print(ref) +print(res) +assert_allclose(ref,res,1e-10,1e-10) + +print("negate f64") +sa = np.random.randn(nb) +ref = -sa +res=dsp.arm_negate_f64(sa) +print(ref) +print(res) +assert_allclose(ref,res,1e-10,1e-10) + +print("offset f64") +sa = np.random.randn(nb) +ref = sa + 0.1 +res=dsp.arm_offset_f64(sa,0.1) +print(ref) +print(res) +assert_allclose(ref,res,1e-10,1e-10) + +print("scale f64") +sa = np.random.randn(nb) +ref = sa * 0.1 +res=dsp.arm_scale_f64(sa,0.1) +print(ref) +print(res) +assert_allclose(ref,res,1e-10,1e-10) + +print("mean f64") +sa = np.random.randn(nb) +ref = np.mean(sa) +res=dsp.arm_mean_f64(sa) +print(ref) +print(res) +assert_allclose(ref,res,1e-10,1e-10) + +print("power f64") +sa = np.random.randn(nb) +ref = np.sum(sa * sa) +res=dsp.arm_power_f64(sa) +print(ref) +print(res) +assert_allclose(ref,res,1e-10,1e-10) + +print("std f64") +sa = np.random.randn(nb) +ref = tstd(sa) +res=dsp.arm_std_f64(sa) +print(ref) +print(res) +assert_allclose(ref,res,1e-10,1e-10) + +print("variance f64") +sa = np.random.randn(nb) +ref = tvar(sa) +res=dsp.arm_var_f64(sa) +print(ref) +print(res) +assert_allclose(ref,res,1e-10,1e-10) + +print("fill f64") +nb=20 +ref = np.ones(nb)*4.0 +res = dsp.arm_fill_f64(4.0,nb) +assert_allclose(ref,res,1e-10,1e-10) + +print("copy f64") +nb=20 +sa = np.random.randn(nb) +ref = sa +res = dsp.arm_copy_f64(sa) +assert_allclose(ref,res,1e-10,1e-10) + +print("arm_div_q63_to_q31") +den=0x7FFF00000000 +num=0x10000 +ref=den//num + +res=dsp.arm_div_q63_to_q31(den,num) +print(ref) +print(res) + +print("fir f64") + +firf64 = dsp.arm_fir_instance_f64() +dsp.arm_fir_init_f64(firf64,3,[1.,2,3],[0,0,0,0,0,0,0]) +filtered_x = signal.lfilter([3,2,1.], 1.0, [1,2,3,4,5,1,2,3,4,5]) +print(filtered_x) +ra=dsp.arm_fir_f64(firf64,[1,2,3,4,5]) +rb=dsp.arm_fir_f64(firf64,[1,2,3,4,5]) +assert ((filtered_x == np.hstack([ra,rb])).all) + +print("arm_cmplx_mag") +sa = np.random.randn(nb) +ca = realToIm1D(sa) +ref = np.abs(ca) +print(ref) +res=dsp.arm_cmplx_mag_f32(sa) +print(res) +assert_allclose(ref,res,1e-6,1e-6) +res=dsp.arm_cmplx_mag_f64(sa) +print(res) +assert_allclose(ref,res,1e-10,1e-10) + +print("arm_cmplx_mag_squared") +sa = np.random.randn(nb) +ca = realToIm1D(sa) +ref = np.abs(ca) * np.abs(ca) +print(ref) +res=dsp.arm_cmplx_mag_squared_f32(sa) +print(res) +assert_allclose(ref,res,1e-6,1e-6) +res=dsp.arm_cmplx_mag_squared_f64(sa) +print(res) +assert_allclose(ref,res,1e-10,1e-10) + +print("cmplx mult") +sa = np.random.randn(nb) +ca = realToIm1D(sa) +sb = np.random.randn(nb) +cb = realToIm1D(sb) +ref = imToReal1D(ca * cb) +print(ref) +res = dsp.arm_cmplx_mult_cmplx_f32(sa,sb) +print(res) +assert_allclose(ref,res,1e-6,1e-6) + +res = dsp.arm_cmplx_mult_cmplx_f64(sa,sb) +print(res) +assert_allclose(ref,res,1e-10,1e-10) diff --git a/PythonWrapper/examples/testdsp6.py b/PythonWrapper/examples/testdsp6.py new file mode 100755 index 00000000..51754eb2 --- /dev/null +++ b/PythonWrapper/examples/testdsp6.py @@ -0,0 +1,185 @@ +import cmsisdsp as dsp +import numpy as np +from numpy.testing import assert_allclose +from scipy.interpolate import CubicSpline +from sklearn.naive_bayes import GaussianNB +from sklearn import svm +import math + +a=[1,4,2,6,7,0,-3,5] +ref=sorted(a) +print(ref) + +SORT_BITONIC=0 +SORT_BUBBLE=1 +SORT_HEAP=2 +SORT_INSERTION=3 +SORT_QUICK=4 +SORT_SELECTION=5 + + +SORT_DESCENDING = 0 +SORT_ASCENDING = 1 + +sortinst=dsp.arm_sort_instance_f32() + +for mode in range(6): + dsp.arm_sort_init_f32(sortinst,mode,SORT_ASCENDING) + res=dsp.arm_sort_f32(sortinst,a) + print(res) + assert (res==ref).all() + +print("") +ref.reverse() +print(ref) + +for mode in range(6): + # Problem with bitonic probably in the C code + if mode > 0: + dsp.arm_sort_init_f32(sortinst,mode,SORT_DESCENDING) + res=dsp.arm_sort_f32(sortinst,a) + print(res) + assert (res==ref).all() + +print("Spline") + +x = np.arange(0, 2*np.pi+np.pi/4, np.pi/4) +y = np.sin(x) +xnew = np.arange(0, 2*np.pi+np.pi/16, np.pi/16) +ynew = CubicSpline(x,y,bc_type="natural") +yref=ynew(xnew) +print(yref) + +splineInst = dsp.arm_spline_instance_f32() +dsp.arm_spline_init_f32(splineInst,0,x,y) +yres=dsp.arm_spline_f32(splineInst,xnew) +print(yres) + +assert_allclose(yref,yres,1e-6,1e-6) + +print("Bayes") +# Reusing example from https://developer.arm.com/documentation/102052/0000/Train-your-Bayesian-estimator-with-scikit-learn + +NBVECS = 100 +VECDIM = 2 + +# 3 cluster of points are generated (3 classes) +ballRadius = 1.0 +x1 = [1.5, 1] + ballRadius * np.random.randn(NBVECS,VECDIM) +x2 = [-1.5, 1] + ballRadius * np.random.randn(NBVECS,VECDIM) +x3 = [0, -3] + ballRadius * np.random.randn(NBVECS,VECDIM) + +# All points are concatenated +X_train=np.concatenate((x1,x2,x3)) + +# The classes are 0,1 and 2. +Y_train=np.concatenate((np.zeros(NBVECS),np.ones(NBVECS),2*np.ones(NBVECS))) + +gnb = GaussianNB() +gnb.fit(X_train, Y_train) + +src1=[1.5,1.0] +src2=[-1.5,1] +src3=[0,-3] +ref1 = gnb.predict([src1]) +print(ref1) + +ref2 = gnb.predict([src2]) +print(ref2) + +ref3 = gnb.predict([src3]) +print(ref3) + +#print(gnb.predict_log_proba([src])) + +theta=list(np.reshape(gnb.theta_,np.size(gnb.theta_))) + +# Gaussian variances +sigma=list(np.reshape(gnb.var_,np.size(gnb.var_))) + +# Class priors +prior=list(np.reshape(gnb.class_prior_,np.size(gnb.class_prior_))) + +epsilon=gnb.epsilon_ + +bayesInst = dsp.arm_gaussian_naive_bayes_instance_f32( + vectorDimension=VECDIM,numberOfClasses=3, + theta=theta,sigma=sigma,classPriors=prior,epsilon=epsilon) + +_,res1=dsp.arm_gaussian_naive_bayes_predict_f32(bayesInst,src1) +print(res1) + +_,res2=dsp.arm_gaussian_naive_bayes_predict_f32(bayesInst,src2) +print(res2) + +_,res3=dsp.arm_gaussian_naive_bayes_predict_f32(bayesInst,src3) +print(res3) + +assert res1 == ref1 +assert res2 == ref2 +assert res3 == ref3 + +print("SVM") + +NBVECS = 100 +VECDIM = 2 + +ballRadius = 0.5 +x = ballRadius * np.random.randn(NBVECS, 2) + +angle = 2.0 * math.pi * np.random.randn(1, NBVECS) +radius = 3.0 + 0.1 * np.random.randn(1, NBVECS) + +xa = np.zeros((NBVECS,2)) +xa[:, 0] = radius * np.cos(angle) +xa[:, 1] = radius * np.sin(angle) + +X_train = np.concatenate((x, xa)) +Y_train = np.concatenate((np.zeros(NBVECS), np.ones(NBVECS))) + +clf = svm.SVC(kernel='poly', gamma='auto', coef0=1.1) +clf.fit(X_train, Y_train) + +test1 = np.array([0.4,0.1]) +test1 = test1.reshape(1,-1) + +refpredicted1 = clf.predict(test1) +print(refpredicted1) + +test2 = np.array([3.1,0.1]) +test2 = test2.reshape(1,-1) + +refpredicted2 = clf.predict(test2) +print(refpredicted2) + +supportShape = clf.support_vectors_.shape + +nbSupportVectors = supportShape[0] +vectorDimensions = supportShape[1] + +degree=clf.degree +coef0=clf.coef0 +gamma=clf._gamma + +intercept=clf.intercept_ + +dualCoefs = clf.dual_coef_ +dualCoefs = dualCoefs.reshape(nbSupportVectors) +supportVectors = clf.support_vectors_ +supportVectors = supportVectors.reshape(nbSupportVectors * VECDIM) + +svmInst=dsp.arm_svm_polynomial_instance_f32() +dsp.arm_svm_polynomial_init_f32(svmInst,nbSupportVectors,vectorDimensions, + intercept,dualCoefs,supportVectors, + [0,1],degree,coef0,gamma) + +test1 = np.array([0.4,0.1]) +predicted1 = dsp.arm_svm_polynomial_predict_f32(svmInst,test1) +print(predicted1) + +test2 = np.array([3.1,0.1]) +predicted2 = dsp.arm_svm_polynomial_predict_f32(svmInst,test2) +print(predicted2) + +assert predicted1==refpredicted1 +assert predicted2==refpredicted2 \ No newline at end of file diff --git a/PythonWrapper_README.md b/PythonWrapper_README.md index 1189a75d..421bcb2d 100644 --- a/PythonWrapper_README.md +++ b/PythonWrapper_README.md @@ -47,9 +47,7 @@ Synchronous Data Flow examples are available in the [SDF](https://github.com/ARM You can also install and run it from [Google colab](https://colab.research.google.com/): -This [link](https://colab.research.google.com/github/ARM-software/CMSIS_5/blob/develop/CMSIS/DSP/PythonWrapper/examples/cmsisdsp_tests.ipynb) will open a Jupyter notebook in [Google colab](https://colab.research.google.com/) for testing. - -The notebook is from the [examples](https://github.com/ARM-software/CMSIS_5/tree/develop/CMSIS/DSP/PythonWrapper/examples) in the CMSIS-DSP GitHub repository. +This [link](https://colab.research.google.com/github/ARM-software/CMSIS_5/blob/develop/CMSIS/DSP/PythonWrapper/examples/cmsisdsp_tests.ipynb) will open a Jupyter notebook in [Google colab](https://colab.research.google.com/) for testing. This notebook is from the [examples](https://github.com/ARM-software/CMSIS_5/tree/develop/CMSIS/DSP/PythonWrapper/examples) in the CMSIS-DSP GitHub repository. ### Building diff --git a/Source/MatrixFunctions/arm_mat_ldlt_f32.c b/Source/MatrixFunctions/arm_mat_ldlt_f32.c index 7e5ecbdd..1d3586c6 100755 --- a/Source/MatrixFunctions/arm_mat_ldlt_f32.c +++ b/Source/MatrixFunctions/arm_mat_ldlt_f32.c @@ -119,6 +119,7 @@ arm_status arm_mat_ldlt_f32( int fullRank = 1, diag,k; float32_t *pA; + memset(pd->pData,0,sizeof(float32_t)*n*n); memcpy(pl->pData,pSrc->pData,n*n*sizeof(float32_t)); pA = pl->pData; @@ -397,6 +398,7 @@ arm_status arm_mat_ldlt_f32( float32_t *pA; int row,d; + memset(pd->pData,0,sizeof(float32_t)*n*n); memcpy(pl->pData,pSrc->pData,n*n*sizeof(float32_t)); pA = pl->pData; diff --git a/Source/MatrixFunctions/arm_mat_ldlt_f64.c b/Source/MatrixFunctions/arm_mat_ldlt_f64.c index 36deadc9..8f7331dc 100755 --- a/Source/MatrixFunctions/arm_mat_ldlt_f64.c +++ b/Source/MatrixFunctions/arm_mat_ldlt_f64.c @@ -112,6 +112,8 @@ arm_status arm_mat_ldlt_f64( int fullRank = 1, diag,k; float64_t *pA; + memset(pd->pData,0,sizeof(float64_t)*n*n); + memcpy(pl->pData,pSrc->pData,n*n*sizeof(float64_t)); pA = pl->pData; diff --git a/Testing/testmain.cpp b/Testing/testmain.cpp index 59df851b..8e14920a 100644 --- a/Testing/testmain.cpp +++ b/Testing/testmain.cpp @@ -11,11 +11,13 @@ #include "ArrayMemory.h" using namespace std; +#ifndef MEMSIZE #ifdef BENCHMARK #define MEMSIZE 300000 #else #define MEMSIZE 230000 #endif +#endif // Dummy (will be generated by python scripts) // char* array describing the tests and the input patterns. diff --git a/cmsisdsp/__init__.py b/cmsisdsp/__init__.py index df9c71b4..7fe6262b 100755 --- a/cmsisdsp/__init__.py +++ b/cmsisdsp/__init__.py @@ -11,6 +11,10 @@ from cmsisdsp_transform import * from cmsisdsp_interpolation import * from cmsisdsp_quaternion import * from cmsisdsp_fastmath import * +from cmsisdsp_distance import * +from cmsisdsp_bayes import * +from cmsisdsp_svm import * + __version__ = cmsisdsp.version.__version__ diff --git a/cmsisdsp/version.py b/cmsisdsp/version.py index bc86c944..67bc602a 100755 --- a/cmsisdsp/version.py +++ b/cmsisdsp/version.py @@ -1 +1 @@ -__version__ = "1.2.2" +__version__ = "1.3.0" diff --git a/setup.py b/setup.py index 1103cd8e..8d7cca84 100644 --- a/setup.py +++ b/setup.py @@ -107,13 +107,27 @@ try: except: pass -#distance = glob.glob(os.path.join(ROOT,"Source","DistanceFunctions","*.c")) -#distance.remove(os.path.join(ROOT,"Source","DistanceFunctions","DistanceFunctions.c")) +distance = glob.glob(os.path.join(ROOT,"Source","DistanceFunctions","*.c")) +try: + distance.remove(os.path.join(ROOT,"Source","DistanceFunctions","DistanceFunctions.c")) +except: + pass + +bayes = glob.glob(os.path.join(ROOT,"Source","BayesFunctions","*.c")) +try: + bayes.remove(os.path.join(ROOT,"Source","BayesFunctions","BayesFunctions.c")) +except: + pass +svm = glob.glob(os.path.join(ROOT,"Source","SVMFunctions","*.c")) +try: + svm.remove(os.path.join(ROOT,"Source","SVMFunctions","SVMFunctions.c")) +except: + pass # Add dependencies transformMod = transform + common + basic + complexf + fastmath + matrix + statistics -statisticsMod = statistics + common + fastmath +statisticsMod = statistics + common + fastmath + basic interpolationMod = interpolation + common filteringMod = filtering + common + support + fastmath controllerMod = controller + common @@ -124,6 +138,9 @@ complexfMod = complexf + fastmath + common basicMod = basic quaternionMod = quaternion fastmathMod = fastmath + common +distanceMod = distance + common + basic + statistics + fastmath +bayesMod = bayes + fastmath + common + statistics + basic +svmMod = svm + fastmath + common filteringMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_filtering.c")) @@ -137,104 +154,14 @@ transformMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_ interpolationMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_interpolation.c")) quaternionMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_quaternion.c")) fastmathMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_fastmath.c")) +distanceMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_distance.c")) +bayesMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_bayes.c")) +svmMod.append(os.path.join("PythonWrapper","cmsisdsp_pkg","src","cmsisdsp_svm.c")) -missing=set(["arm_abs_f64" -,"arm_absmax_f64" -,"arm_absmax_no_idx_f32" -,"arm_absmax_no_idx_f64" -,"arm_absmin_f64" -,"arm_absmin_no_idx_f32" -,"arm_absmin_no_idx_f64" -,"arm_add_f64" -,"arm_barycenter_f32" -,"arm_braycurtis_distance_f32" -,"arm_canberra_distance_f32" -,"arm_chebyshev_distance_f32" -,"arm_chebyshev_distance_f64" -,"arm_circularRead_f32" -,"arm_cityblock_distance_f32" -,"arm_cityblock_distance_f64" -,"arm_cmplx_mag_f64" -,"arm_cmplx_mag_squared_f64" -,"arm_cmplx_mult_cmplx_f64" -,"arm_copy_f64" -,"arm_correlate_f64" -,"arm_correlation_distance_f32" -,"arm_cosine_distance_f32" -,"arm_cosine_distance_f64" -,"arm_dot_prod_f64" -,"arm_entropy_f32" -,"arm_entropy_f64" -,"arm_euclidean_distance_f32" -,"arm_euclidean_distance_f64" -,"arm_exponent_f32" -,"arm_fill_f64" -,"arm_fir_f64" -,"arm_fir_init_f64" -,"arm_gaussian_naive_bayes_predict_f32" -,"arm_jensenshannon_distance_f32" -,"arm_kullback_leibler_f32" -,"arm_kullback_leibler_f64" -,"arm_logsumexp_dot_prod_f32" -,"arm_logsumexp_f32" -,"arm_mat_cholesky_f32" -,"arm_mat_cholesky_f64" -,"arm_mat_init_f32" -,"arm_mat_ldlt_f32" -,"arm_mat_ldlt_f64" -,"arm_mat_mult_f64" -,"arm_mat_solve_lower_triangular_f32" -,"arm_mat_solve_lower_triangular_f64" -,"arm_mat_solve_upper_triangular_f32" -,"arm_mat_solve_upper_triangular_f64" -,"arm_mat_sub_f64" -,"arm_mat_trans_f64" -,"arm_max_f64" -,"arm_max_no_idx_f32" -,"arm_max_no_idx_f64" -,"arm_mean_f64" -,"arm_merge_sort_f32" -,"arm_merge_sort_init_f32" -,"arm_min_f64" -,"arm_min_no_idx_f32" -,"arm_min_no_idx_f64" -,"arm_minkowski_distance_f32" -,"arm_mult_f64" -,"arm_negate_f64" -,"arm_offset_f64" -,"arm_power_f64" -,"arm_scale_f64" -,"arm_sort_f32" -,"arm_sort_init_f32" -,"arm_spline_f32" -,"arm_spline_init_f32" -,"arm_std_f64" -,"arm_sub_f64" -,"arm_svm_linear_init_f32" -,"arm_svm_linear_predict_f32" -,"arm_svm_polynomial_init_f32" -,"arm_svm_polynomial_predict_f32" -,"arm_svm_rbf_init_f32" -,"arm_svm_rbf_predict_f32" -,"arm_svm_sigmoid_init_f32" -,"arm_svm_sigmoid_predict_f32" -,"arm_var_f64" -,"arm_vexp_f32" -,"arm_vexp_f64" -,"arm_vlog_f64" -,"arm_vsqrt_f32" -,"arm_weighted_sum_f32" -,"arm_circularRead_q15" -,"arm_circularRead_q7" -,"arm_div_q63_to_q31" -,"arm_fir_sparse_q15" -,"arm_fir_sparse_q31" -,"arm_fir_sparse_q7" -,"arm_mat_init_q15" -,"arm_mat_init_q31" +missing=set([ ]) def notf16(number): @@ -264,31 +191,42 @@ transform = list(filter(isnotmissing,list(filter(notf16, transformMod)))) interpolation = list(filter(isnotmissing,list(filter(notf16, interpolationMod)))) quaternion = list(filter(isnotmissing,list(filter(notf16, quaternionMod)))) fastmath = list(filter(isnotmissing,list(filter(notf16, fastmathMod)))) +distance = list(filter(isnotmissing,list(filter(notf16, distanceMod)))) +bayes = list(filter(isnotmissing,list(filter(notf16, bayesMod)))) +svm = list(filter(isnotmissing,list(filter(notf16, svmMod)))) #for l in filtering: # print(os.path.basename(l)) #quit() -def mkModule(name,srcs): +def mkModule(name,srcs,funcDir,newCflags=[]): + localinc = os.path.join(ROOT,"Source",funcDir) return(Extension(name, sources = (srcs ) , - include_dirs = includes + [numpy.get_include()], - extra_compile_args = cflags + include_dirs = [localinc] + includes + [numpy.get_include()], + extra_compile_args = cflags + newCflags )) -moduleFiltering = mkModule('cmsisdsp_filtering',filtering) -moduleMatrix = mkModule('cmsisdsp_matrix',matrix) -moduleSupport = mkModule('cmsisdsp_support',support) -moduleStatistics = mkModule('cmsisdsp_statistics',statistics) -moduleComplexf= mkModule('cmsisdsp_complexf',complexf) -moduleBasic = mkModule('cmsisdsp_basic',basic) -moduleController = mkModule('cmsisdsp_controller',controller) -moduleTransform = mkModule('cmsisdsp_transform',transform) -moduleInterpolation = mkModule('cmsisdsp_interpolation',interpolation) -moduleQuaternion = mkModule('cmsisdsp_quaternion',quaternion) -moduleFastmath = mkModule('cmsisdsp_fastmath',fastmath) +flagsForCommonWithoutFFT=["-DARM_DSP_CONFIG_TABLES", + "-DARM_FAST_ALLOW_TABLES", + "-DARM_ALL_FAST_TABLES"] + +moduleFiltering = mkModule('cmsisdsp_filtering',filtering,"FilteringFunctions",flagsForCommonWithoutFFT) +moduleMatrix = mkModule('cmsisdsp_matrix',matrix,"MatrixFunctions") +moduleSupport = mkModule('cmsisdsp_support',support,"SupportFunctions") +moduleStatistics = mkModule('cmsisdsp_statistics',statistics,"StatisticsFunctions",flagsForCommonWithoutFFT) +moduleComplexf= mkModule('cmsisdsp_complexf',complexf,"ComplexMathFunctions") +moduleBasic = mkModule('cmsisdsp_basic',basic,"BasicMathFunctions") +moduleController = mkModule('cmsisdsp_controller',controller,"ControllerFunctions",flagsForCommonWithoutFFT) +moduleTransform = mkModule('cmsisdsp_transform',transform,"TransformFunctions") +moduleInterpolation = mkModule('cmsisdsp_interpolation',interpolation,"InterpolationFunctions",flagsForCommonWithoutFFT) +moduleQuaternion = mkModule('cmsisdsp_quaternion',quaternion,"QuaternionMathFunctions") +moduleFastmath = mkModule('cmsisdsp_fastmath',fastmath,"FastMathFunctions",flagsForCommonWithoutFFT) +moduleDistance = mkModule('cmsisdsp_distance',distance,"DistanceFunctions",flagsForCommonWithoutFFT) +moduleBayes = mkModule('cmsisdsp_bayes',bayes,"BayesFunctions",flagsForCommonWithoutFFT) +moduleSVM = mkModule('cmsisdsp_svm',svm,"SVMFunctions",flagsForCommonWithoutFFT) @@ -319,7 +257,10 @@ def build(): moduleTransform, moduleInterpolation, moduleQuaternion, - moduleFastmath + moduleFastmath, + moduleDistance, + moduleBayes, + moduleSVM ], include_package_data=True, author = 'Copyright (C) 2010-2022 ARM Limited or its affiliates. All rights reserved.', @@ -343,8 +284,10 @@ def build(): keywords=['development','dsp','cmsis','cmsis-dsp','Arm','signal processing','maths'], install_requires=['numpy>=1.19', 'networkx>=2.5', - 'jinja2>= 3.0', - 'sympy>=1.6'], + 'jinja2>= 2.0, <3.0', + 'sympy>=1.6', + 'markupsafe<2.1' + ], project_urls={ # Optional 'Bug Reports': 'https://github.com/ARM-software/CMSIS_5/issues', 'Source': 'https://github.com/ARM-software/CMSIS_5/tree/develop/CMSIS/DSP',