mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-23 21:11:08 +00:00
[pre-commit.ci] pre-commit autoupdate (#11275)
* [pre-commit.ci] pre-commit autoupdate updates: - [github.com/astral-sh/ruff-pre-commit: v0.1.14 → v0.2.0](https://github.com/astral-sh/ruff-pre-commit/compare/v0.1.14...v0.2.0) * Upgrade pyproject.toml * Revert sudoku_solver.py RUF017 Avoid quadratic list summation --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Christian Clauss <cclauss@me.com>
This commit is contained in:
parent
4128f19170
commit
ed8d9209da
|
@ -16,7 +16,7 @@ repos:
|
||||||
- id: auto-walrus
|
- id: auto-walrus
|
||||||
|
|
||||||
- repo: https://github.com/astral-sh/ruff-pre-commit
|
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||||
rev: v0.1.14
|
rev: v0.2.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: ruff
|
- id: ruff
|
||||||
- id: ruff-format
|
- id: ruff-format
|
||||||
|
|
|
@ -67,7 +67,7 @@ def mixed_keyword(
|
||||||
if verbose:
|
if verbose:
|
||||||
print(mapping)
|
print(mapping)
|
||||||
# create the encrypted text by mapping the plaintext to the modified alphabet
|
# create the encrypted text by mapping the plaintext to the modified alphabet
|
||||||
return "".join(mapping[char] if char in mapping else char for char in plaintext)
|
return "".join(mapping.get(char, char) for char in plaintext)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
@ -22,7 +22,7 @@ unitlist = (
|
||||||
+ [cross(rs, cs) for rs in ("ABC", "DEF", "GHI") for cs in ("123", "456", "789")]
|
+ [cross(rs, cs) for rs in ("ABC", "DEF", "GHI") for cs in ("123", "456", "789")]
|
||||||
)
|
)
|
||||||
units = {s: [u for u in unitlist if s in u] for s in squares}
|
units = {s: [u for u in unitlist if s in u] for s in squares}
|
||||||
peers = {s: set(sum(units[s], [])) - {s} for s in squares}
|
peers = {s: set(sum(units[s], [])) - {s} for s in squares} # noqa: RUF017
|
||||||
|
|
||||||
|
|
||||||
def test():
|
def test():
|
||||||
|
|
|
@ -171,11 +171,9 @@ def is_palindrome_dict(head: ListNode | None) -> bool:
|
||||||
if len(v) % 2 != 0:
|
if len(v) % 2 != 0:
|
||||||
middle += 1
|
middle += 1
|
||||||
else:
|
else:
|
||||||
step = 0
|
for step, i in enumerate(range(len(v))):
|
||||||
for i in range(len(v)):
|
|
||||||
if v[i] + v[len(v) - 1 - step] != checksum:
|
if v[i] + v[len(v) - 1 - step] != checksum:
|
||||||
return False
|
return False
|
||||||
step += 1
|
|
||||||
if middle > 1:
|
if middle > 1:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -22,11 +22,9 @@ def gaussian_filter(image, k_size, sigma):
|
||||||
|
|
||||||
# im2col, turn the k_size*k_size pixels into a row and np.vstack all rows
|
# im2col, turn the k_size*k_size pixels into a row and np.vstack all rows
|
||||||
image_array = zeros((dst_height * dst_width, k_size * k_size))
|
image_array = zeros((dst_height * dst_width, k_size * k_size))
|
||||||
row = 0
|
for row, (i, j) in enumerate(product(range(dst_height), range(dst_width))):
|
||||||
for i, j in product(range(dst_height), range(dst_width)):
|
|
||||||
window = ravel(image[i : i + k_size, j : j + k_size])
|
window = ravel(image[i : i + k_size, j : j + k_size])
|
||||||
image_array[row, :] = window
|
image_array[row, :] = window
|
||||||
row += 1
|
|
||||||
|
|
||||||
# turn the kernel into shape(k*k, 1)
|
# turn the kernel into shape(k*k, 1)
|
||||||
gaussian_kernel = gen_gaussian_kernel(k_size, sigma)
|
gaussian_kernel = gen_gaussian_kernel(k_size, sigma)
|
||||||
|
|
|
@ -20,13 +20,11 @@ def resistor_parallel(resistors: list[float]) -> float:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
first_sum = 0.00
|
first_sum = 0.00
|
||||||
index = 0
|
for index, resistor in enumerate(resistors):
|
||||||
for resistor in resistors:
|
|
||||||
if resistor <= 0:
|
if resistor <= 0:
|
||||||
msg = f"Resistor at index {index} has a negative or zero value!"
|
msg = f"Resistor at index {index} has a negative or zero value!"
|
||||||
raise ValueError(msg)
|
raise ValueError(msg)
|
||||||
first_sum += 1 / float(resistor)
|
first_sum += 1 / float(resistor)
|
||||||
index += 1
|
|
||||||
return 1 / first_sum
|
return 1 / first_sum
|
||||||
|
|
||||||
|
|
||||||
|
@ -44,13 +42,11 @@ def resistor_series(resistors: list[float]) -> float:
|
||||||
ValueError: Resistor at index 2 has a negative value!
|
ValueError: Resistor at index 2 has a negative value!
|
||||||
"""
|
"""
|
||||||
sum_r = 0.00
|
sum_r = 0.00
|
||||||
index = 0
|
for index, resistor in enumerate(resistors):
|
||||||
for resistor in resistors:
|
|
||||||
sum_r += resistor
|
sum_r += resistor
|
||||||
if resistor < 0:
|
if resistor < 0:
|
||||||
msg = f"Resistor at index {index} has a negative value!"
|
msg = f"Resistor at index {index} has a negative value!"
|
||||||
raise ValueError(msg)
|
raise ValueError(msg)
|
||||||
index += 1
|
|
||||||
return sum_r
|
return sum_r
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -123,8 +123,7 @@ def emitter_converter(size_par, data):
|
||||||
# Bit counter one for a given parity
|
# Bit counter one for a given parity
|
||||||
cont_bo = 0
|
cont_bo = 0
|
||||||
# counter to control the loop reading
|
# counter to control the loop reading
|
||||||
cont_loop = 0
|
for cont_loop, x in enumerate(data_ord):
|
||||||
for x in data_ord:
|
|
||||||
if x is not None:
|
if x is not None:
|
||||||
try:
|
try:
|
||||||
aux = (bin_pos[cont_loop])[-1 * (bp)]
|
aux = (bin_pos[cont_loop])[-1 * (bp)]
|
||||||
|
@ -132,7 +131,6 @@ def emitter_converter(size_par, data):
|
||||||
aux = "0"
|
aux = "0"
|
||||||
if aux == "1" and x == "1":
|
if aux == "1" and x == "1":
|
||||||
cont_bo += 1
|
cont_bo += 1
|
||||||
cont_loop += 1
|
|
||||||
parity.append(cont_bo % 2)
|
parity.append(cont_bo % 2)
|
||||||
|
|
||||||
qtd_bp += 1
|
qtd_bp += 1
|
||||||
|
@ -164,10 +162,10 @@ def receptor_converter(size_par, data):
|
||||||
parity_received = []
|
parity_received = []
|
||||||
data_output = []
|
data_output = []
|
||||||
|
|
||||||
for x in range(1, len(data) + 1):
|
for i, item in enumerate(data, 1):
|
||||||
# Performs a template of bit positions - who should be given,
|
# Performs a template of bit positions - who should be given,
|
||||||
# and who should be parity
|
# and who should be parity
|
||||||
if qtd_bp < size_par and (np.log(x) / np.log(2)).is_integer():
|
if qtd_bp < size_par and (np.log(i) / np.log(2)).is_integer():
|
||||||
data_out_gab.append("P")
|
data_out_gab.append("P")
|
||||||
qtd_bp = qtd_bp + 1
|
qtd_bp = qtd_bp + 1
|
||||||
else:
|
else:
|
||||||
|
@ -175,10 +173,9 @@ def receptor_converter(size_par, data):
|
||||||
|
|
||||||
# Sorts the data to the new output size
|
# Sorts the data to the new output size
|
||||||
if data_out_gab[-1] == "D":
|
if data_out_gab[-1] == "D":
|
||||||
data_output.append(data[cont_data])
|
data_output.append(item)
|
||||||
else:
|
else:
|
||||||
parity_received.append(data[cont_data])
|
parity_received.append(item)
|
||||||
cont_data += 1
|
|
||||||
|
|
||||||
# -----------calculates the parity with the data
|
# -----------calculates the parity with the data
|
||||||
data_out = []
|
data_out = []
|
||||||
|
@ -215,9 +212,7 @@ def receptor_converter(size_par, data):
|
||||||
for bp in range(1, size_par + 1):
|
for bp in range(1, size_par + 1):
|
||||||
# Bit counter one for a certain parity
|
# Bit counter one for a certain parity
|
||||||
cont_bo = 0
|
cont_bo = 0
|
||||||
# Counter to control loop reading
|
for cont_loop, x in enumerate(data_ord):
|
||||||
cont_loop = 0
|
|
||||||
for x in data_ord:
|
|
||||||
if x is not None:
|
if x is not None:
|
||||||
try:
|
try:
|
||||||
aux = (bin_pos[cont_loop])[-1 * (bp)]
|
aux = (bin_pos[cont_loop])[-1 * (bp)]
|
||||||
|
@ -225,7 +220,6 @@ def receptor_converter(size_par, data):
|
||||||
aux = "0"
|
aux = "0"
|
||||||
if aux == "1" and x == "1":
|
if aux == "1" and x == "1":
|
||||||
cont_bo += 1
|
cont_bo += 1
|
||||||
cont_loop += 1
|
|
||||||
parity.append(str(cont_bo % 2))
|
parity.append(str(cont_bo % 2))
|
||||||
|
|
||||||
qtd_bp += 1
|
qtd_bp += 1
|
||||||
|
|
|
@ -237,7 +237,7 @@ def report_generator(
|
||||||
[
|
[
|
||||||
("sum", "sum"),
|
("sum", "sum"),
|
||||||
("mean_with_zeros", lambda x: np.mean(np.nan_to_num(x))),
|
("mean_with_zeros", lambda x: np.mean(np.nan_to_num(x))),
|
||||||
("mean_without_zeros", lambda x: x.replace(0, np.NaN).mean()),
|
("mean_without_zeros", lambda x: x.replace(0, np.nan).mean()),
|
||||||
(
|
(
|
||||||
"mean_25-75",
|
"mean_25-75",
|
||||||
lambda x: np.mean(
|
lambda x: np.mean(
|
||||||
|
|
|
@ -589,7 +589,7 @@ def plot_partition_boundary(
|
||||||
ax.contour(
|
ax.contour(
|
||||||
xrange,
|
xrange,
|
||||||
yrange,
|
yrange,
|
||||||
np.mat(grid).T,
|
np.asmatrix(grid).T,
|
||||||
levels=(-1, 0, 1),
|
levels=(-1, 0, 1),
|
||||||
linestyles=("--", "-", "--"),
|
linestyles=("--", "-", "--"),
|
||||||
linewidths=(1, 1, 1),
|
linewidths=(1, 1, 1),
|
||||||
|
|
|
@ -41,11 +41,11 @@ class CNN:
|
||||||
self.rate_weight = rate_w
|
self.rate_weight = rate_w
|
||||||
self.rate_thre = rate_t
|
self.rate_thre = rate_t
|
||||||
self.w_conv1 = [
|
self.w_conv1 = [
|
||||||
np.mat(-1 * np.random.rand(self.conv1[0], self.conv1[0]) + 0.5)
|
np.asmatrix(-1 * np.random.rand(self.conv1[0], self.conv1[0]) + 0.5)
|
||||||
for i in range(self.conv1[1])
|
for i in range(self.conv1[1])
|
||||||
]
|
]
|
||||||
self.wkj = np.mat(-1 * np.random.rand(self.num_bp3, self.num_bp2) + 0.5)
|
self.wkj = np.asmatrix(-1 * np.random.rand(self.num_bp3, self.num_bp2) + 0.5)
|
||||||
self.vji = np.mat(-1 * np.random.rand(self.num_bp2, self.num_bp1) + 0.5)
|
self.vji = np.asmatrix(-1 * np.random.rand(self.num_bp2, self.num_bp1) + 0.5)
|
||||||
self.thre_conv1 = -2 * np.random.rand(self.conv1[1]) + 1
|
self.thre_conv1 = -2 * np.random.rand(self.conv1[1]) + 1
|
||||||
self.thre_bp2 = -2 * np.random.rand(self.num_bp2) + 1
|
self.thre_bp2 = -2 * np.random.rand(self.num_bp2) + 1
|
||||||
self.thre_bp3 = -2 * np.random.rand(self.num_bp3) + 1
|
self.thre_bp3 = -2 * np.random.rand(self.num_bp3) + 1
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
[tool.ruff]
|
[tool.ruff]
|
||||||
ignore = [ # `ruff rule S101` for a description of that rule
|
lint.ignore = [ # `ruff rule S101` for a description of that rule
|
||||||
"ARG001", # Unused function argument `amount` -- FIX ME?
|
"ARG001", # Unused function argument `amount` -- FIX ME?
|
||||||
"B904", # Within an `except` clause, raise exceptions with `raise ... from err` -- FIX ME
|
"B904", # Within an `except` clause, raise exceptions with `raise ... from err` -- FIX ME
|
||||||
"B905", # `zip()` without an explicit `strict=` parameter -- FIX ME
|
"B905", # `zip()` without an explicit `strict=` parameter -- FIX ME
|
||||||
|
@ -31,7 +31,7 @@ ignore = [ # `ruff rule S101` for a description of that rule
|
||||||
"SLF001", # Private member accessed: `_Iterator` -- FIX ME
|
"SLF001", # Private member accessed: `_Iterator` -- FIX ME
|
||||||
"UP038", # Use `X | Y` in `{}` call instead of `(X, Y)` -- DO NOT FIX
|
"UP038", # Use `X | Y` in `{}` call instead of `(X, Y)` -- DO NOT FIX
|
||||||
]
|
]
|
||||||
select = [ # https://beta.ruff.rs/docs/rules
|
lint.select = [ # https://beta.ruff.rs/docs/rules
|
||||||
"A", # flake8-builtins
|
"A", # flake8-builtins
|
||||||
"ARG", # flake8-unused-arguments
|
"ARG", # flake8-unused-arguments
|
||||||
"ASYNC", # flake8-async
|
"ASYNC", # flake8-async
|
||||||
|
@ -84,13 +84,13 @@ select = [ # https://beta.ruff.rs/docs/rules
|
||||||
# "TCH", # flake8-type-checking
|
# "TCH", # flake8-type-checking
|
||||||
# "TRY", # tryceratops
|
# "TRY", # tryceratops
|
||||||
]
|
]
|
||||||
show-source = true
|
output-format = "full"
|
||||||
target-version = "py311"
|
target-version = "py312"
|
||||||
|
|
||||||
[tool.ruff.mccabe] # DO NOT INCREASE THIS VALUE
|
[tool.ruff.lint.mccabe] # DO NOT INCREASE THIS VALUE
|
||||||
max-complexity = 17 # default: 10
|
max-complexity = 17 # default: 10
|
||||||
|
|
||||||
[tool.ruff.per-file-ignores]
|
[tool.ruff.lint.per-file-ignores]
|
||||||
"arithmetic_analysis/newton_raphson.py" = ["PGH001"]
|
"arithmetic_analysis/newton_raphson.py" = ["PGH001"]
|
||||||
"audio_filters/show_response.py" = ["ARG002"]
|
"audio_filters/show_response.py" = ["ARG002"]
|
||||||
"data_structures/binary_tree/binary_search_tree_recursive.py" = ["BLE001"]
|
"data_structures/binary_tree/binary_search_tree_recursive.py" = ["BLE001"]
|
||||||
|
@ -110,7 +110,7 @@ max-complexity = 17 # default: 10
|
||||||
"project_euler/problem_099/sol1.py" = ["SIM115"]
|
"project_euler/problem_099/sol1.py" = ["SIM115"]
|
||||||
"sorts/external_sort.py" = ["SIM115"]
|
"sorts/external_sort.py" = ["SIM115"]
|
||||||
|
|
||||||
[tool.ruff.pylint] # DO NOT INCREASE THESE VALUES
|
[tool.ruff.lint.pylint] # DO NOT INCREASE THESE VALUES
|
||||||
allow-magic-value-types = ["float", "int", "str"]
|
allow-magic-value-types = ["float", "int", "str"]
|
||||||
max-args = 10 # default: 5
|
max-args = 10 # default: 5
|
||||||
max-branches = 20 # default: 12
|
max-branches = 20 # default: 12
|
||||||
|
|
Loading…
Reference in New Issue
Block a user