From b96ca61cf07255d3f80449fbd3f51887a918d2dc Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner <inform@tiker.net> Date: Wed, 11 Nov 2020 16:05:32 -0600 Subject: [PATCH] Array.__repr__: Make CL arrays visually distinguishable from numpy arrays --- pyopencl/array.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pyopencl/array.py b/pyopencl/array.py index f3b84c63..531f2321 100644 --- a/pyopencl/array.py +++ b/pyopencl/array.py @@ -801,7 +801,14 @@ class Array: return str(self.get()) def __repr__(self): - return repr(self.get()) + result = repr(self.get()) + if result[:5] == "array": + result = "cl.Array" + result[5:] + else: + from warnings import warn + warn("numpy.ndarray.__repr__ was expected to return a string starting " + f"with 'array'. It didn't: '{result[:10]:r}'") + return result def safely_stringify_for_pudb(self): return f"cl.Array {self.dtype} {self.shape}" -- GitLab