Skip to content

Commit abcc390

Browse files
github-actionsgithub-actions
github-actions
authored and
github-actions
committed
fixup! Format Python code with psf/black push
1 parent 88522bd commit abcc390

Some content is hidden

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

47 files changed

+69
-69
lines changed

arithmetic_analysis/bisection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def bisection(
1919
return
2020
else:
2121
mid = start + (end - start) / 2.0
22-
while abs(start - mid) > 10 ** -7: # until we achieve precise equals to 10^-7
22+
while abs(start - mid) > 10**-7: # until we achieve precise equals to 10^-7
2323
if function(mid) == 0:
2424
return mid
2525
elif function(mid) * function(start) < 0:

arithmetic_analysis/in_static_equilibrium.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def polar_force(
2727

2828

2929
def in_static_equilibrium(
30-
forces: array, location: array, eps: float = 10 ** -1
30+
forces: array, location: array, eps: float = 10**-1
3131
) -> bool:
3232
"""
3333
Check if a system is in equilibrium.

arithmetic_analysis/intersection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def intersection(
1010
x_n2 = x_n1 - (
1111
function(x_n1) / ((function(x_n1) - function(x_n)) / (x_n1 - x_n))
1212
)
13-
if abs(x_n2 - x_n1) < 10 ** -5:
13+
if abs(x_n2 - x_n1) < 10**-5:
1414
return x_n2
1515
x_n = x_n1
1616
x_n1 = x_n2

arithmetic_analysis/newton_method.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ def newton(function, function1, startingInt):
88
x_n = startingInt
99
while True:
1010
x_n1 = x_n - function(x_n) / function1(x_n)
11-
if abs(x_n - x_n1) < 10 ** -5:
11+
if abs(x_n - x_n1) < 10**-5:
1212
return x_n1
1313
x_n = x_n1
1414

1515

1616
def f(x):
17-
return (x ** 3) - (2 * x) - 5
17+
return (x**3) - (2 * x) - 5
1818

1919

2020
def f1(x):
21-
return 3 * (x ** 2) - 2
21+
return 3 * (x**2) - 2
2222

2323

2424
if __name__ == "__main__":

arithmetic_analysis/newton_raphson.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from sympy import diff
99

1010

11-
def newton_raphson(func: str, a: int, precision: int = 10 ** -10) -> float:
11+
def newton_raphson(func: str, a: int, precision: int = 10**-10) -> float:
1212
"""Finds root from the point 'a' onwards by Newton-Raphson method
1313
>>> newton_raphson("sin(x)", 2)
1414
3.1415926536808043

ciphers/deterministic_miller_rabin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def miller_rabin(n, allow_probable=False):
7373
for prime in plist:
7474
pr = False
7575
for r in range(s):
76-
m = pow(prime, d * 2 ** r, n)
76+
m = pow(prime, d * 2**r, n)
7777
# see article for analysis explanation for m
7878
if (r == 0 and m == 1) or ((m + 1) % n == 0):
7979
pr = True

ciphers/rabin_miller.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def rabinMiller(num):
2121
return False
2222
else:
2323
i = i + 1
24-
v = (v ** 2) % num
24+
v = (v**2) % num
2525
return True
2626

2727

ciphers/rsa_cipher.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ def getTextFromBlocks(blockInts, messageLength, blockSize=DEFAULT_BLOCK_SIZE):
5858
blockMessage = []
5959
for i in range(blockSize - 1, -1, -1):
6060
if len(message) + i < messageLength:
61-
asciiNumber = blockInt // (BYTE_SIZE ** i)
62-
blockInt = blockInt % (BYTE_SIZE ** i)
61+
asciiNumber = blockInt // (BYTE_SIZE**i)
62+
blockInt = blockInt % (BYTE_SIZE**i)
6363
blockMessage.insert(0, chr(asciiNumber))
6464
message.extend(blockMessage)
6565
return "".join(message)

ciphers/rsa_factorization.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def rsafactor(d: int, e: int, N: int) -> List[int]:
3939
while True:
4040
if t % 2 == 0:
4141
t = t // 2
42-
x = (g ** t) % N
42+
x = (g**t) % N
4343
y = math.gcd(x - 1, N)
4444
if x > 1 and y > 1:
4545
p = y

computer_vision/harriscorner.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ def detect(self, img_path: str):
3939
color_img = img.copy()
4040
color_img = cv2.cvtColor(color_img, cv2.COLOR_GRAY2RGB)
4141
dy, dx = np.gradient(img)
42-
ixx = dx ** 2
43-
iyy = dy ** 2
42+
ixx = dx**2
43+
iyy = dy**2
4444
ixy = dx * dy
4545
k = 0.04
4646
offset = self.window_size // 2
@@ -56,9 +56,9 @@ def detect(self, img_path: str):
5656
y - offset : y + offset + 1, x - offset : x + offset + 1
5757
].sum()
5858

59-
det = (wxx * wyy) - (wxy ** 2)
59+
det = (wxx * wyy) - (wxy**2)
6060
trace = wxx + wyy
61-
r = det - k * (trace ** 2)
61+
r = det - k * (trace**2)
6262
# Can change the value
6363
if r > 0.5:
6464
corner_list.append([x, y, r])

digital_image_processing/index_calculation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def CVI(self):
203203
https://www.indexdatabase.de/db/i-single.php?id=391
204204
:return: index
205205
"""
206-
return self.nir * (self.red / (self.green ** 2))
206+
return self.nir * (self.red / (self.green**2))
207207

208208
def GLI(self):
209209
"""
@@ -295,7 +295,7 @@ def ATSAVI(self, X=0.08, a=1.22, b=0.03):
295295
"""
296296
return a * (
297297
(self.nir - a * self.red - b)
298-
/ (a * self.nir + self.red - a * b + X * (1 + a ** 2))
298+
/ (a * self.nir + self.red - a * b + X * (1 + a**2))
299299
)
300300

301301
def BWDRVI(self):
@@ -363,7 +363,7 @@ def GEMI(self):
363363
https://www.indexdatabase.de/db/i-single.php?id=25
364364
:return: index
365365
"""
366-
n = (2 * (self.nir ** 2 - self.red ** 2) + 1.5 * self.nir + 0.5 * self.red) / (
366+
n = (2 * (self.nir**2 - self.red**2) + 1.5 * self.nir + 0.5 * self.red) / (
367367
self.nir + self.red + 0.5
368368
)
369369
return n * (1 - 0.25 * n) - (self.red - 0.125) / (1 - self.red)

graphics/bezier_curve.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def basis_function(self, t: float) -> List[float]:
4040
for i in range(len(self.list_of_points)):
4141
# basis function for each i
4242
output_values.append(
43-
comb(self.degree, i) * ((1 - t) ** (self.degree - i)) * (t ** i)
43+
comb(self.degree, i) * ((1 - t) ** (self.degree - i)) * (t**i)
4444
)
4545
# the basis must sum up to 1 for it to produce a valid Bezier curve.
4646
assert round(sum(output_values), 5) == 1

graphs/bidirectional_a_star.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def calculate_heuristic(self) -> float:
5858
if HEURISTIC == 1:
5959
return abs(dx) + abs(dy)
6060
else:
61-
return sqrt(dy ** 2 + dx ** 2)
61+
return sqrt(dy**2 + dx**2)
6262

6363
def __lt__(self, other) -> bool:
6464
return self.f_cost < other.f_cost

hashes/chaos_machine.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ def xorshift(X, Y):
6262
params_space[key] = (machine_time * 0.01 + r * 1.01) % 1 + 3
6363

6464
# Choosing Chaotic Data
65-
X = int(buffer_space[(key + 2) % m] * (10 ** 10))
66-
Y = int(buffer_space[(key - 2) % m] * (10 ** 10))
65+
X = int(buffer_space[(key + 2) % m] * (10**10))
66+
Y = int(buffer_space[(key - 2) % m] * (10**10))
6767

6868
# Machine Time
6969
machine_time += 1

hashes/hamming_code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def emitterConverter(sizePar, data):
7878
>>> emitterConverter(4, "101010111111")
7979
['1', '1', '1', '1', '0', '1', '0', '0', '1', '0', '1', '1', '1', '1', '1', '1']
8080
"""
81-
if sizePar + len(data) <= 2 ** sizePar - (len(data) - 1):
81+
if sizePar + len(data) <= 2**sizePar - (len(data) - 1):
8282
print("ERROR - size of parity don't match with size of data")
8383
exit(0)
8484

hashes/md5.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def not32(i):
9595

9696
def sum32(a, b):
9797
""" """
98-
return (a + b) % 2 ** 32
98+
return (a + b) % 2**32
9999

100100

101101
def leftrot32(i, s):
@@ -115,7 +115,7 @@ def md5me(testString):
115115
bs += format(ord(i), "08b")
116116
bs = pad(bs)
117117

118-
tvals = [int(2 ** 32 * abs(math.sin(i + 1))) for i in range(64)]
118+
tvals = [int(2**32 * abs(math.sin(i + 1))) for i in range(64)]
119119

120120
a0 = 0x67452301
121121
b0 = 0xEFCDAB89
@@ -212,7 +212,7 @@ def md5me(testString):
212212
dtemp = D
213213
D = C
214214
C = B
215-
B = sum32(B, leftrot32((A + f + tvals[i] + m[g]) % 2 ** 32, s[i]))
215+
B = sum32(B, leftrot32((A + f + tvals[i] + m[g]) % 2**32, s[i]))
216216
A = dtemp
217217
a0 = sum32(a0, A)
218218
b0 = sum32(b0, B)

linear_algebra/src/lib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def euclidLength(self):
9393
"""
9494
summe = 0
9595
for c in self.__components:
96-
summe += c ** 2
96+
summe += c**2
9797
return math.sqrt(summe)
9898

9999
def __add__(self, other):

machine_learning/k_means_clust.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def compute_heterogeneity(data, k, centroids, cluster_assignment):
117117
distances = pairwise_distances(
118118
member_data_points, [centroids[i]], metric="euclidean"
119119
)
120-
squared_distances = distances ** 2
120+
squared_distances = distances**2
121121
heterogeneity += np.sum(squared_distances)
122122

123123
return heterogeneity

machine_learning/sequential_minimum_optimization.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,15 +339,15 @@ def _get_new_alpha(self, i1, i2, a1, a2, e1, e2, y1, y2):
339339
ol = (
340340
l1 * f1
341341
+ L * f2
342-
+ 1 / 2 * l1 ** 2 * K(i1, i1)
343-
+ 1 / 2 * L ** 2 * K(i2, i2)
342+
+ 1 / 2 * l1**2 * K(i1, i1)
343+
+ 1 / 2 * L**2 * K(i2, i2)
344344
+ s * L * l1 * K(i1, i2)
345345
)
346346
oh = (
347347
h1 * f1
348348
+ H * f2
349-
+ 1 / 2 * h1 ** 2 * K(i1, i1)
350-
+ 1 / 2 * H ** 2 * K(i2, i2)
349+
+ 1 / 2 * h1**2 * K(i1, i1)
350+
+ 1 / 2 * H**2 * K(i2, i2)
351351
+ s * H * h1 * K(i1, i2)
352352
)
353353
"""

maths/area_under_curve.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def trapezoidal_area(
4949
if __name__ == "__main__":
5050

5151
def f(x):
52-
return x ** 3 + x ** 2
52+
return x**3 + x**2
5353

5454
print("f(x) = x^3 + x^2")
5555
print("The area between the curve, x = -5, x = 5 and the x axis is:")

maths/armstrong_numbers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def armstrong_number(n: int) -> bool:
3737
temp = n
3838
while temp > 0:
3939
rem = temp % 10
40-
sum += rem ** number_of_digits
40+
sum += rem**number_of_digits
4141
temp //= 10
4242
return n == sum
4343

maths/basic_maths.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ def sum_of_divisors(n: int) -> int:
5151
temp += 1
5252
n = int(n / 2)
5353
if temp > 1:
54-
s *= (2 ** temp - 1) / (2 - 1)
54+
s *= (2**temp - 1) / (2 - 1)
5555
for i in range(3, int(math.sqrt(n)) + 1, 2):
5656
temp = 1
5757
while n % i == 0:
5858
temp += 1
5959
n = int(n / i)
6060
if temp > 1:
61-
s *= (i ** temp - 1) / (i - 1)
61+
s *= (i**temp - 1) / (i - 1)
6262
return int(s)
6363

6464

maths/gaussian.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def gaussian(x, mu: float = 0.0, sigma: float = 1.0) -> int:
5050
>>> gaussian(2523, mu=234234, sigma=3425)
5151
0.0
5252
"""
53-
return 1 / sqrt(2 * pi * sigma ** 2) * exp(-((x - mu) ** 2) / 2 * sigma ** 2)
53+
return 1 / sqrt(2 * pi * sigma**2) * exp(-((x - mu) ** 2) / 2 * sigma**2)
5454

5555

5656
if __name__ == "__main__":

maths/karatsuba.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ def karatsuba(a, b):
1414
m1 = max(len(str(a)), len(str(b)))
1515
m2 = m1 // 2
1616

17-
a1, a2 = divmod(a, 10 ** m2)
18-
b1, b2 = divmod(b, 10 ** m2)
17+
a1, a2 = divmod(a, 10**m2)
18+
b1, b2 = divmod(b, 10**m2)
1919

2020
x = karatsuba(a2, b2)
2121
y = karatsuba((a1 + a2), (b1 + b2))

maths/monte_carlo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def pi_estimator(iterations: int):
2020
"""
2121
# A local function to see if a dot lands in the circle.
2222
def is_in_circle(x: float, y: float) -> bool:
23-
distance_from_centre = sqrt((x ** 2) + (y ** 2))
23+
distance_from_centre = sqrt((x**2) + (y**2))
2424
# Our circle has a radius of 1, so a distance
2525
# greater than 1 would land outside the circle.
2626
return distance_from_centre <= 1

maths/numerical_integration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def trapezoidal_area(
5555
if __name__ == "__main__":
5656

5757
def f(x):
58-
return x ** 3
58+
return x**3
5959

6060
print("f(x) = x^3")
6161
print("The area between the curve, x = -10, x = 10 and the x axis is:")

maths/pi_monte_carlo_estimation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def is_in_unit_circle(self) -> bool:
1111
True, if the point lies in the unit circle
1212
False, otherwise
1313
"""
14-
return (self.x ** 2 + self.y ** 2) <= 1
14+
return (self.x**2 + self.y**2) <= 1
1515

1616
@classmethod
1717
def random_unit_square(cls):

maths/polynomial_evaluation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def evaluate_poly(poly: Sequence[float], x: float) -> float:
1212
>>> evaluate_poly((0.0, 0.0, 5.0, 9.3, 7.0), 10.0)
1313
79800.0
1414
"""
15-
return sum(c * (x ** i) for i, c in enumerate(poly))
15+
return sum(c * (x**i) for i, c in enumerate(poly))
1616

1717

1818
def horner(poly: Sequence[float], x: float) -> float:

maths/radix2_fft.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def __DFT(self, which):
9191
next_ncol = self.C_max_length // 2
9292
while next_ncol > 0:
9393
new_dft = [[] for i in range(next_ncol)]
94-
root = self.root ** next_ncol
94+
root = self.root**next_ncol
9595

9696
# First half of next step
9797
current_root = 1

maths/segmented_sieve.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@ def sieve(n):
4848
return prime
4949

5050

51-
print(sieve(10 ** 6))
51+
print(sieve(10**6))

project_euler/problem_06/sol1.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ def solution(n):
3131
suma = 0
3232
sumb = 0
3333
for i in range(1, n + 1):
34-
suma += i ** 2
34+
suma += i**2
3535
sumb += i
36-
sum = sumb ** 2 - suma
36+
sum = sumb**2 - suma
3737
return sum
3838

3939

project_euler/problem_07/sol2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010
def isprime(number):
11-
for i in range(2, int(number ** 0.5) + 1):
11+
for i in range(2, int(number**0.5) + 1):
1212
if number % i == 0:
1313
return False
1414
return True

project_euler/problem_09/sol1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def solution():
2525
for b in range(400):
2626
for c in range(500):
2727
if a < b < c:
28-
if (a ** 2) + (b ** 2) == (c ** 2):
28+
if (a**2) + (b**2) == (c**2):
2929
if (a + b + c) == 1000:
3030
return a * b * c
3131

project_euler/problem_10/sol3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def prime_sum(n: int) -> int:
4141
list_[0] = 1
4242
list_[1] = 1
4343

44-
for i in range(2, int(n ** 0.5) + 1):
44+
for i in range(2, int(n**0.5) + 1):
4545
if list_[i] == 0:
4646
for j in range(i * i, n + 1, i):
4747
list_[j] = 1

0 commit comments

Comments
 (0)