1 /* Copyright 2017 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 #ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_TENSOR_H_ 16 #define TENSORFLOW_LITE_KERNELS_INTERNAL_TENSOR_H_ 17 18 // Most functionality has been moved into a version of this file that doesn't 19 // rely on std::string, so that it can be used in TFL Micro. 20 #include "tensorflow/lite/kernels/internal/portable_tensor.h" 21 #include "tensorflow/lite/string_util.h" 22 23 namespace tflite { 24 25 template <> 26 class SequentialTensorWriter<string> { 27 public: SequentialTensorWriter(const TfLiteTensor * input,TfLiteTensor * output)28 SequentialTensorWriter(const TfLiteTensor* input, TfLiteTensor* output) 29 : input_(input), output_(output) {} ~SequentialTensorWriter()30 ~SequentialTensorWriter() { buffer_.WriteToTensor(output_, nullptr); } 31 Write(int position)32 void Write(int position) { this->WriteN(position, 1); } WriteN(int position,int len)33 void WriteN(int position, int len) { 34 for (int i = 0; i < len; i++) { 35 buffer_.AddString(GetString(input_, position + i)); 36 } 37 } 38 39 private: 40 const TfLiteTensor* input_; 41 TfLiteTensor* output_; 42 DynamicBuffer buffer_; 43 }; 44 45 } // namespace tflite 46 47 #endif // TENSORFLOW_LITE_KERNELS_INTERNAL_TENSOR_H_ 48