1 | /* Copyright 2020 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 | // Note: This library is only used by python_api_parameter_converter_test. It |
16 | // is not meant to be used in other circumstances. |
17 | |
18 | #include "pybind11/pybind11.h" |
19 | #include "pybind11/pytypes.h" |
20 | #include "pybind11/stl.h" |
21 | #include "tensorflow/python/framework/python_api_parameter_converter.h" |
22 | |
23 | namespace py = pybind11; |
24 | |
25 | namespace tensorflow { |
26 | namespace { |
27 | |
28 | PythonAPIInfo::InferredAttributes Convert( |
29 | const PythonAPIInfo& api_info, |
30 | const PythonTensorConverter& tensor_converter, py::handle arg_list) { |
31 | PythonAPIInfo::InferredAttributes inferred_attrs; |
32 | |
33 | PyObject* args_fast = PySequence_Fast(arg_list.ptr(), "Expected a list" ); |
34 | absl::Span<PyObject*> args_raw(PySequence_Fast_ITEMS(args_fast), |
35 | PySequence_Fast_GET_SIZE(args_fast)); |
36 | |
37 | if (!CopyPythonAPITensorLists(api_info, args_raw)) { |
38 | throw py::error_already_set(); |
39 | } |
40 | if (!ConvertPythonAPIParameters(api_info, tensor_converter, args_raw, |
41 | &inferred_attrs)) { |
42 | throw py::error_already_set(); |
43 | } |
44 | |
45 | return inferred_attrs; |
46 | } |
47 | |
48 | } // namespace |
49 | } // namespace tensorflow |
50 | |
51 | PYBIND11_MODULE(_pywrap_python_api_parameter_converter, m) { |
52 | m.def("Convert" , tensorflow::Convert); |
53 | } |
54 | |