summaryrefslogtreecommitdiff
path: root/numpy/_array_api/_array_object.py
diff options
context:
space:
mode:
authorAaron Meurer <asmeurer@gmail.com>2021-02-23 18:21:35 -0700
committerAaron Meurer <asmeurer@gmail.com>2021-02-23 18:21:35 -0700
commit853a18de30219a0d25709caac0410de6dfeb4e95 (patch)
treebf596592e9313f3c34501c88bf0a8f48ebbf36de /numpy/_array_api/_array_object.py
parentc791956135e3a1e63ca1e51ec5a1a79e65015ce8 (diff)
downloadnumpy-853a18de30219a0d25709caac0410de6dfeb4e95.tar.gz
Implement a simple passthrough __str__ and __repr__ on the array_api ndarray class
These methods aren't required by the spec, but without them, the array object is harder to use interactively.
Diffstat (limited to 'numpy/_array_api/_array_object.py')
-rw-r--r--numpy/_array_api/_array_object.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/numpy/_array_api/_array_object.py b/numpy/_array_api/_array_object.py
index 5ce650ae9..09f5e5710 100644
--- a/numpy/_array_api/_array_object.py
+++ b/numpy/_array_api/_array_object.py
@@ -40,6 +40,23 @@ class ndarray:
def __new__(cls, *args, **kwargs):
raise TypeError("The array_api ndarray object should not be instantiated directly. Use an array creation function, such as asarray(), instead.")
+ # These functions are not required by the spec, but are implemented for
+ # the sake of usability.
+
+ def __str__(x: array, /) -> str:
+ """
+ Performs the operation __str__.
+ """
+ return x._array.__str__()
+
+ def __repr__(x: array, /) -> str:
+ """
+ Performs the operation __repr__.
+ """
+ return x._array.__repr__()
+
+ # Everything below this is required by the spec.
+
def __abs__(x: array, /) -> array:
"""
Performs the operation __abs__.