mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-04 16:57:32 +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:
@ -70,10 +70,11 @@ def multiply(matrix_a: list[list[int]], matrix_b: list[list[int]]) -> list[list[
|
||||
rows, cols = _verify_matrix_sizes(matrix_a, matrix_b)
|
||||
|
||||
if cols[0] != rows[1]:
|
||||
raise ValueError(
|
||||
f"Cannot multiply matrix of dimensions ({rows[0]},{cols[0]}) "
|
||||
f"and ({rows[1]},{cols[1]})"
|
||||
msg = (
|
||||
"Cannot multiply matrix of dimensions "
|
||||
f"({rows[0]},{cols[0]}) and ({rows[1]},{cols[1]})"
|
||||
)
|
||||
raise ValueError(msg)
|
||||
return [
|
||||
[sum(m * n for m, n in zip(i, j)) for j in zip(*matrix_b)] for i in matrix_a
|
||||
]
|
||||
@ -174,10 +175,11 @@ def _verify_matrix_sizes(
|
||||
) -> tuple[tuple[int, int], tuple[int, int]]:
|
||||
shape = _shape(matrix_a) + _shape(matrix_b)
|
||||
if shape[0] != shape[3] or shape[1] != shape[2]:
|
||||
raise ValueError(
|
||||
f"operands could not be broadcast together with shape "
|
||||
msg = (
|
||||
"operands could not be broadcast together with shape "
|
||||
f"({shape[0], shape[1]}), ({shape[2], shape[3]})"
|
||||
)
|
||||
raise ValueError(msg)
|
||||
return (shape[0], shape[2]), (shape[1], shape[3])
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user