From 7ca263b34bed42b48f07aac4e632f1faa28462d2 Mon Sep 17 00:00:00 2001 From: Ryan Soklaski Date: Sat, 7 Sep 2024 12:35:43 -0400 Subject: [PATCH] format --- .flake8 | 3 + setup.cfg | 130 ------------------ src/mygrad/indexing_routines/funcs.py | 2 +- src/mygrad/linalg/ops.py | 2 +- src/mygrad/math/sequential/funcs.py | 14 +- src/mygrad/nnet/activations/softmax.py | 4 +- src/mygrad/nnet/losses/margin_ranking_loss.py | 2 +- src/mygrad/nnet/losses/multiclass_hinge.py | 2 +- src/mygrad/no_grad_funcs/__init__.py | 125 +++++++---------- src/mygrad/tensor_manip/array_shape/funcs.py | 2 +- src/mygrad/typing/_array_like.py | 9 +- src/mygrad/typing/_dtype_like.py | 3 +- src/mygrad/typing/_shape.py | 3 +- tests/math/binary/test_binary_funcs.py | 2 +- tests/test_tensor_manip.py | 2 +- tests/utils/numerical_gradient.py | 2 +- 16 files changed, 75 insertions(+), 232 deletions(-) create mode 100644 .flake8 delete mode 100644 setup.cfg diff --git a/.flake8 b/.flake8 new file mode 100644 index 00000000..2081204d --- /dev/null +++ b/.flake8 @@ -0,0 +1,3 @@ +[flake8] +extend-ignore = F811,D1,D205,D209,D213,D400,D401,D999,D202,E203,E501,W503,E721,F403,F405,E701 +exclude = .git,__pycache__,docs,old,build,dis,tests/annotations/*, tests/test_py310.py,docs/*, src/mygrad/__init__.py, src/mygrad/numpy_compat/__init__.py,src/mygrad/nnet/__init__.py \ No newline at end of file diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index e3ef3b8c..00000000 --- a/setup.cfg +++ /dev/null @@ -1,130 +0,0 @@ -[isort] -known_third_party = graphviz, hypothesis, numpy, numba, pytest, scipy -known_first_party = mygrad, tests -multi_line_output = 3 -include_trailing_comma = True -force_grid_wrap = 0 -combine_as_imports = True -line_length = 88 -src_paths=src/mygrad,tests - -[flake8] -extend-ignore = F811,D1,D205,D209,D213,D400,D401,D999,D202,E203,E501,W503,E721,F403,F405 -exclude = .git,__pycache__,docs,old,build,dis,tests/annotations/*, tests/test_py310.py,versioneer.py,docs/*, src/mygrad/__init__.py, src/mygrad/numpy_compat/__init__.py,src/mygrad/nnet/__init__.py - -[versioneer] -VCS = git -style = pep440 -versionfile_source = src/mygrad/_version.py -versionfile_build = mygrad/_version.py -tag_prefix = v -parentdir_prefix = mygrad- - - -[coverage:run] -omit = src/mygrad/_version.py - src/mygrad/computational_graph.py - - -[codespell] -skip = *.po,*.ts,**/_version.py,docs/source/generated/* -ignore-words-list = ND,nd,nin,dout - -[tox:tox] -envlist = py39,py310,py311,py312,format,min_numpy - -[gh-actions] -python = - 3.9: py39 - 3.10: py310 - 3.11: py311 - 3.12: py312 - -[testenv] -deps = - pytest - hypothesis - scipy - pytest-xdist -commands = pytest -n auto --hypothesis-profile ci \ - {posargs} -extras = rnn - - -[testenv:min_numpy] -deps = numpy==1.24 - {[testenv]deps} -basepython = python3.9 -commands = pytest -n auto --hypothesis-profile ci \ - {posargs} -extras = - -[testenv:py310] -deps = {[testenv]deps} -commands = pytest -n auto --hypothesis-profile ci \ - {posargs} -extras = - -[testenv:py311] -deps = {[testenv]deps} -commands = pytest -n auto --hypothesis-profile ci \ - {posargs} -extras = - -[testenv:py312] # exclude numba dependency for now -deps = pytest - pytest-xdist - hypothesis - scipy -commands = pytest -n auto --hypothesis-profile ci \ - {posargs} -extras = - - -[testenv:coverage] -setenv = NUMBA_DISABLE_JIT=1 - MYGRAD_COVERAGE_MODE=1 -usedevelop = true -basepython = python3.10 -deps = {[testenv]deps} - coverage - pytest-cov -commands = pytest -n auto --cov-report term-missing --cov-config=setup.cfg --cov-fail-under=100 --cov=mygrad tests - - -[testenv:format] -deps = - autoflake - black - isort -commands = - autoflake --recursive --in-place --remove-duplicate-keys --remove-unused-variables . - isort . - black . - - -[testenv:pre-release] # test against pre-releases of dependencies -pip_pre = true -deps = pytest - hypothesis - scipy - pytest-xdist -basepython = python3.11 -commands = pytest -n auto --hypothesis-profile ci \ - {posargs} -extras = - - -[testenv:enforce-format] -skip_install=true -basepython=python3.11 -deps=black - isort - flake8 - pytest - codespell -commands= - black src/ tests/ --diff --check - isort src/ tests/ --diff --check - flake8 src/ tests/ - codespell src/ docs/ \ No newline at end of file diff --git a/src/mygrad/indexing_routines/funcs.py b/src/mygrad/indexing_routines/funcs.py index 78d98fd6..8947c39b 100644 --- a/src/mygrad/indexing_routines/funcs.py +++ b/src/mygrad/indexing_routines/funcs.py @@ -17,7 +17,7 @@ def where( x: ArrayLike = _NoValue, y: ArrayLike = _NoValue, *, - constant: Optional[bool] = None + constant: Optional[bool] = None, ) -> Tensor: """ where(condition, [x, y]) diff --git a/src/mygrad/linalg/ops.py b/src/mygrad/linalg/ops.py index 9deac1bb..3992e6dc 100644 --- a/src/mygrad/linalg/ops.py +++ b/src/mygrad/linalg/ops.py @@ -264,7 +264,7 @@ def __call__( axis=None, keepdims: bool = False, *, - nan_to_num: bool = True + nan_to_num: bool = True, ): self.variables = (tensor,) self._nan_to_num = nan_to_num diff --git a/src/mygrad/math/sequential/funcs.py b/src/mygrad/math/sequential/funcs.py index d8c5d5c5..92270cec 100644 --- a/src/mygrad/math/sequential/funcs.py +++ b/src/mygrad/math/sequential/funcs.py @@ -36,7 +36,7 @@ def sum( axis: Axis = None, keepdims: bool = False, *, - constant: Optional[bool] = None + constant: Optional[bool] = None, ) -> Tensor: """ Sum of tensor elements over a given axis. @@ -124,7 +124,7 @@ def mean( axis: Axis = None, keepdims: bool = False, *, - constant: Optional[bool] = None + constant: Optional[bool] = None, ) -> Tensor: """ Mean of tensor elements over a given axis. @@ -202,7 +202,7 @@ def var( ddof: int = 0, keepdims: bool = False, *, - constant: Optional[bool] = None + constant: Optional[bool] = None, ) -> Tensor: """ Compute the variance along the specified axis. @@ -298,7 +298,7 @@ def std( ddof: int = 0, keepdims: bool = False, *, - constant: Optional[bool] = None + constant: Optional[bool] = None, ) -> Tensor: """ Compute the standard deviation along the specified axis. @@ -392,7 +392,7 @@ def max( axis: Axis = None, keepdims: bool = False, *, - constant: Optional[bool] = None + constant: Optional[bool] = None, ) -> Tensor: """ Return the maximum of a tensor or maximum along its axes. @@ -457,7 +457,7 @@ def min( axis: Axis = None, keepdims: bool = False, *, - constant: Optional[bool] = None + constant: Optional[bool] = None, ) -> Tensor: """ Return the minimum of a tensor or minimum along its axes. @@ -527,7 +527,7 @@ def prod( axis: Axis = None, keepdims: bool = False, *, - constant: Optional[bool] = None + constant: Optional[bool] = None, ) -> Tensor: """ Return the product of array elements over given axes. diff --git a/src/mygrad/nnet/activations/softmax.py b/src/mygrad/nnet/activations/softmax.py index d5f86c26..24ab16d3 100644 --- a/src/mygrad/nnet/activations/softmax.py +++ b/src/mygrad/nnet/activations/softmax.py @@ -41,7 +41,7 @@ def softmax( x: ArrayLike, axis: Union[None, int, Tuple[int, ...]] = -1, *, - constant: Optional[bool] = None + constant: Optional[bool] = None, ) -> Tensor: r""" Applies the softmax activation function:: @@ -115,7 +115,7 @@ def logsoftmax( x: ArrayLike, axis: Union[None, int, Tuple[int, ...]] = -1, *, - constant: Optional[bool] = None + constant: Optional[bool] = None, ) -> Tensor: r""" Applies the log-softmax activation function:: diff --git a/src/mygrad/nnet/losses/margin_ranking_loss.py b/src/mygrad/nnet/losses/margin_ranking_loss.py index 3f099253..daf7e2a4 100644 --- a/src/mygrad/nnet/losses/margin_ranking_loss.py +++ b/src/mygrad/nnet/losses/margin_ranking_loss.py @@ -55,7 +55,7 @@ def margin_ranking_loss( y: ArrayLike, margin: float, *, - constant: Optional[bool] = None + constant: Optional[bool] = None, ) -> Tensor: r"""Computes the margin average margin ranking loss. Equivalent to:: diff --git a/src/mygrad/nnet/losses/multiclass_hinge.py b/src/mygrad/nnet/losses/multiclass_hinge.py index 228e81e7..f107a3bc 100644 --- a/src/mygrad/nnet/losses/multiclass_hinge.py +++ b/src/mygrad/nnet/losses/multiclass_hinge.py @@ -64,7 +64,7 @@ def multiclass_hinge( y_true: ArrayLike, hinge: float = 1.0, *, - constant: Optional[bool] = None + constant: Optional[bool] = None, ) -> Tensor: """Computes the average multiclass hinge loss. diff --git a/src/mygrad/no_grad_funcs/__init__.py b/src/mygrad/no_grad_funcs/__init__.py index b362c241..58d9e2a4 100644 --- a/src/mygrad/no_grad_funcs/__init__.py +++ b/src/mygrad/no_grad_funcs/__init__.py @@ -123,9 +123,8 @@ def isnan( where: Mask = True, order: str = "K", dtype: DTypeLike = None, - subok: bool = True - ) -> Union[numpy.ndarray, bool]: - ... + subok: bool = True, + ) -> Union[numpy.ndarray, bool]: ... def isfinite( x: ArrayLike, @@ -135,9 +134,8 @@ def isfinite( where: Mask = True, order: str = "K", dtype: DTypeLike = None, - subok: bool = True - ) -> Union[numpy.ndarray, bool]: - ... + subok: bool = True, + ) -> Union[numpy.ndarray, bool]: ... def isinf( x: ArrayLike, @@ -147,9 +145,8 @@ def isinf( where: Mask = True, order: str = "K", dtype: DTypeLike = None, - subok: bool = True - ) -> Union[numpy.ndarray, bool]: - ... + subok: bool = True, + ) -> Union[numpy.ndarray, bool]: ... def isnat( x: ArrayLike, @@ -159,9 +156,8 @@ def isnat( where: Mask = True, order: str = "K", dtype: DTypeLike = None, - subok: bool = True - ) -> Union[numpy.ndarray, bool]: - ... + subok: bool = True, + ) -> Union[numpy.ndarray, bool]: ... def signbit( x: ArrayLike, @@ -171,9 +167,8 @@ def signbit( where: Mask = True, order: str = "K", dtype: DTypeLike = None, - subok: bool = True - ) -> Union[numpy.ndarray, bool]: - ... + subok: bool = True, + ) -> Union[numpy.ndarray, bool]: ... def logical_not( x1: ArrayLike, @@ -184,9 +179,8 @@ def logical_not( where: Mask = True, order: str = "K", dtype: DTypeLike = None, - subok: bool = True - ) -> Union[numpy.ndarray, bool]: - ... + subok: bool = True, + ) -> Union[numpy.ndarray, bool]: ... def logical_and( x1: ArrayLike, @@ -197,9 +191,8 @@ def logical_and( where: Mask = True, order: str = "K", dtype: DTypeLike = None, - subok: bool = True - ) -> Union[numpy.ndarray, bool]: - ... + subok: bool = True, + ) -> Union[numpy.ndarray, bool]: ... def logical_or( x1: ArrayLike, @@ -210,9 +203,8 @@ def logical_or( where: Mask = True, order: str = "K", dtype: DTypeLike = None, - subok: bool = True - ) -> Union[numpy.ndarray, bool]: - ... + subok: bool = True, + ) -> Union[numpy.ndarray, bool]: ... def logical_xor( x1: ArrayLike, @@ -223,9 +215,8 @@ def logical_xor( where: Mask = True, order: str = "K", dtype: DTypeLike = None, - subok: bool = True - ) -> Union[numpy.ndarray, bool]: - ... + subok: bool = True, + ) -> Union[numpy.ndarray, bool]: ... def greater( x1: ArrayLike, @@ -236,9 +227,8 @@ def greater( where: Mask = True, order: str = "K", dtype: DTypeLike = None, - subok: bool = True - ) -> Union[numpy.ndarray, bool]: - ... + subok: bool = True, + ) -> Union[numpy.ndarray, bool]: ... def greater_equal( x1: ArrayLike, @@ -249,9 +239,8 @@ def greater_equal( where: Mask = True, order: str = "K", dtype: DTypeLike = None, - subok: bool = True - ) -> Union[numpy.ndarray, bool]: - ... + subok: bool = True, + ) -> Union[numpy.ndarray, bool]: ... def less( x1: ArrayLike, @@ -262,9 +251,8 @@ def less( where: Mask = True, order: str = "K", dtype: DTypeLike = None, - subok: bool = True - ) -> Union[numpy.ndarray, bool]: - ... + subok: bool = True, + ) -> Union[numpy.ndarray, bool]: ... def less_equal( x1: ArrayLike, @@ -275,9 +263,8 @@ def less_equal( where: Mask = True, order: str = "K", dtype: DTypeLike = None, - subok: bool = True - ) -> Union[numpy.ndarray, bool]: - ... + subok: bool = True, + ) -> Union[numpy.ndarray, bool]: ... def equal( x1: ArrayLike, @@ -288,9 +275,8 @@ def equal( where: Mask = True, order: str = "K", dtype: DTypeLike = None, - subok: bool = True - ) -> Union[numpy.ndarray, bool]: - ... + subok: bool = True, + ) -> Union[numpy.ndarray, bool]: ... def not_equal( x1: ArrayLike, @@ -301,9 +287,8 @@ def not_equal( where: Mask = True, order: str = "K", dtype: DTypeLike = None, - subok: bool = True - ) -> Union[numpy.ndarray, bool]: - ... + subok: bool = True, + ) -> Union[numpy.ndarray, bool]: ... def floor_divide( x1: ArrayLike, @@ -314,9 +299,8 @@ def floor_divide( where: Mask = True, order: str = "K", dtype: DTypeLike = None, - subok: bool = True - ) -> numpy.ndarray: - ... + subok: bool = True, + ) -> numpy.ndarray: ... def remainder( x1: ArrayLike, @@ -327,9 +311,8 @@ def remainder( where: Mask = True, order: str = "K", dtype: DTypeLike = None, - subok: bool = True - ) -> numpy.ndarray: - ... + subok: bool = True, + ) -> numpy.ndarray: ... def divmod( x1: ArrayLike, @@ -340,9 +323,8 @@ def divmod( where: Mask = True, order: str = "K", dtype: DTypeLike = None, - subok: bool = True - ) -> Tuple[numpy.ndarray, numpy.ndarray]: - ... + subok: bool = True, + ) -> Tuple[numpy.ndarray, numpy.ndarray]: ... def mod( x1: ArrayLike, @@ -353,9 +335,8 @@ def mod( where: Mask = True, order: str = "K", dtype: DTypeLike = None, - subok: bool = True - ) -> Tuple[numpy.ndarray, numpy.ndarray]: - ... + subok: bool = True, + ) -> Tuple[numpy.ndarray, numpy.ndarray]: ... def fmod( x1: ArrayLike, @@ -366,9 +347,8 @@ def fmod( where: Mask = True, order: str = "K", dtype: DTypeLike = None, - subok: bool = True - ) -> Tuple[numpy.ndarray, numpy.ndarray]: - ... + subok: bool = True, + ) -> Tuple[numpy.ndarray, numpy.ndarray]: ... def rint( x: ArrayLike, @@ -378,9 +358,8 @@ def rint( where: Mask = True, order: str = "K", dtype: DTypeLike = None, - subok: bool = True - ) -> numpy.ndarray: - ... + subok: bool = True, + ) -> numpy.ndarray: ... def sign( x: ArrayLike, @@ -390,9 +369,8 @@ def sign( where: Mask = True, order: str = "K", dtype: DTypeLike = None, - subok: bool = True - ) -> numpy.ndarray: - ... + subok: bool = True, + ) -> numpy.ndarray: ... def floor( x: ArrayLike, @@ -402,9 +380,8 @@ def floor( where: Mask = True, order: str = "K", dtype: DTypeLike = None, - subok: bool = True - ) -> numpy.ndarray: - ... + subok: bool = True, + ) -> numpy.ndarray: ... def ceil( x: ArrayLike, @@ -414,9 +391,8 @@ def ceil( where: Mask = True, order: str = "K", dtype: DTypeLike = None, - subok: bool = True - ) -> numpy.ndarray: - ... + subok: bool = True, + ) -> numpy.ndarray: ... def trunc( x: ArrayLike, @@ -426,6 +402,5 @@ def trunc( where: Mask = True, order: str = "K", dtype: DTypeLike = None, - subok: bool = True - ) -> numpy.ndarray: - ... + subok: bool = True, + ) -> numpy.ndarray: ... diff --git a/src/mygrad/tensor_manip/array_shape/funcs.py b/src/mygrad/tensor_manip/array_shape/funcs.py index 3b6027a2..7dde6bf6 100644 --- a/src/mygrad/tensor_manip/array_shape/funcs.py +++ b/src/mygrad/tensor_manip/array_shape/funcs.py @@ -72,7 +72,7 @@ def squeeze( a: ArrayLike, axis: Optional[Union[int, Tuple[int, ...]]] = None, *, - constant: Optional[bool] = None + constant: Optional[bool] = None, ) -> Tensor: """ Remove single-dimensional entries from the shape of a tensor. diff --git a/src/mygrad/typing/_array_like.py b/src/mygrad/typing/_array_like.py index dc656293..1de45df5 100644 --- a/src/mygrad/typing/_array_like.py +++ b/src/mygrad/typing/_array_like.py @@ -32,8 +32,7 @@ if not TYPE_CHECKING and not HAS_PROTOCOL: # pragma: no cover class ImplementsArray: - def __array__(self, dtype: None = ...) -> np.ndarray: - ... + def __array__(self, dtype: None = ...) -> np.ndarray: ... else: # pragma: no cover @@ -41,8 +40,7 @@ def __array__(self, dtype: None = ...) -> np.ndarray: class ImplementsArray(Protocol): def __array__( self, dtype: None = ..., copy: Optional[bool] = ... - ) -> np.ndarray: - ... + ) -> np.ndarray: ... Real = Union[int, float] @@ -63,8 +61,7 @@ def __array__( ArrayLike = Union[Real, "Tensor", np.ndarray, ImplementsArray, SequenceNDReals] else: # pragma: no cover - class ArrayLike: - ... + class ArrayLike: ... sb1 = Sequence[bool] diff --git a/src/mygrad/typing/_dtype_like.py b/src/mygrad/typing/_dtype_like.py index 412fafeb..31298a4b 100644 --- a/src/mygrad/typing/_dtype_like.py +++ b/src/mygrad/typing/_dtype_like.py @@ -15,5 +15,4 @@ else: # pragma: no cover - class DTypeLikeReals: - ... + class DTypeLikeReals: ... diff --git a/src/mygrad/typing/_shape.py b/src/mygrad/typing/_shape.py index eb33278e..ecd82f3f 100644 --- a/src/mygrad/typing/_shape.py +++ b/src/mygrad/typing/_shape.py @@ -6,5 +6,4 @@ Shape: TypeAlias = Tuple[int, ...] else: - class Shape: - ... + class Shape: ... diff --git a/tests/math/binary/test_binary_funcs.py b/tests/math/binary/test_binary_funcs.py index 345637a4..7416e38a 100644 --- a/tests/math/binary/test_binary_funcs.py +++ b/tests/math/binary/test_binary_funcs.py @@ -65,7 +65,7 @@ def test_inplace_arithmetic_fwd(op_name: str, kwargs: Dict[str, Any]): true_func=iop, num_arrays=2, permit_0d_array_as_float=False, - **kwargs + **kwargs, ) def iop_fwd(): pass diff --git a/tests/test_tensor_manip.py b/tests/test_tensor_manip.py index 58286af6..c1e08035 100644 --- a/tests/test_tensor_manip.py +++ b/tests/test_tensor_manip.py @@ -392,7 +392,7 @@ def gen_roll_args(draw, arr): dict(min_size=len(shift), max_size=len(shift)) if isinstance(shift, tuple) else {} - ) + ), ) axis = draw(st.none() | st.integers(-arr.ndim, arr.ndim - 1) | ax_strat) else: diff --git a/tests/utils/numerical_gradient.py b/tests/utils/numerical_gradient.py index 20080143..f7a356c7 100644 --- a/tests/utils/numerical_gradient.py +++ b/tests/utils/numerical_gradient.py @@ -13,7 +13,7 @@ def finite_difference( vary_ind=None, h=Decimal(1) / Decimal(int(1e8)), as_decimal=False, - kwargs=None + kwargs=None, ): """Computes numerical partial derivatives of f(x0, x1, ...) in each of its variables, using the central difference method.