1 /* Copyright 2015 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 #ifndef TENSORFLOW_PYTHON_LIB_CORE_PY_FUNC_H_ 17 #define TENSORFLOW_PYTHON_LIB_CORE_PY_FUNC_H_ 18 19 // Must be included first 20 #include "tensorflow/python/lib/core/numpy.h" 21 22 #include "tensorflow/core/framework/tensor.h" 23 #include "tensorflow/core/lib/core/status.h" 24 25 namespace tensorflow { 26 27 // Called by python code on initialization. 28 // 29 // "trampoline" must represent a python function which has the 30 // following signature: 31 // (string, list(ndarray)) | (string, list(EagerTensor)) -> 32 // ndarray | list(ndarray) | python scalar | 33 // EagerTensor | list(EagerTensor) | None 34 // 35 // The trampoline takes two arguments, the first is a string token 36 // used by the python frontend's dispatching logic; the second is a 37 // list of numpy ndarrays or EagerTensor objects. It can return a 38 // single numpy ndarray, a list of numpy ndarrays, a python scalar, an 39 // EagerTensor, a list of EagerTensors, or None. 40 // 41 // PyFunc requires inputs and outputs to be ndarrays. EagerPyFunc requires 42 // inputs to be a list of EagerTensors and outputs to be an EagerTensor, a list 43 // of EagerTensors, or None. 44 // 45 // The C++ runtime converts outputs back to Tensor objects. 46 // 47 // This function is called by script_ops.py during its module initialization. 48 // 49 // TODO(zhifengc): Support distributed runtime. 50 void InitializePyTrampoline(PyObject* trampoline); 51 52 // Creates a numpy array in 'ret' and copies the content of tensor 't' 53 // into 'ret'. 54 Status ConvertTensorToNdarray(const Tensor& t, PyObject** ret); 55 56 // Given an numpy ndarray object 'obj', creates a corresponding tf 57 // Tensor in '*ret'. 58 Status ConvertNdarrayToTensor(PyObject* obj, Tensor* ret); 59 60 } // end namespace tensorflow 61 62 #endif // TENSORFLOW_PYTHON_LIB_CORE_PY_FUNC_H_ 63