Getter for `_shape_tuple`.
| 578 | |
| 579 | // Getter for `_shape_tuple`. |
| 580 | static PyObject* EagerTensor_shape_tuple(EagerTensor* self) { |
| 581 | auto handle = self->handle; |
| 582 | int n = TFE_TensorHandleNumDims(handle, self->status); |
| 583 | if (MaybeRaiseExceptionFromTFStatus(self->status, PyExc_ValueError)) { |
| 584 | // Cleanup self->status before returning. |
| 585 | TF_SetStatus(self->status, TF_OK, ""); |
| 586 | return nullptr; |
| 587 | } |
| 588 | PyObject* shape = PyTuple_New(n); |
| 589 | if (PyErr_Occurred()) return nullptr; |
| 590 | for (int i = 0; i < n; ++i) { |
| 591 | PyObject* dim = |
| 592 | PyLong_FromLongLong(TFE_TensorHandleDim(handle, i, self->status)); |
| 593 | if (MaybeRaiseExceptionFromTFStatus(self->status, PyExc_ValueError) || |
| 594 | dim == nullptr || PyTuple_SetItem(shape, i, dim) != 0) { |
| 595 | // Cleanup self->status before returning. |
| 596 | TF_SetStatus(self->status, TF_OK, ""); |
| 597 | Py_DECREF(shape); |
| 598 | if (dim != nullptr) Py_DECREF(dim); |
| 599 | PyErr_SetString(PyExc_RuntimeError, "Error while creating shape"); |
| 600 | return nullptr; |
| 601 | } |
| 602 | } |
| 603 | return shape; |
| 604 | } |
| 605 | |
| 606 | // Getter for `_rank`. |
| 607 | static PyObject* EagerTensor_rank(EagerTensor* self) { |
nothing calls this directly
no test coverage detected