MCPcopy Create free account
hub / github.com/MTG/essentia / buildReturnValue

Function buildReturnValue

src/python/parsing.cpp:124–141  ·  view source on GitHub ↗

This function builds the python object that is to be returned given a vector of outputs. It automatically chooses the correct output type (None, simple value, tuple of values) wrt the number of outputs. /

Source from the content-addressed store, hash-verified

122// * (None, simple value, tuple of values) wrt the number of outputs.
123// */
124PyObject* buildReturnValue(const vector<PyObject*>& result_vec) {
125 int size = result_vec.size();
126
127 // if there is no result to be returned, return None to the python interpreter
128 if (size == 0) Py_RETURN_NONE;
129
130 // if there is only one value, return it directly instead of a 1-sized tuple
131 if (size == 1) return result_vec[0];
132
133 // otherwise, create a tuple and fill it with the results
134 PyObject* result = PyTuple_New(result_vec.size());
135
136 for (int i=0; i<size; i++) {
137 PyTuple_SET_ITEM(result, i, result_vec[i]);
138 }
139
140 return result;
141}
142
143PyObject* toPython(void* obj, Edt tp) {
144 switch (tp) {

Callers 1

computeMethod · 0.85

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected