mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-05 01:09:40 +08:00
Add more ruff rules (#8767)
* Add more ruff rules * Add more ruff rules * pre-commit: Update ruff v0.0.269 -> v0.0.270 * Apply suggestions from code review * Fix doctest * Fix doctest (ignore whitespace) * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
@ -49,7 +49,9 @@ def jacobi_iteration_method(
|
||||
>>> constant = np.array([[2], [-6]])
|
||||
>>> init_val = [0.5, -0.5, -0.5]
|
||||
>>> iterations = 3
|
||||
>>> jacobi_iteration_method(coefficient, constant, init_val, iterations)
|
||||
>>> jacobi_iteration_method(
|
||||
... coefficient, constant, init_val, iterations
|
||||
... ) # doctest: +NORMALIZE_WHITESPACE
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValueError: Coefficient and constant matrices dimensions must be nxn and nx1 but
|
||||
@ -59,7 +61,9 @@ def jacobi_iteration_method(
|
||||
>>> constant = np.array([[2], [-6], [-4]])
|
||||
>>> init_val = [0.5, -0.5]
|
||||
>>> iterations = 3
|
||||
>>> jacobi_iteration_method(coefficient, constant, init_val, iterations)
|
||||
>>> jacobi_iteration_method(
|
||||
... coefficient, constant, init_val, iterations
|
||||
... ) # doctest: +NORMALIZE_WHITESPACE
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValueError: Number of initial values must be equal to number of rows in coefficient
|
||||
@ -79,24 +83,26 @@ def jacobi_iteration_method(
|
||||
rows2, cols2 = constant_matrix.shape
|
||||
|
||||
if rows1 != cols1:
|
||||
raise ValueError(
|
||||
f"Coefficient matrix dimensions must be nxn but received {rows1}x{cols1}"
|
||||
)
|
||||
msg = f"Coefficient matrix dimensions must be nxn but received {rows1}x{cols1}"
|
||||
raise ValueError(msg)
|
||||
|
||||
if cols2 != 1:
|
||||
raise ValueError(f"Constant matrix must be nx1 but received {rows2}x{cols2}")
|
||||
msg = f"Constant matrix must be nx1 but received {rows2}x{cols2}"
|
||||
raise ValueError(msg)
|
||||
|
||||
if rows1 != rows2:
|
||||
raise ValueError(
|
||||
f"""Coefficient and constant matrices dimensions must be nxn and nx1 but
|
||||
received {rows1}x{cols1} and {rows2}x{cols2}"""
|
||||
msg = (
|
||||
"Coefficient and constant matrices dimensions must be nxn and nx1 but "
|
||||
f"received {rows1}x{cols1} and {rows2}x{cols2}"
|
||||
)
|
||||
raise ValueError(msg)
|
||||
|
||||
if len(init_val) != rows1:
|
||||
raise ValueError(
|
||||
f"""Number of initial values must be equal to number of rows in coefficient
|
||||
matrix but received {len(init_val)} and {rows1}"""
|
||||
msg = (
|
||||
"Number of initial values must be equal to number of rows in coefficient "
|
||||
f"matrix but received {len(init_val)} and {rows1}"
|
||||
)
|
||||
raise ValueError(msg)
|
||||
|
||||
if iterations <= 0:
|
||||
raise ValueError("Iterations must be at least 1")
|
||||
|
@ -80,10 +80,11 @@ def lower_upper_decomposition(table: np.ndarray) -> tuple[np.ndarray, np.ndarray
|
||||
# Ensure that table is a square array
|
||||
rows, columns = np.shape(table)
|
||||
if rows != columns:
|
||||
raise ValueError(
|
||||
f"'table' has to be of square shaped array but got a "
|
||||
msg = (
|
||||
"'table' has to be of square shaped array but got a "
|
||||
f"{rows}x{columns} array:\n{table}"
|
||||
)
|
||||
raise ValueError(msg)
|
||||
|
||||
lower = np.zeros((rows, columns))
|
||||
upper = np.zeros((rows, columns))
|
||||
|
Reference in New Issue
Block a user