1/* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
5You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9Unless required by applicable law or agreed to in writing, software
10distributed under the License is distributed on an "AS IS" BASIS,
11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12See the License for the specific language governing permissions and
13limitations 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
23bool EagerTensor_CheckExact(const PyObject* o);
24int64_t PyEagerTensor_ID(const PyObject* tensor);
25tensorflow::DataType PyEagerTensor_Dtype(const PyObject* tensor);
26int64_t PyEagerTensor_NumElements(PyObject* tensor);
27TFE_TensorHandle* EagerTensor_Handle(const PyObject* o);
28
29namespace 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.
37TFE_TensorHandle* ConvertToEagerTensor(TFE_Context* ctx, PyObject* value,
38 DataType dtype,
39 const char* device_name = nullptr);
40
41PyObject* TFE_TensorHandleToNumpy(TFE_TensorHandle* handle, TF_Status* status);
42
43} // namespace tensorflow
44
45#endif // TENSORFLOW_PYTHON_EAGER_PYWRAP_TENSOR_H_
46