| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392 |
- /* ----------------------------------------------------------------------
- * 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_quaternion"
- #define MODINITNAME cmsisdsp_quaternion
- #include "cmsisdsp_module.h"
- NUMPYVECTORFROMBUFFER(f32,float32_t,NPY_FLOAT);
- void typeRegistration(PyObject *module) {
-
- }
- static PyObject *
- cmsis_arm_quaternion_product_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 nbQuaternions; // input
- if (PyArg_ParseTuple(args,"OO",&pSrcA,&pSrcB))
- {
- GETARGUMENT(pSrcA,NPY_DOUBLE,double,float32_t);
- GETARGUMENT(pSrcB,NPY_DOUBLE,double,float32_t);
- nbQuaternions = arraySizepSrcA / 4 ;
- pDst=PyMem_Malloc(4*sizeof(float32_t)*nbQuaternions);
- arm_quaternion_product_f32(pSrcA_converted,pSrcB_converted,pDst,nbQuaternions);
- FLOATARRAY1(pDstOBJ,4*nbQuaternions,pDst);
- PyObject *pythonResult = Py_BuildValue("O",pDstOBJ);
- FREEARGUMENT(pSrcA_converted);
- FREEARGUMENT(pSrcB_converted);
- Py_DECREF(pDstOBJ);
- return(pythonResult);
- }
- return(NULL);
- }
- static PyObject *
- cmsis_arm_quaternion_product_single_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
- if (PyArg_ParseTuple(args,"OO",&pSrcA,&pSrcB))
- {
- GETARGUMENT(pSrcA,NPY_DOUBLE,double,float32_t);
- GETARGUMENT(pSrcB,NPY_DOUBLE,double,float32_t);
- pDst=PyMem_Malloc(4*sizeof(float32_t));
- arm_quaternion_product_single_f32(pSrcA_converted,pSrcB_converted,pDst);
- FLOATARRAY1(pDstOBJ,4,pDst);
- PyObject *pythonResult = Py_BuildValue("O",pDstOBJ);
- FREEARGUMENT(pSrcA_converted);
- FREEARGUMENT(pSrcB_converted);
- Py_DECREF(pDstOBJ);
- return(pythonResult);
- }
- return(NULL);
- }
- static PyObject *
- cmsis_arm_quaternion2rotation_f32(PyObject *obj, PyObject *args)
- {
- PyObject *pSrc=NULL; // input
- float32_t *pSrc_converted=NULL; // input
- float32_t *pDst=NULL; // output
- uint32_t nbQuaternions; // input
- if (PyArg_ParseTuple(args,"O",&pSrc))
- {
- GETARGUMENT(pSrc,NPY_DOUBLE,double,float32_t);
- nbQuaternions = arraySizepSrc / 4 ;
- pDst=PyMem_Malloc(9*sizeof(float32_t)*nbQuaternions);
- arm_quaternion2rotation_f32(pSrc_converted,pDst,nbQuaternions);
- FLOATARRAY1(pDstOBJ,9*nbQuaternions,pDst);
- PyObject *pythonResult = Py_BuildValue("O",pDstOBJ);
- FREEARGUMENT(pSrc_converted);
- Py_DECREF(pDstOBJ);
- return(pythonResult);
- }
- return(NULL);
- }
- static PyObject *
- cmsis_arm_rotation2quaternion_f32(PyObject *obj, PyObject *args)
- {
- PyObject *pSrc=NULL; // input
- float32_t *pSrc_converted=NULL; // input
- float32_t *pDst=NULL; // output
- uint32_t nbQuaternions; // input
- if (PyArg_ParseTuple(args,"O",&pSrc))
- {
- GETARGUMENT(pSrc,NPY_DOUBLE,double,float32_t);
- nbQuaternions = arraySizepSrc / 9 ;
- pDst=PyMem_Malloc(4*sizeof(float32_t)*nbQuaternions);
- arm_rotation2quaternion_f32(pSrc_converted,pDst,nbQuaternions);
- FLOATARRAY1(pDstOBJ,4*nbQuaternions,pDst);
- PyObject *pythonResult = Py_BuildValue("O",pDstOBJ);
- FREEARGUMENT(pSrc_converted);
- Py_DECREF(pDstOBJ);
- return(pythonResult);
- }
- return(NULL);
- }
- static PyObject *
- cmsis_arm_quaternion_normalize_f32(PyObject *obj, PyObject *args)
- {
- PyObject *pSrc=NULL; // input
- float32_t *pSrc_converted=NULL; // input
- float32_t *pDst=NULL; // output
- uint32_t nbQuaternions; // input
- if (PyArg_ParseTuple(args,"O",&pSrc))
- {
- GETARGUMENT(pSrc,NPY_DOUBLE,double,float32_t);
- nbQuaternions = arraySizepSrc / 4 ;
- pDst=PyMem_Malloc(4*sizeof(float32_t)*nbQuaternions);
- arm_quaternion_normalize_f32(pSrc_converted,pDst,nbQuaternions);
- FLOATARRAY1(pDstOBJ,4*nbQuaternions,pDst);
- PyObject *pythonResult = Py_BuildValue("O",pDstOBJ);
- FREEARGUMENT(pSrc_converted);
- Py_DECREF(pDstOBJ);
- return(pythonResult);
- }
- return(NULL);
- }
- static PyObject *
- cmsis_arm_quaternion_norm_f32(PyObject *obj, PyObject *args)
- {
- PyObject *pSrc=NULL; // input
- float32_t *pSrc_converted=NULL; // input
- float32_t *pDst=NULL; // output
- uint32_t nbQuaternions; // input
- if (PyArg_ParseTuple(args,"O",&pSrc))
- {
- GETARGUMENT(pSrc,NPY_DOUBLE,double,float32_t);
- nbQuaternions = arraySizepSrc / 4 ;
- pDst=PyMem_Malloc(sizeof(float32_t)*nbQuaternions);
- arm_quaternion_norm_f32(pSrc_converted,pDst,nbQuaternions);
- FLOATARRAY1(pDstOBJ,nbQuaternions,pDst);
- PyObject *pythonResult = Py_BuildValue("O",pDstOBJ);
- FREEARGUMENT(pSrc_converted);
- Py_DECREF(pDstOBJ);
- return(pythonResult);
- }
- return(NULL);
- }
- static PyObject *
- cmsis_arm_quaternion_conjugate_f32(PyObject *obj, PyObject *args)
- {
- PyObject *pSrc=NULL; // input
- float32_t *pSrc_converted=NULL; // input
- float32_t *pDst=NULL; // output
- uint32_t nbQuaternions; // input
- if (PyArg_ParseTuple(args,"O",&pSrc))
- {
- GETARGUMENT(pSrc,NPY_DOUBLE,double,float32_t);
- nbQuaternions = arraySizepSrc / 4 ;
- pDst=PyMem_Malloc(4*sizeof(float32_t)*nbQuaternions);
- arm_quaternion_conjugate_f32(pSrc_converted,pDst,nbQuaternions);
- FLOATARRAY1(pDstOBJ,4*nbQuaternions,pDst);
- PyObject *pythonResult = Py_BuildValue("O",pDstOBJ);
- FREEARGUMENT(pSrc_converted);
- Py_DECREF(pDstOBJ);
- return(pythonResult);
- }
- return(NULL);
- }
- static PyObject *
- cmsis_arm_quaternion_inverse_f32(PyObject *obj, PyObject *args)
- {
- PyObject *pSrc=NULL; // input
- float32_t *pSrc_converted=NULL; // input
- float32_t *pDst=NULL; // output
- uint32_t nbQuaternions; // input
- if (PyArg_ParseTuple(args,"O",&pSrc))
- {
- GETARGUMENT(pSrc,NPY_DOUBLE,double,float32_t);
- nbQuaternions = arraySizepSrc / 4 ;
- pDst=PyMem_Malloc(4*sizeof(float32_t)*nbQuaternions);
- arm_quaternion_inverse_f32(pSrc_converted,pDst,nbQuaternions);
- FLOATARRAY1(pDstOBJ,4*nbQuaternions,pDst);
- PyObject *pythonResult = Py_BuildValue("O",pDstOBJ);
- FREEARGUMENT(pSrc_converted);
- Py_DECREF(pDstOBJ);
- return(pythonResult);
- }
- return(NULL);
- }
- static PyMethodDef CMSISDSPMethods[] = {
- {"arm_quaternion_normalize_f32" , cmsis_arm_quaternion_normalize_f32, METH_VARARGS,""},
- {"arm_quaternion_conjugate_f32" , cmsis_arm_quaternion_conjugate_f32, METH_VARARGS,""},
- {"arm_quaternion_inverse_f32" , cmsis_arm_quaternion_inverse_f32, METH_VARARGS,""},
- {"arm_quaternion_norm_f32" , cmsis_arm_quaternion_norm_f32, METH_VARARGS,""},
- {"arm_quaternion2rotation_f32" , cmsis_arm_quaternion2rotation_f32, METH_VARARGS,""},
- {"arm_rotation2quaternion_f32" , cmsis_arm_rotation2quaternion_f32, METH_VARARGS,""},
- {"arm_quaternion_product_f32" , cmsis_arm_quaternion_product_f32, METH_VARARGS,""},
- {"arm_quaternion_product_single_f32" , cmsis_arm_quaternion_product_single_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
- }
|