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 <memory> 17 18 #include "tensorflow/lite/testing/string_util.h" 19 20 #include "absl/strings/escaping.h" 21 #include "tensorflow/lite/python/interpreter_wrapper/numpy.h" 22 #include "tensorflow/lite/python/interpreter_wrapper/python_utils.h" 23 #include "tensorflow/lite/string_util.h" 24 25 namespace tflite { 26 namespace testing { 27 namespace python { 28 SerializeAsHexString(PyObject * value)29PyObject* SerializeAsHexString(PyObject* value) { 30 DynamicBuffer dynamic_buffer; 31 if (!python_utils::FillStringBufferWithPyArray(value, &dynamic_buffer)) { 32 return nullptr; 33 } 34 35 char* char_buffer = nullptr; 36 size_t size = dynamic_buffer.WriteToBuffer(&char_buffer); 37 string s = absl::BytesToHexString({char_buffer, size}); 38 free(char_buffer); 39 40 return python_utils::ConvertToPyString(s.data(), s.size()); 41 } 42 43 } // namespace python 44 } // namespace testing 45 } // namespace tflite 46