@@ -21,6 +21,7 @@ limitations under the License.
21
21
#include < memory>
22
22
#include < sstream>
23
23
#include < string>
24
+ #include < utility>
24
25
25
26
#include " absl/memory/memory.h"
26
27
#include " absl/strings/str_format.h"
@@ -58,15 +59,19 @@ using python_utils::PyDecrefDeleter;
58
59
59
60
PyObject* PyArrayFromFloatVector (const float * data, npy_intp size) {
60
61
void * pydata = malloc (size * sizeof (float ));
61
- memcpy (pydata, data, size * sizeof (float ));
62
+ if (data != nullptr ) {
63
+ memcpy (pydata, data, size * sizeof (float ));
64
+ }
62
65
PyObject* obj = PyArray_SimpleNewFromData (1 , &size, NPY_FLOAT32, pydata);
63
66
PyArray_ENABLEFLAGS (reinterpret_cast <PyArrayObject*>(obj), NPY_ARRAY_OWNDATA);
64
67
return obj;
65
68
}
66
69
67
70
PyObject* PyArrayFromIntVector (const int * data, npy_intp size) {
68
71
void * pydata = malloc (size * sizeof (int ));
69
- memcpy (pydata, data, size * sizeof (int ));
72
+ if (data != nullptr ) {
73
+ memcpy (pydata, data, size * sizeof (int ));
74
+ }
70
75
PyObject* obj = PyArray_SimpleNewFromData (1 , &size, NPY_INT32, pydata);
71
76
PyArray_ENABLEFLAGS (reinterpret_cast <PyArrayObject*>(obj), NPY_ARRAY_OWNDATA);
72
77
return obj;
@@ -270,9 +275,9 @@ PyObject* InterpreterWrapper2::ResizeInputTensor(int i, PyObject* value,
270
275
/*
271
276
* This returns an int, and never returns an error
272
277
*/
273
- int InterpreterWrapper2::NumTensors () const {
278
+ int InterpreterWrapper2::NumTensors (int subgraph_index ) const {
274
279
if (local_exec)
275
- return lwrap->NumTensors ();
280
+ return lwrap->NumTensors (subgraph_index );
276
281
try {
277
282
roundtrip (tflite_num_tensors, proxy.id );
278
283
return resp.count ();
@@ -284,9 +289,9 @@ int InterpreterWrapper2::NumTensors() const {
284
289
/*
285
290
* This returns a string, and never returns an error
286
291
*/
287
- std::string InterpreterWrapper2::TensorName (int i) const {
292
+ std::string InterpreterWrapper2::TensorName (int i, int subgraph_index ) const {
288
293
if (local_exec)
289
- return lwrap->TensorName (i);
294
+ return lwrap->TensorName (i, subgraph_index );
290
295
try {
291
296
roundtrip (tflite_tensor_name, proxy.id , i);
292
297
return resp.name ();
@@ -298,9 +303,9 @@ std::string InterpreterWrapper2::TensorName(int i) const {
298
303
/*
299
304
* Get TfLiteType from remote and convert to Numpy Type class
300
305
*/
301
- PyObject* InterpreterWrapper2::TensorType (int i) const {
306
+ PyObject* InterpreterWrapper2::TensorType (int i, int subgraph_index ) const {
302
307
if (local_exec)
303
- return lwrap->TensorType (i);
308
+ return lwrap->TensorType (i, subgraph_index );
304
309
try {
305
310
roundtrip (tflite_tensor_type, proxy.id , i);
306
311
if (resp.status ())
@@ -319,9 +324,9 @@ PyObject* InterpreterWrapper2::TensorType(int i) const {
319
324
return nullptr ;
320
325
}
321
326
322
- PyObject* InterpreterWrapper2::TensorSize (int i) const {
327
+ PyObject* InterpreterWrapper2::TensorSize (int i, int subgraph_index ) const {
323
328
if (local_exec)
324
- return lwrap->TensorSize (i);
329
+ return lwrap->TensorSize (i, subgraph_index );
325
330
try {
326
331
roundtrip (tflite_tensor_size, proxy.id , i);
327
332
if (resp.status ())
@@ -337,9 +342,9 @@ PyObject* InterpreterWrapper2::TensorSize(int i) const {
337
342
return nullptr ;
338
343
}
339
344
340
- PyObject* InterpreterWrapper2::TensorSizeSignature (int i) const {
345
+ PyObject* InterpreterWrapper2::TensorSizeSignature (int i, int subgraph_index ) const {
341
346
if (local_exec)
342
- return lwrap->TensorSizeSignature (i);
347
+ return lwrap->TensorSizeSignature (i, subgraph_index );
343
348
try {
344
349
roundtrip (tflite_tensor_size_signature, proxy.id , i);
345
350
if (resp.status ())
@@ -359,9 +364,9 @@ PyObject* InterpreterWrapper2::TensorSizeSignature(int i) const {
359
364
* Use <PyDictFromSparsityParam> from interpreter_wrapper.cc
360
365
* and therefore convert out response to a TfLiteSparsity struct
361
366
*/
362
- PyObject* InterpreterWrapper2::TensorSparsityParameters (int i) const {
367
+ PyObject* InterpreterWrapper2::TensorSparsityParameters (int i, int subgraph_index ) const {
363
368
if (local_exec)
364
- return lwrap->TensorSparsityParameters (i);
369
+ return lwrap->TensorSparsityParameters (i, subgraph_index );
365
370
try {
366
371
roundtrip (tflite_tensor_sparsity_parameters, proxy.id , i);
367
372
if (resp.status ())
@@ -412,9 +417,9 @@ PyObject* InterpreterWrapper2::TensorSparsityParameters(int i) const {
412
417
return nullptr ;
413
418
}
414
419
415
- PyObject* InterpreterWrapper2::TensorQuantization (int i) const {
420
+ PyObject* InterpreterWrapper2::TensorQuantization (int i, int subgraph_index ) const {
416
421
if (local_exec)
417
- return lwrap->TensorQuantization (i);
422
+ return lwrap->TensorQuantization (i, subgraph_index );
418
423
try {
419
424
roundtrip (tflite_tensor_quantization, proxy.id , i);
420
425
if (resp.status ())
@@ -430,9 +435,9 @@ PyObject* InterpreterWrapper2::TensorQuantization(int i) const {
430
435
return nullptr ;
431
436
}
432
437
433
- PyObject* InterpreterWrapper2::TensorQuantizationParameters (int i) const {
438
+ PyObject* InterpreterWrapper2::TensorQuantizationParameters (int i, int subgraph_index ) const {
434
439
if (local_exec)
435
- return lwrap->TensorQuantizationParameters (i);
440
+ return lwrap->TensorQuantizationParameters (i, subgraph_index );
436
441
try {
437
442
roundtrip (tflite_tensor_quantization_parameters, proxy.id , i);
438
443
if (resp.status ())
0 commit comments