Skip to content

Commit 07560ea

Browse files
Merge branch 'master' into remove-some-per-file-ignores
2 parents 7ca6b10 + ea53051 commit 07560ea

File tree

87 files changed

+270
-189
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+270
-189
lines changed

Diff for: .pre-commit-config.yaml

+4-4
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.3.7
19+
rev: v0.4.2
2020
hooks:
2121
- id: ruff
2222
- id: ruff-format
@@ -29,7 +29,7 @@ repos:
2929
- tomli
3030

3131
- repo: https://github.com/tox-dev/pyproject-fmt
32-
rev: "1.7.0"
32+
rev: "1.8.0"
3333
hooks:
3434
- id: pyproject-fmt
3535

@@ -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:

Diff for: 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)

Diff for: audio_filters/show_response.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
from abc import abstractmethod
34
from math import pi
45
from typing import Protocol
56

@@ -8,14 +9,14 @@
89

910

1011
class FilterType(Protocol):
12+
@abstractmethod
1113
def process(self, sample: float) -> float:
1214
"""
1315
Calculate y[n]
1416
1517
>>> issubclass(FilterType, Protocol)
1618
True
1719
"""
18-
return 0.0
1920

2021

2122
def get_bounds(

Diff for: backtracking/sudoku.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
2-
Given a partially filled 9×9 2D array, the objective is to fill a 9×9
2+
Given a partially filled 9x9 2D array, the objective is to fill a 9x9
33
square grid with digits numbered 1 to 9, so that every row, column, and
4-
and each of the nine 3×3 sub-grids contains all of the digits.
4+
and each of the nine 3x3 sub-grids contains all of the digits.
55
66
This can be solved using Backtracking and is similar to n-queens.
77
We check to see if a cell is safe or not and recursively call the

Diff for: bit_manipulation/single_bit_manipulation_operations.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ def set_bit(number: int, position: int) -> int:
88
Set the bit at position to 1.
99
1010
Details: perform bitwise or for given number and X.
11-
Where X is a number with all the bits zeroes and bit on given
12-
position one.
11+
Where X is a number with all the bits - zeroes and bit on given
12+
position - one.
1313
1414
>>> set_bit(0b1101, 1) # 0b1111
1515
15
@@ -26,8 +26,8 @@ def clear_bit(number: int, position: int) -> int:
2626
Set the bit at position to 0.
2727
2828
Details: perform bitwise and for given number and X.
29-
Where X is a number with all the bits ones and bit on given
30-
position zero.
29+
Where X is a number with all the bits - ones and bit on given
30+
position - zero.
3131
3232
>>> clear_bit(0b10010, 1) # 0b10000
3333
16
@@ -42,8 +42,8 @@ def flip_bit(number: int, position: int) -> int:
4242
Flip the bit at position.
4343
4444
Details: perform bitwise xor for given number and X.
45-
Where X is a number with all the bits zeroes and bit on given
46-
position one.
45+
Where X is a number with all the bits - zeroes and bit on given
46+
position - one.
4747
4848
>>> flip_bit(0b101, 1) # 0b111
4949
7
@@ -79,7 +79,7 @@ def get_bit(number: int, position: int) -> int:
7979
Get the bit at the given position
8080
8181
Details: perform bitwise and for the given number and X,
82-
Where X is a number with all the bits zeroes and bit on given position one.
82+
Where X is a number with all the bits - zeroes and bit on given position - one.
8383
If the result is not equal to 0, then the bit on the given position is 1, else 0.
8484
8585
>>> get_bit(0b1010, 0)

Diff for: compression/burrows_wheeler.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
https://en.wikipedia.org/wiki/Burrows%E2%80%93Wheeler_transform
33
4-
The BurrowsWheeler transform (BWT, also called block-sorting compression)
4+
The Burrows-Wheeler transform (BWT, also called block-sorting compression)
55
rearranges a character string into runs of similar characters. This is useful
66
for compression, since it tends to be easy to compress a string that has runs
77
of repeated characters by techniques such as move-to-front transform and

Diff for: compression/lempel_ziv.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
One of the several implementations of LempelZivWelch compression algorithm
2+
One of the several implementations of Lempel-Ziv-Welch compression algorithm
33
https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch
44
"""
55

@@ -43,7 +43,7 @@ def add_key_to_lexicon(
4343

4444
def compress_data(data_bits: str) -> str:
4545
"""
46-
Compresses given data_bits using LempelZivWelch compression algorithm
46+
Compresses given data_bits using Lempel-Ziv-Welch compression algorithm
4747
and returns the result as a string
4848
"""
4949
lexicon = {"0": "0", "1": "1"}

Diff for: compression/lempel_ziv_decompress.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
One of the several implementations of LempelZivWelch decompression algorithm
2+
One of the several implementations of Lempel-Ziv-Welch decompression algorithm
33
https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch
44
"""
55

@@ -26,7 +26,7 @@ def read_file_binary(file_path: str) -> str:
2626

2727
def decompress_data(data_bits: str) -> str:
2828
"""
29-
Decompresses given data_bits using LempelZivWelch compression algorithm
29+
Decompresses given data_bits using Lempel-Ziv-Welch compression algorithm
3030
and returns the result as a string
3131
"""
3232
lexicon = {"0": "0", "1": "1"}

Diff for: computer_vision/cnn_classification.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
# Importing the Keras libraries and packages
2727
import tensorflow as tf
28-
from tensorflow.keras import layers, models
28+
from keras import layers, models
2929

3030
if __name__ == "__main__":
3131
# Initialising the CNN

Diff for: 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")

Diff for: data_structures/binary_tree/red_black_tree.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class RedBlackTree:
1717
and slower for reading in the average case, though, because they're
1818
both balanced binary search trees, both will get the same asymptotic
1919
performance.
20-
To read more about them, https://en.wikipedia.org/wiki/Redblack_tree
20+
To read more about them, https://en.wikipedia.org/wiki/Red-black_tree
2121
Unless otherwise specified, all asymptotic runtimes are specified in
2222
terms of the size of the tree.
2323
"""

Diff for: data_structures/hashing/hash_table.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#!/usr/bin/env python3
2+
from abc import abstractmethod
3+
24
from .number_theory.prime_numbers import next_prime
35

46

@@ -173,6 +175,7 @@ def _set_value(self, key, data):
173175
self.values[key] = data
174176
self._keys[key] = data
175177

178+
@abstractmethod
176179
def _collision_resolution(self, key, data=None):
177180
"""
178181
This method is a type of open addressing which is used for handling collision.

Diff for: data_structures/hashing/quadratic_probing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class QuadraticProbing(HashTable):
1111
def __init__(self, *args, **kwargs):
1212
super().__init__(*args, **kwargs)
1313

14-
def _collision_resolution(self, key, data=None):
14+
def _collision_resolution(self, key, data=None): # noqa: ARG002
1515
"""
1616
Quadratic probing is an open addressing scheme used for resolving
1717
collisions in hash table.

Diff for: digital_image_processing/edge_detection/canny.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ def detect_high_low_threshold(
7474
image_shape, destination, threshold_low, threshold_high, weak, strong
7575
):
7676
"""
77-
High-Low threshold detection. If an edge pixels gradient value is higher
77+
High-Low threshold detection. If an edge pixel's gradient value is higher
7878
than the high threshold value, it is marked as a strong edge pixel. If an
79-
edge pixels gradient value is smaller than the high threshold value and
79+
edge pixel's gradient value is smaller than the high threshold value and
8080
larger than the low threshold value, it is marked as a weak edge pixel. If
8181
an edge pixel's value is smaller than the low threshold value, it will be
8282
suppressed.

Diff for: digital_image_processing/index_calculation.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def arv12(self):
182182
Atmospherically Resistant Vegetation Index 2
183183
https://www.indexdatabase.de/db/i-single.php?id=396
184184
:return: index
185-
0.18+1.17*(self.nirself.red)/(self.nir+self.red)
185+
-0.18+1.17*(self.nir-self.red)/(self.nir+self.red)
186186
"""
187187
return -0.18 + (1.17 * ((self.nir - self.red) / (self.nir + self.red)))
188188

Diff for: dynamic_programming/combination_sum_iv.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
The basic idea is to go over recursively to find the way such that the sum
1919
of chosen elements is “tar”. For every element, we have two choices
2020
1. Include the element in our set of chosen elements.
21-
2. Dont include the element in our set of chosen elements.
21+
2. Don't include the element in our set of chosen elements.
2222
"""
2323

2424

Diff for: dynamic_programming/fast_fibonacci.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def _fib(n: int) -> tuple[int, int]:
2626
if n == 0: # (F(0), F(1))
2727
return (0, 1)
2828

29-
# F(2n) = F(n)[2F(n+1) F(n)]
29+
# F(2n) = F(n)[2F(n+1) - F(n)]
3030
# F(2n+1) = F(n+1)^2+F(n)^2
3131
a, b = _fib(n // 2)
3232
c = a * (b * 2 - a)

Diff for: electronics/coulombs_law.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ def couloumbs_law(
2020
2121
Reference
2222
----------
23-
Coulomb (1785) "Premier mémoire sur lélectricité et le magnétisme,"
24-
Histoire de lAcadémie Royale des Sciences, pp. 569577.
23+
Coulomb (1785) "Premier mémoire sur l'électricité et le magnétisme,"
24+
Histoire de l'Académie Royale des Sciences, pp. 569-577.
2525
2626
Parameters
2727
----------

Diff for: fuzzy_logic/fuzzy_operations.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class FuzzySet:
5757
5858
# Union Operations
5959
>>> siya.union(sheru)
60-
FuzzySet(name='Siya Sheru', left_boundary=0.4, peak=0.7, right_boundary=1.0)
60+
FuzzySet(name='Siya U Sheru', left_boundary=0.4, peak=0.7, right_boundary=1.0)
6161
"""
6262

6363
name: str
@@ -147,10 +147,10 @@ def union(self, other) -> FuzzySet:
147147
FuzzySet: A new fuzzy set representing the union.
148148
149149
>>> FuzzySet("a", 0.1, 0.2, 0.3).union(FuzzySet("b", 0.4, 0.5, 0.6))
150-
FuzzySet(name='a b', left_boundary=0.1, peak=0.6, right_boundary=0.35)
150+
FuzzySet(name='a U b', left_boundary=0.1, peak=0.6, right_boundary=0.35)
151151
"""
152152
return FuzzySet(
153-
f"{self.name} {other.name}",
153+
f"{self.name} U {other.name}",
154154
min(self.left_boundary, other.left_boundary),
155155
max(self.right_boundary, other.right_boundary),
156156
(self.peak + other.peak) / 2,

Diff for: graphs/ant_colony_optimization_algorithms.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def main(
3333
pheromone_evaporation: float,
3434
alpha: float,
3535
beta: float,
36-
q: float, # Pheromone system parameters Qwhich is a constant
36+
q: float, # Pheromone system parameters Q, which is a constant
3737
) -> tuple[list[int], float]:
3838
"""
3939
Ant colony algorithm main function
@@ -117,7 +117,7 @@ def pheromone_update(
117117
cities: dict[int, list[int]],
118118
pheromone_evaporation: float,
119119
ants_route: list[list[int]],
120-
q: float, # Pheromone system parameters Qwhich is a constant
120+
q: float, # Pheromone system parameters Q, which is a constant
121121
best_path: list[int],
122122
best_distance: float,
123123
) -> tuple[list[list[float]], list[int], float]:

Diff for: hashes/fletcher16.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
The Fletcher checksum is an algorithm for computing a position-dependent
3-
checksum devised by John G. Fletcher (19342012) at Lawrence Livermore Labs
3+
checksum devised by John G. Fletcher (1934-2012) at Lawrence Livermore Labs
44
in the late 1970s.[1] The objective of the Fletcher checksum was to
55
provide error-detection properties approaching those of a cyclic
66
redundancy check but with the lower computational effort associated

Diff for: linear_algebra/lu_decomposition.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Lowerupper (LU) decomposition factors a matrix as a product of a lower
2+
Lower-upper (LU) decomposition factors a matrix as a product of a lower
33
triangular matrix and an upper triangular matrix. A square matrix has an LU
44
decomposition under the following conditions:
55
- If the matrix is invertible, then it has an LU decomposition if and only

Diff for: linear_algebra/src/schur_complement.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def schur_complement(
1818
the pseudo_inv argument.
1919
2020
Link to Wiki: https://en.wikipedia.org/wiki/Schur_complement
21-
See also Convex Optimization Boyd and Vandenberghe, A.5.5
21+
See also Convex Optimization - Boyd and Vandenberghe, A.5.5
2222
>>> import numpy as np
2323
>>> a = np.array([[1, 2], [2, 1]])
2424
>>> b = np.array([[0, 3], [3, 0]])

Diff for: 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
"""

Diff for: machine_learning/lstm/lstm_prediction.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
import numpy as np
99
import pandas as pd
10+
from keras.layers import LSTM, Dense
11+
from keras.models import Sequential
1012
from sklearn.preprocessing import MinMaxScaler
11-
from tensorflow.keras.layers import LSTM, Dense
12-
from tensorflow.keras.models import Sequential
1313

1414
if __name__ == "__main__":
1515
"""

Diff for: machine_learning/polynomial_regression.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
1212
β = (XᵀX)⁻¹Xᵀy = X⁺y
1313
14-
where X is the design matrix, y is the response vector, and X⁺ denotes the MoorePenrose
14+
where X is the design matrix, y is the response vector, and X⁺ denotes the Moore-Penrose
1515
pseudoinverse of X. In the case of polynomial regression, the design matrix is
1616
1717
|1 x₁ x₁² ⋯ x₁ᵐ|
@@ -106,7 +106,7 @@ def fit(self, x_train: np.ndarray, y_train: np.ndarray) -> None:
106106
107107
β = (XᵀX)⁻¹Xᵀy = X⁺y
108108
109-
where X⁺ denotes the MoorePenrose pseudoinverse of the design matrix X. This
109+
where X⁺ denotes the Moore-Penrose pseudoinverse of the design matrix X. This
110110
function computes X⁺ using singular value decomposition (SVD).
111111
112112
References:
@@ -146,7 +146,7 @@ def fit(self, x_train: np.ndarray, y_train: np.ndarray) -> None:
146146
"Design matrix is not full rank, can't compute coefficients"
147147
)
148148

149-
# np.linalg.pinv() computes the MoorePenrose pseudoinverse using SVD
149+
# np.linalg.pinv() computes the Moore-Penrose pseudoinverse using SVD
150150
self.params = np.linalg.pinv(X) @ y_train
151151

152152
def predict(self, data: np.ndarray) -> np.ndarray:

Diff for: maths/chudnovsky_algorithm.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
def pi(precision: int) -> str:
66
"""
77
The Chudnovsky algorithm is a fast method for calculating the digits of PI,
8-
based on Ramanujans PI formulae.
8+
based on Ramanujan's PI formulae.
99
1010
https://en.wikipedia.org/wiki/Chudnovsky_algorithm
1111

Diff for: maths/entropy.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ def calculate_prob(text: str) -> None:
2121
:return: Prints
2222
1) Entropy of information based on 1 alphabet
2323
2) Entropy of information based on couples of 2 alphabet
24-
3) print Entropy of H(X n∣Xn−1)
24+
3) print Entropy of H(X n|Xn-1)
2525
2626
Text from random books. Also, random quotes.
27-
>>> text = ("Behind Winstons back the voice "
27+
>>> text = ("Behind Winston's back the voice "
2828
... "from the telescreen was still "
2929
... "babbling and the overfulfilment")
3030
>>> calculate_prob(text)

0 commit comments

Comments
 (0)