From f5ad74a467051c2764529efdd720c766da2eb1c5 Mon Sep 17 00:00:00 2001 From: Martin Wicke Date: Mon, 4 May 2020 22:08:41 -0700 Subject: [PATCH] Enable __array__ access on EagerTensors (forwarding to _numpy) PiperOrigin-RevId: 309881480 Change-Id: I095a3ab0e3a991074d5f3949501302792cc9fd3b --- tensorflow/python/framework/ops.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tensorflow/python/framework/ops.py b/tensorflow/python/framework/ops.py index c139a9b11de..f43663d5396 100644 --- a/tensorflow/python/framework/ops.py +++ b/tensorflow/python/framework/ops.py @@ -1067,15 +1067,17 @@ class _EagerTensorBase(Tensor): except core._NotOkStatusException as e: six.raise_from(core._status_to_exception(e.code, e.message), None) + def __array__(self): + return self._numpy() + def _numpy_internal(self): raise NotImplementedError() def _numpy(self): - # pylint: disable=protected-access try: return self._numpy_internal() - except core._NotOkStatusException as e: - six.raise_from(core._status_to_exception(e.code, e.message), None) + except core._NotOkStatusException as e: # pylint: disable=protected-access + six.raise_from(core._status_to_exception(e.code, e.message), None) # pylint: disable=protected-access @property def dtype(self):