1 // Copyright 2018 Google Inc. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at:
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #import "tensorflow/lite/experimental/objc/apis/TFLInterpreter.h"
16 
17 @class TFLTensor;
18 
19 NS_ASSUME_NONNULL_BEGIN
20 
21 @interface TFLInterpreter (Internal)
22 
23 /**
24  * Copies the given data into the input tensor at the given index. This is allowed only before the
25  * interpreter is invoked.
26  *
27  * @param data The data to set. The byte size of the data must match what's required by the input
28  *     tensor at the given index.
29  * @param index An input tensor index.
30  * @param error An optional error parameter populated when there is an error in setting the data.
31  *
32  * @return Whether the data was copied into the input tensor at the given index successfully.
33  *     Returns NO if an error occurred.
34  */
35 - (BOOL)copyData:(NSData *)data toInputTensorAtIndex:(NSUInteger)index error:(NSError **)error;
36 
37 /**
38  * Retrieves a copy of the data from the given tensor. For an output tensor, the interpreter
39  * invocation has to complete before the data can be retrieved.
40  *
41  * @param tensor A tensor.
42  * @param error An optional error parameter populated when there is an error in getting the data.
43  *
44  * @return The data of the given tensor. `nil` if there is an error or data is not available.
45  */
46 - (nullable NSData *)dataFromTensor:(TFLTensor *)tensor error:(NSError **)error;
47 
48 /**
49  * Retrieves the shape of the given tensor, an array of positive unsigned integer(s) containing the
50  * size of each dimension. For example: shape of [[[1, 1, 1], [2, 2, 2]], [[3, 3, 3], [4, 4, 4]]] is
51  * [2, 2, 3].
52  *
53  * @param tensor An input or output tensor.
54  * @param error An optional error parameter populated when there is an error in retrieving the
55  *     shape.
56  *
57  * @return The shape of the tensor. `nil` if there is an error in retrieving the shape.
58  */
59 - (nullable NSArray<NSNumber *> *)shapeOfTensor:(TFLTensor *)tensor error:(NSError **)error;
60 
61 @end
62 
63 NS_ASSUME_NONNULL_END
64