From 74cff3d9b0967072ae3e6d3fb663ff69c5e41df8 Mon Sep 17 00:00:00 2001 From: Yannick Augenstein Date: Thu, 10 Oct 2024 18:22:47 +0200 Subject: [PATCH 1/3] Add `__array_namespace__` to `ArrayBox` --- autograd/numpy/numpy_boxes.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/autograd/numpy/numpy_boxes.py b/autograd/numpy/numpy_boxes.py index 937037a4..e6c68c2a 100644 --- a/autograd/numpy/numpy_boxes.py +++ b/autograd/numpy/numpy_boxes.py @@ -23,6 +23,9 @@ def __getitem__(A, idx): dtype = property(lambda self: self._value.dtype) T = property(lambda self: anp.transpose(self)) + def __array_namespace__(self, *, api_version: str | None = None): + return anp + def __len__(self): return len(self._value) From e0f869955a2c5e0d0891cb36677595bfe59218b4 Mon Sep 17 00:00:00 2001 From: Fabian Joswig Date: Sun, 13 Oct 2024 22:55:37 +0200 Subject: [PATCH 2/3] Fix typehints for python<3.10 --- autograd/numpy/numpy_boxes.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/autograd/numpy/numpy_boxes.py b/autograd/numpy/numpy_boxes.py index e6c68c2a..0e9a6867 100644 --- a/autograd/numpy/numpy_boxes.py +++ b/autograd/numpy/numpy_boxes.py @@ -1,5 +1,6 @@ import numpy as np +from typing import Union from autograd.builtins import SequenceBox from autograd.extend import Box, primitive @@ -23,7 +24,7 @@ def __getitem__(A, idx): dtype = property(lambda self: self._value.dtype) T = property(lambda self: anp.transpose(self)) - def __array_namespace__(self, *, api_version: str | None = None): + def __array_namespace__(self, *, api_version: Union[str, None] = None): return anp def __len__(self): From fd9eceb34ba53eab53ccb3da12d23cd9598b9d1e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 13 Oct 2024 20:56:06 +0000 Subject: [PATCH 3/3] style: pre-commit fixes --- autograd/numpy/numpy_boxes.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/autograd/numpy/numpy_boxes.py b/autograd/numpy/numpy_boxes.py index 0e9a6867..b9c73963 100644 --- a/autograd/numpy/numpy_boxes.py +++ b/autograd/numpy/numpy_boxes.py @@ -1,6 +1,7 @@ +from typing import Union + import numpy as np -from typing import Union from autograd.builtins import SequenceBox from autograd.extend import Box, primitive