| 962 | } |
| 963 | |
| 964 | class PyTapeTensor { |
| 965 | public: |
| 966 | PyTapeTensor(tensorflow::int64 id, tensorflow::DataType dtype, |
| 967 | const tensorflow::TensorShape& shape) |
| 968 | : id_(id), dtype_(dtype), shape_(shape) {} |
| 969 | PyTapeTensor(tensorflow::int64 id, tensorflow::DataType dtype, |
| 970 | PyObject* shape) |
| 971 | : id_(id), dtype_(dtype), shape_(shape) { |
| 972 | Py_INCREF(absl::get<1>(shape_)); |
| 973 | } |
| 974 | PyTapeTensor(const PyTapeTensor& other) { |
| 975 | id_ = other.id_; |
| 976 | dtype_ = other.dtype_; |
| 977 | shape_ = other.shape_; |
| 978 | if (shape_.index() == 1) { |
| 979 | Py_INCREF(absl::get<1>(shape_)); |
| 980 | } |
| 981 | } |
| 982 | |
| 983 | ~PyTapeTensor() { |
| 984 | if (shape_.index() == 1) { |
| 985 | Py_DECREF(absl::get<1>(shape_)); |
| 986 | } |
| 987 | } |
| 988 | PyObject* GetShape() const; |
| 989 | PyObject* GetPyDType() const { return PyLong_FromLong(dtype_); } |
| 990 | tensorflow::int64 GetID() const { return id_; } |
| 991 | tensorflow::DataType GetDType() const { return dtype_; } |
| 992 | |
| 993 | private: |
| 994 | tensorflow::int64 id_; |
| 995 | tensorflow::DataType dtype_; |
| 996 | absl::variant<tensorflow::TensorShape, PyObject*> shape_; |
| 997 | }; |
| 998 | |
| 999 | static PyTapeTensor TapeTensorFromTensor(PyObject* tensor); |
| 1000 |
no outgoing calls
no test coverage detected