aboutsummaryrefslogtreecommitdiff
path: root/python/pyarmnn/src/pyarmnn/swig/typemaps/model_options.i
blob: c4acaefb1b1c0621859c70bd3c67db92e5c4d2d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//
// Copyright © 2021 Arm Ltd. All rights reserved.
// SPDX-License-Identifier: MIT
//
%inline %{

   static PyObject* from_model_options_to_python(std::vector<armnn::BackendOptions>* input) {
        Py_ssize_t size = input->size();
        PyObject* localList = PyList_New(size);

        if (!localList) {
            Py_XDECREF(localList);
            return PyErr_NoMemory();
        }

        for(Py_ssize_t i = 0; i < size; ++i) {

            PyObject* obj = SWIG_NewPointerObj(SWIG_as_voidptr(&input->at(i)), SWIGTYPE_p_armnn__BackendOptions, 0 |  0 );

            PyList_SET_ITEM(localList, i, obj);
        }
        return localList;
    }
%}

%define %model_options_typemap

// this typemap works for struct argument get

    %typemap(out) std::vector<armnn::BackendOptions>* {
        $result = from_model_options_to_python($1);
    }

// this typemap works for struct argument set
    %typemap(in) std::vector<armnn::BackendOptions>* {
        if (PySequence_Check($input)) {

            int res = swig::asptr($input, &$1);
            if (!SWIG_IsOK(res) || !$1) {
                SWIG_exception_fail(SWIG_ArgError(($1 ? res : SWIG_TypeError)),
                    "in method '" "OptimizerOptions_m_ModelOptions_set" "', argument " "2"" of type '" "std::vector< armnn::BackendOptions,std::allocator< armnn::BackendOptions > > *""'");
            }

        } else {
            PyErr_SetString(PyExc_TypeError, "Argument value object does not provide sequence protocol.");
            SWIG_fail;
        }
    }

%enddef

%define %model_options_clear
    %typemap(out) std::vector<armnn::BackendOptions>*;
    %typemap(in) std::vector<armnn::BackendOptions>*;
%enddef