• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2019 The TensorFlow Authors. 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 
16 #include "tensorflow/lite/core/api/tensor_utils.h"
17 
18 #include <string.h>
19 
20 namespace tflite {
21 
ResetVariableTensor(TfLiteTensor * tensor)22 TfLiteStatus ResetVariableTensor(TfLiteTensor* tensor) {
23   if (!tensor->is_variable) {
24     return kTfLiteOk;
25   }
26   // TODO(b/115961645): Implement - If a variable tensor has a buffer, reset it
27   // to the value of the buffer.
28   int value = 0;
29   if (tensor->type == kTfLiteInt8) {
30     value = tensor->params.zero_point;
31   }
32   // TODO(b/139446230): Provide a platform header to better handle these
33   // specific scenarios.
34 #if __ANDROID__ || defined(__x86_64__) || defined(__i386__) || \
35     defined(__i386) || defined(__x86__) || defined(__X86__) || \
36     defined(_X86_) || defined(_M_IX86) || defined(_M_X64)
37   memset(tensor->data.raw, value, tensor->bytes);
38 #else
39   char* raw_ptr = tensor->data.raw;
40   for (size_t i = 0; i < tensor->bytes; ++i) {
41     *raw_ptr = value;
42     raw_ptr++;
43   }
44 #endif
45   return kTfLiteOk;
46 }
47 
48 }  // namespace tflite
49