Skip to content

Commit

Permalink
Merge pull request #437 from rsokl/fix-ci
Browse files Browse the repository at this point in the history
fix registered hypothesis strategies and ban numpy 1.25.0
  • Loading branch information
rsokl authored Jul 3, 2023
2 parents 75d7a54 + 370f4c6 commit 133072b
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 19 deletions.
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"Topic :: Scientific/Engineering",
]

INSTALL_REQUIRES = ["numpy >= 1.20"]
# tests/tensor_ops/test_getitem.py::test_getitem_advindex_bool_bkwdprop segfaults
INSTALL_REQUIRES = ["numpy >= 1.20, !=1.25.0", "typing-extensions >= 4.1.0, !=4.6.0"]
TESTS_REQUIRE = ["pytest >= 3.8", "hypothesis >= 6.17.1", "scipy"]

DESCRIPTION = "Brings drop-in automatic differentiation to NumPy"
Expand Down
2 changes: 1 addition & 1 deletion src/mygrad/tensor_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2346,7 +2346,7 @@ def __gt__(self, other: ArrayLike) -> np.ndarray:
def __ge__(self, other: ArrayLike) -> np.ndarray:
return np.ndarray.__ge__(self.data, asarray(other))

def __imatmul__(self, other):
def __imatmul__(self, other): # pragma: no cover
raise TypeError(
"In-place matrix multiplication is not (yet) supported. "
"Use 'a = a @ b' instead of 'a @= b'"
Expand Down
8 changes: 5 additions & 3 deletions src/mygrad/typing/_array_like.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import TYPE_CHECKING, List, Sequence, Tuple, TypeVar, Union

import numpy as np
from typing_extensions import runtime_checkable

if TYPE_CHECKING: # pragma: no cover
from mygrad import Tensor
Expand Down Expand Up @@ -36,6 +37,7 @@ def __array__(self, dtype: None = ...) -> np.ndarray:

else: # pragma: no cover

@runtime_checkable
class ImplementsArray(Protocol):
def __array__(self, dtype: None = ...) -> np.ndarray:
...
Expand All @@ -58,9 +60,9 @@ def __array__(self, dtype: None = ...) -> np.ndarray:
if TYPE_CHECKING: # pragma: no cover
ArrayLike = Union[Real, "Tensor", np.ndarray, ImplementsArray, SequenceNDReals]
else: # pragma: no cover
ArrayLike = TypeVar(
"ArrayLike", Real, "Tensor", np.ndarray, ImplementsArray, SequenceNDReals
)

class ArrayLike:
...


sb1 = Sequence[bool]
Expand Down
9 changes: 4 additions & 5 deletions src/mygrad/typing/_dtype_like.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
)

if TYPE_CHECKING: # pragma: no cover
DTypeLikeReals = Union[dtype, None, Type[bool], Type[int], Type[float], str]
DTypeLikeReals = Union[dtype, None, Type[bool], Type[int], Type[float]]

else: # pragma: no cover
DTypeLikeReals = TypeVar(
"DTypeLikeReals",
bound=Union[dtype, None, Type[bool], Type[int], Type[float], str],
)

class DTypeLikeReals:
...
12 changes: 8 additions & 4 deletions src/mygrad/typing/_shape.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from typing import TYPE_CHECKING, Tuple, TypeVar
from typing import TYPE_CHECKING, Tuple

from typing_extensions import TypeAlias

if TYPE_CHECKING: # pragma: no cover
Shape = Tuple[int, ...]
else: # pragma: no cover
Shape = TypeVar("Shape", bound=Tuple[int, ...])
Shape: TypeAlias = Tuple[int, ...]
else:

class Shape:
...
6 changes: 6 additions & 0 deletions tests/custom_strategies/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -885,3 +885,9 @@ def populates_ufunc(
)
args["out"] = np.full(out_shape, fill_value=fill_value, dtype=float)
return args


st.register_type_strategy(
Shape, st.lists(st.integers(0, 10), min_size=0, max_size=5).map(tuple)
)
ArrayLike
8 changes: 3 additions & 5 deletions tests/tensor_base/test_augmented_updates.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import numpy as np
import pytest
from numpy.testing import assert_allclose

import mygrad as mg
Expand Down Expand Up @@ -114,10 +113,9 @@ def test_augmented_power():

def test_augmented_matmul():
a = np.arange(9.0).reshape(3, 3)
t = mg.arange(9.0).reshape(3, 3)

try:
a[a < 4] @= np.arange(4.0)
except Exception as e:
with pytest.raises(type(e), match="Use 'a = a @ b' instead of 'a @= b'"):
t[t < 4] @= mg.arange(4.0)
except Exception:
# TODO: add support -- numpy supports this now
...

0 comments on commit 133072b

Please sign in to comment.