Skip to content

Commit 45c084e

Browse files
committed
Merge branch 'master' into fix-some-ARG002-per-file-ignores
2 parents 0570aff + c03f16d commit 45c084e

File tree

7 files changed

+64
-8
lines changed

7 files changed

+64
-8
lines changed

.pre-commit-config.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ repos:
1111
- id: requirements-txt-fixer
1212

1313
- repo: https://github.com/MarcoGorelli/auto-walrus
14-
rev: 0.3.3
14+
rev: 0.3.4
1515
hooks:
1616
- id: auto-walrus
1717

1818
- repo: https://github.com/astral-sh/ruff-pre-commit
19-
rev: v0.4.1
19+
rev: v0.4.2
2020
hooks:
2121
- id: ruff
2222
- id: ruff-format
@@ -47,7 +47,7 @@ repos:
4747
- id: validate-pyproject
4848

4949
- repo: https://github.com/pre-commit/mirrors-mypy
50-
rev: v1.9.0
50+
rev: v1.10.0
5151
hooks:
5252
- id: mypy
5353
args:

DIRECTORY.md

+1
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,7 @@
773773
* [Inverse Of Matrix](matrix/inverse_of_matrix.py)
774774
* [Largest Square Area In Matrix](matrix/largest_square_area_in_matrix.py)
775775
* [Matrix Class](matrix/matrix_class.py)
776+
* [Matrix Equalization](matrix/matrix_equalization.py)
776777
* [Matrix Multiplication Recursion](matrix/matrix_multiplication_recursion.py)
777778
* [Matrix Operation](matrix/matrix_operation.py)
778779
* [Max Area Of Island](matrix/max_area_of_island.py)

data_structures/arrays/sudoku_solver.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def time_solve(grid):
150150
display(grid_values(grid))
151151
if values:
152152
display(values)
153-
print("(%.5f seconds)\n" % t)
153+
print(f"({t:.5f} seconds)\n")
154154
return (t, solved(values))
155155

156156
times, results = zip(*[time_solve(grid) for grid in grids])
@@ -217,4 +217,4 @@ def shuffled(seq):
217217
start = time.monotonic()
218218
solve(puzzle)
219219
t = time.monotonic() - start
220-
print("Solved: %.5f sec" % t)
220+
print(f"Solved: {t:.5f} sec")

machine_learning/linear_discriminant_analysis.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ def valid_input(
256256
input_type: Callable[[object], num], # Usually float or int
257257
input_msg: str,
258258
err_msg: str,
259-
condition: Callable[[num], bool] = lambda x: True,
259+
condition: Callable[[num], bool] = lambda _: True,
260260
default: str | None = None,
261261
) -> num:
262262
"""

matrix/matrix_equalization.py

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
from sys import maxsize
2+
3+
4+
def array_equalization(vector: list[int], step_size: int) -> int:
5+
"""
6+
This algorithm equalizes all elements of the input vector
7+
to a common value, by making the minimal number of
8+
"updates" under the constraint of a step size (step_size).
9+
10+
>>> array_equalization([1, 1, 6, 2, 4, 6, 5, 1, 7, 2, 2, 1, 7, 2, 2], 4)
11+
4
12+
>>> array_equalization([22, 81, 88, 71, 22, 81, 632, 81, 81, 22, 92], 2)
13+
5
14+
>>> array_equalization([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 5)
15+
0
16+
>>> array_equalization([22, 22, 22, 33, 33, 33], 2)
17+
2
18+
>>> array_equalization([1, 2, 3], 0)
19+
Traceback (most recent call last):
20+
ValueError: Step size must be positive and non-zero.
21+
>>> array_equalization([1, 2, 3], -1)
22+
Traceback (most recent call last):
23+
ValueError: Step size must be positive and non-zero.
24+
>>> array_equalization([1, 2, 3], 0.5)
25+
Traceback (most recent call last):
26+
ValueError: Step size must be an integer.
27+
>>> array_equalization([1, 2, 3], maxsize)
28+
1
29+
"""
30+
if step_size <= 0:
31+
raise ValueError("Step size must be positive and non-zero.")
32+
if not isinstance(step_size, int):
33+
raise ValueError("Step size must be an integer.")
34+
35+
unique_elements = set(vector)
36+
min_updates = maxsize
37+
38+
for element in unique_elements:
39+
elem_index = 0
40+
updates = 0
41+
while elem_index < len(vector):
42+
if vector[elem_index] != element:
43+
updates += 1
44+
elem_index += step_size
45+
else:
46+
elem_index += 1
47+
min_updates = min(min_updates, updates)
48+
49+
return min_updates
50+
51+
52+
if __name__ == "__main__":
53+
from doctest import testmod
54+
55+
testmod()

neural_network/input_data.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ def __init__(
156156
self._rng = np.random.default_rng(seed1 if seed is None else seed2)
157157
dtype = dtypes.as_dtype(dtype).base_dtype
158158
if dtype not in (dtypes.uint8, dtypes.float32):
159-
raise TypeError("Invalid image dtype %r, expected uint8 or float32" % dtype)
159+
msg = f"Invalid image dtype {dtype!r}, expected uint8 or float32"
160+
raise TypeError(msg)
160161
if fake_data:
161162
self._num_examples = 10000
162163
self.one_hot = one_hot

pyproject.toml

-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ max-complexity = 17 # default: 10
8383
"graphs/minimum_spanning_tree_prims.py" = ["SIM114"]
8484
"hashes/enigma_machine.py" = ["BLE001"]
8585
"machine_learning/decision_tree.py" = ["SIM114"]
86-
"machine_learning/linear_discriminant_analysis.py" = ["ARG005"]
8786
"machine_learning/sequential_minimum_optimization.py" = ["SIM115"]
8887
"matrix/sherman_morrison.py" = ["SIM103", "SIM114"]
8988
"other/l*u_cache.py" = ["RUF012"]

0 commit comments

Comments
 (0)