Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cirq-core/cirq/linalg/predicates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions cirq-core/cirq/linalg/tolerance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/hidden_linear_function.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down