From 245d64c60d0ea30f5080ff53225b5169927e24d6 Mon Sep 17 00:00:00 2001 From: Matthew Bentham Date: Mon, 2 Dec 2019 12:59:43 +0000 Subject: Work in progress of python bindings for Arm NN Not built or tested in any way Signed-off-by: Matthew Bentham Change-Id: Ie7f92b529aa5087130f0c5cc8c17db1581373236 --- .../src/pyarmnn/swig/typemaps/permutation_vector.i | 52 ++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 python/pyarmnn/src/pyarmnn/swig/typemaps/permutation_vector.i (limited to 'python/pyarmnn/src/pyarmnn/swig/typemaps/permutation_vector.i') diff --git a/python/pyarmnn/src/pyarmnn/swig/typemaps/permutation_vector.i b/python/pyarmnn/src/pyarmnn/swig/typemaps/permutation_vector.i new file mode 100644 index 0000000000..daa9663fb1 --- /dev/null +++ b/python/pyarmnn/src/pyarmnn/swig/typemaps/permutation_vector.i @@ -0,0 +1,52 @@ +// +// Copyright © 2017 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// +%define %permutation_vector_typemap(TYPE1, TYPE2) + %typemap(in) (TYPE1, TYPE2) { + if (PyTuple_Check($input)) { + PyObject* seq = $input; + + $2 = PySequence_Fast_GET_SIZE(seq); + $1 = (unsigned int*)PyMem_RawMalloc($2*sizeof(unsigned int)); + + + if(!$1) { + PyErr_NoMemory(); + SWIG_fail; + } + int size = (int)$2; + for(int i=0; i < size; i++) { + PyObject *longItem; + // Borrowed reference. No need to Py_DECREF + PyObject *item = PySequence_Fast_GET_ITEM(seq, i); + if(!item) { + PyErr_SetString(PyExc_TypeError, "Failed to read data from tuple"); + SWIG_fail; + } + // New reference. Need to Py_DECREF + longItem = PyNumber_Long(item); + if(!longItem) { + Py_XDECREF(longItem); + PyErr_SetString(PyExc_TypeError, "All elements must be numbers"); + SWIG_fail; + } + $1[i] = (unsigned int)PyLong_AsUnsignedLong(longItem); + Py_XDECREF(longItem); + } + + } else { + PyErr_SetString(PyExc_TypeError, "Argument is not a tuple"); + SWIG_fail; + } + } + + %typemap(freearg) (TYPE1, TYPE2) { + PyMem_RawFree($1); + } +%enddef + +%define %clear_permutation_vector_typemap(TYPE1, TYPE2) + %typemap(in) (TYPE1, TYPE2); + %typemap(freearg) (TYPE1, TYPE2); +%enddef -- cgit v1.2.1