From 50f347832ac548e8486c25bba6a544b7c774a427 Mon Sep 17 00:00:00 2001 From: Dave Bacon Date: Mon, 16 May 2022 17:09:39 +0000 Subject: [PATCH 1/2] Avoid np._bool --- cirq-core/cirq/linalg/predicates.py | 2 +- cirq-core/cirq/linalg/tolerance.py | 8 ++++---- docs/tutorials/hidden_linear_function.ipynb | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cirq-core/cirq/linalg/predicates.py b/cirq-core/cirq/linalg/predicates.py index 68caae4d485..d287e25aef6 100644 --- a/cirq-core/cirq/linalg/predicates.py +++ b/cirq-core/cirq/linalg/predicates.py @@ -20,7 +20,7 @@ from cirq import value -def is_diagonal(matrix: np.ndarray, *, atol: float = 1e-8) -> np.bool_: +def is_diagonal(matrix: np.ndarray, *, atol: float = 1e-8) -> bool: """Determines if a matrix is a approximately diagonal. A matrix is diagonal if i!=j implies m[i,j]==0. diff --git a/cirq-core/cirq/linalg/tolerance.py b/cirq-core/cirq/linalg/tolerance.py index 11b46bf852a..dcb4406fc08 100644 --- a/cirq-core/cirq/linalg/tolerance.py +++ b/cirq-core/cirq/linalg/tolerance.py @@ -22,19 +22,19 @@ from numpy.typing import ArrayLike -def all_near_zero(a: 'ArrayLike', *, atol: float = 1e-8) -> np.bool_: +def all_near_zero(a: 'ArrayLike', *, atol: float = 1e-8) -> bool: """Checks if the tensor's elements are all near zero. Args: a: Tensor of elements that could all be near zero. atol: Absolute tolerance. """ - return np.all(np.less_equal(np.abs(a), atol)) + return bool(np.all(np.less_equal(np.abs(a), atol))) def all_near_zero_mod( a: Union[float, complex, Iterable[float], np.ndarray], period: float, *, atol: float = 1e-8 -) -> np.bool_: +) -> bool: """Checks if the tensor's elements are all near multiples of the period. Args: @@ -43,7 +43,7 @@ def all_near_zero_mod( atol: Absolute tolerance. """ b = (np.asarray(a) + period / 2) % period - period / 2 - return np.all(np.less_equal(np.abs(b), atol)) + return bool(np.all(np.less_equal(np.abs(b), atol))) def near_zero(a: float, *, atol: float = 1e-8) -> bool: diff --git a/docs/tutorials/hidden_linear_function.ipynb b/docs/tutorials/hidden_linear_function.ipynb index 6fdbc7df229..28a4f8d791e 100644 --- a/docs/tutorials/hidden_linear_function.ipynb +++ b/docs/tutorials/hidden_linear_function.ipynb @@ -417,7 +417,7 @@ " ans = []\n", " while np.max(A) != 0:\n", " edges_group = []\n", - " used = np.zeros(n, dtype=np.bool)\n", + " used = np.zeros(n, dtype=bool)\n", " for i in range(n):\n", " for j in range(n):\n", " if A[i][j] == 1 and not used[i] and not used[j]:\n", @@ -667,4 +667,4 @@ }, "nbformat": 4, "nbformat_minor": 0 -} +} \ No newline at end of file From 47dcf436acd5ab47f27cf780d6b29b4b0e1f6795 Mon Sep 17 00:00:00 2001 From: Dave Bacon Date: Mon, 16 May 2022 17:29:05 +0000 Subject: [PATCH 2/2] format --- docs/tutorials/hidden_linear_function.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/tutorials/hidden_linear_function.ipynb b/docs/tutorials/hidden_linear_function.ipynb index 28a4f8d791e..1199138ec9e 100644 --- a/docs/tutorials/hidden_linear_function.ipynb +++ b/docs/tutorials/hidden_linear_function.ipynb @@ -667,4 +667,4 @@ }, "nbformat": 4, "nbformat_minor": 0 -} \ No newline at end of file +}