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