From 5229c749553d9ec65d455e0183a574e45ac3e73e Mon Sep 17 00:00:00 2001 From: algobytewise Date: Fri, 2 Apr 2021 13:02:12 +0530 Subject: [PATCH] [mypy] Fix directory arithmetic_analysis (#4304) * fix directory arithmetic_analysis * Update build.yml * temporary fix for psf/black bug see https://github.com/psf/black/issues/2079 * Update in_static_equilibrium.py --- .github/workflows/build.yml | 2 +- .github/workflows/pre-commit.yml | 2 +- arithmetic_analysis/gaussian_elimination.py | 6 +++--- arithmetic_analysis/in_static_equilibrium.py | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 76c6357fe..e66b94b1a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -23,7 +23,7 @@ jobs: python -m pip install mypy pytest-cov -r requirements.txt # FIXME: #4052 fix mypy errors in the exclude directories and remove them below - run: mypy --ignore-missing-imports - --exclude '(arithmetic_analysis|ciphers|conversions|data_structures|digital_image_processing|dynamic_programming|graphs|hashes|linear_algebra|maths|matrix|other|project_euler|scripts|searches|strings*)/$' . + --exclude '(ciphers|conversions|data_structures|digital_image_processing|dynamic_programming|graphs|hashes|linear_algebra|maths|matrix|other|project_euler|scripts|searches|strings*)/$' . - name: Run tests run: pytest --doctest-modules --ignore=project_euler/ --ignore=scripts/ --cov-report=term-missing:skip-covered --cov=. . - if: ${{ success() }} diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 17fdad120..dd1a8a945 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -14,7 +14,7 @@ jobs: ~/.cache/pip key: ${{ runner.os }}-pre-commit-${{ hashFiles('.pre-commit-config.yaml') }} - uses: actions/setup-python@v2 - - uses: psf/black@stable + - uses: psf/black@20.8b1 - name: Install pre-commit run: | python -m pip install --upgrade pip diff --git a/arithmetic_analysis/gaussian_elimination.py b/arithmetic_analysis/gaussian_elimination.py index 51207686c..2dada4fbf 100644 --- a/arithmetic_analysis/gaussian_elimination.py +++ b/arithmetic_analysis/gaussian_elimination.py @@ -7,7 +7,7 @@ Gaussian elimination - https://en.wikipedia.org/wiki/Gaussian_elimination import numpy as np -def retroactive_resolution(coefficients: np.matrix, vector: np.array) -> np.array: +def retroactive_resolution(coefficients: np.matrix, vector: np.ndarray) -> np.ndarray: """ This function performs a retroactive linear system resolution for triangular matrix @@ -38,7 +38,7 @@ def retroactive_resolution(coefficients: np.matrix, vector: np.array) -> np.arra return x -def gaussian_elimination(coefficients: np.matrix, vector: np.array) -> np.array: +def gaussian_elimination(coefficients: np.matrix, vector: np.ndarray) -> np.ndarray: """ This function performs Gaussian elimination method @@ -57,7 +57,7 @@ def gaussian_elimination(coefficients: np.matrix, vector: np.array) -> np.array: # coefficients must to be a square matrix so we need to check first rows, columns = np.shape(coefficients) if rows != columns: - return [] + return np.array((), dtype=float) # augmented matrix augmented_mat = np.concatenate((coefficients, vector), axis=1) diff --git a/arithmetic_analysis/in_static_equilibrium.py b/arithmetic_analysis/in_static_equilibrium.py index 9b2892151..7b5006a1a 100644 --- a/arithmetic_analysis/in_static_equilibrium.py +++ b/arithmetic_analysis/in_static_equilibrium.py @@ -3,7 +3,7 @@ Checks if a system of forces is in static equilibrium. """ from typing import List -from numpy import array, cos, cross, radians, sin +from numpy import array, cos, cross, ndarray, radians, sin def polar_force( @@ -23,7 +23,7 @@ def polar_force( def in_static_equilibrium( - forces: array, location: array, eps: float = 10 ** -1 + forces: ndarray, location: ndarray, eps: float = 10 ** -1 ) -> bool: """ Check if a system is in equilibrium. @@ -42,7 +42,7 @@ def in_static_equilibrium( False """ # summation of moments is zero - moments: array = cross(location, forces) + moments: ndarray = cross(location, forces) sum_moments: float = sum(moments) return abs(sum_moments) < eps