• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_PYTHON_EAGER_PYWRAP_TENSOR_H_
16 #define TENSORFLOW_PYTHON_EAGER_PYWRAP_TENSOR_H_
17 
18 #include "tensorflow/c/eager/c_api.h"
19 #include "tensorflow/core/framework/types.pb.h"
20 #include "tensorflow/core/platform/types.h"
21 #include "tensorflow/python/lib/core/numpy.h"
22 
23 bool EagerTensor_CheckExact(const PyObject* o);
24 tensorflow::int64 PyEagerTensor_ID(const PyObject* tensor);
25 tensorflow::DataType PyEagerTensor_Dtype(const PyObject* tensor);
26 tensorflow::int64 PyEagerTensor_NumElements(PyObject* tensor);
27 TFE_TensorHandle* EagerTensor_Handle(const PyObject* o);
28 
29 namespace tensorflow {
30 
31 // Converts a value to a TFE_TensorHandle of a given dtype. The handle is
32 // first allocated on CPU and then copied to a device identified by
33 // device_name, unless it is nullptr.
34 //
35 // Note that an DT_INT32 handle is always kept on CPU regardless of the
36 // device_name argument.
37 TFE_TensorHandle* ConvertToEagerTensor(TFE_Context* ctx, PyObject* value,
38                                        DataType dtype,
39                                        const char* device_name = nullptr);
40 
41 PyObject* TFE_TensorHandleToNumpy(TFE_TensorHandle* handle, TF_Status* status);
42 
43 }  // namespace tensorflow
44 
45 #endif  // TENSORFLOW_PYTHON_EAGER_PYWRAP_TENSOR_H_
46