Upgrade to Python 3.13 (#11588) · foo123/The-Algorithms-Python@0177ae1 · GitHub
Skip to content

Commit 0177ae1

Browse files
authored
Upgrade to Python 3.13 (TheAlgorithms#11588)
1 parent a7bfa22 commit 0177ae1

35 files changed

Lines changed: 135 additions & 131 deletions

.github/workflows/build.yml

Lines changed: 5 additions & 1 deletion

DIRECTORY.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1343,7 +1343,6 @@
13431343
* [Get Ip Geolocation](web_programming/get_ip_geolocation.py)
13441344
* [Get Top Billionaires](web_programming/get_top_billionaires.py)
13451345
* [Get Top Hn Posts](web_programming/get_top_hn_posts.py)
1346-
* [Get User Tweets](web_programming/get_user_tweets.py)
13471346
* [Giphy](web_programming/giphy.py)
13481347
* [Instagram Crawler](web_programming/instagram_crawler.py)
13491348
* [Instagram Pic](web_programming/instagram_pic.py)

computer_vision/haralick_descriptors.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def root_mean_square_error(original: np.ndarray, reference: np.ndarray) -> float
1919
>>> root_mean_square_error(np.array([1, 2, 3]), np.array([6, 4, 2]))
2020
3.1622776601683795
2121
"""
22-
return np.sqrt(((original - reference) ** 2).mean())
22+
return float(np.sqrt(((original - reference) ** 2).mean()))
2323

2424

2525
def normalize_image(
@@ -273,7 +273,7 @@ def haralick_descriptors(matrix: np.ndarray) -> list[float]:
273273
>>> morphological = opening_filter(binary)
274274
>>> mask_1 = binary_mask(gray, morphological)[0]
275275
>>> concurrency = matrix_concurrency(mask_1, (0, 1))
276-
>>> haralick_descriptors(concurrency)
276+
>>> [float(f) for f in haralick_descriptors(concurrency)]
277277
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
278278
"""
279279
# Function np.indices could be used for bigger input types,
@@ -335,7 +335,7 @@ def get_descriptors(
335335
return np.concatenate(descriptors, axis=None)
336336

337337

338-
def euclidean(point_1: np.ndarray, point_2: np.ndarray) -> np.float32:
338+
def euclidean(point_1: np.ndarray, point_2: np.ndarray) -> float:
339339
"""
340340
Simple method for calculating the euclidean distance between two points,
341341
with type np.ndarray.
@@ -346,7 +346,7 @@ def euclidean(point_1: np.ndarray, point_2: np.ndarray) -> np.float32:
346346
>>> euclidean(a, b)
347347
3.3166247903554
348348
"""
349-
return np.sqrt(np.sum(np.square(point_1 - point_2)))
349+
return float(np.sqrt(np.sum(np.square(point_1 - point_2))))
350350

351351

352352
def get_distances(descriptors: np.ndarray, base: int) -> list[tuple[int, float]]:

data_structures/heap/binomial_heap.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class BinomialHeap:
7373
30
7474
7575
Deleting - delete() test
76-
>>> [first_heap.delete_min() for _ in range(20)]
76+
>>> [int(first_heap.delete_min()) for _ in range(20)]
7777
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
7878
7979
Create a new Heap
@@ -118,7 +118,7 @@ class BinomialHeap:
118118
values in merged heap; (merge is inplace)
119119
>>> results = []
120120
>>> while not first_heap.is_empty():
121-
... results.append(first_heap.delete_min())
121+
... results.append(int(first_heap.delete_min()))
122122
>>> results
123123
[17, 20, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 31, 34]
124124
"""
@@ -354,7 +354,7 @@ def delete_min(self):
354354
# Merge heaps
355355
self.merge_heaps(new_heap)
356356

357-
return min_value
357+
return int(min_value)
358358

359359
def pre_order(self):
360360
"""

electronics/circular_convolution.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def circular_convolution(self) -> list[float]:
3939
Usage:
4040
>>> convolution = CircularConvolution()
4141
>>> convolution.circular_convolution()
42-
[10, 10, 6, 14]
42+
[10.0, 10.0, 6.0, 14.0]
4343
4444
>>> convolution.first_signal = [0.2, 0.4, 0.6, 0.8, 1.0, 1.2, 1.4, 1.6]
4545
>>> convolution.second_signal = [0.1, 0.3, 0.5, 0.7, 0.9, 1.1, 1.3, 1.5]
@@ -54,7 +54,7 @@ def circular_convolution(self) -> list[float]:
5454
>>> convolution.first_signal = [1, -1, 2, 3, -1]
5555
>>> convolution.second_signal = [1, 2, 3]
5656
>>> convolution.circular_convolution()
57-
[8, -2, 3, 4, 11]
57+
[8.0, -2.0, 3.0, 4.0, 11.0]
5858
5959
"""
6060

@@ -91,7 +91,7 @@ def circular_convolution(self) -> list[float]:
9191
final_signal = np.matmul(np.transpose(matrix), np.transpose(self.first_signal))
9292

9393
# rounding-off to two decimal places
94-
return [round(i, 2) for i in final_signal]
94+
return [float(round(i, 2)) for i in final_signal]
9595

9696

9797
if __name__ == "__main__":

fractals/julia_sets.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@
4040
def eval_exponential(c_parameter: complex, z_values: np.ndarray) -> np.ndarray:
4141
"""
4242
Evaluate $e^z + c$.
43-
>>> eval_exponential(0, 0)
43+
>>> float(eval_exponential(0, 0))
4444
1.0
45-
>>> abs(eval_exponential(1, np.pi*1.j)) < 1e-15
45+
>>> bool(abs(eval_exponential(1, np.pi*1.j)) < 1e-15)
4646
True
47-
>>> abs(eval_exponential(1.j, 0)-1-1.j) < 1e-15
47+
>>> bool(abs(eval_exponential(1.j, 0)-1-1.j) < 1e-15)
4848
True
4949
"""
5050
return np.exp(z_values) + c_parameter
@@ -98,20 +98,20 @@ def iterate_function(
9898
9999
>>> iterate_function(eval_quadratic_polynomial, 0, 3, np.array([0,1,2])).shape
100100
(3,)
101-
>>> np.round(iterate_function(eval_quadratic_polynomial,
101+
>>> complex(np.round(iterate_function(eval_quadratic_polynomial,
102102
... 0,
103103
... 3,
104-
... np.array([0,1,2]))[0])
104+
... np.array([0,1,2]))[0]))
105105
0j
106-
>>> np.round(iterate_function(eval_quadratic_polynomial,
106+
>>> complex(np.round(iterate_function(eval_quadratic_polynomial,
107107
... 0,
108108
... 3,
109-
... np.array([0,1,2]))[1])
109+
... np.array([0,1,2]))[1]))
110110
(1+0j)
111-
>>> np.round(iterate_function(eval_quadratic_polynomial,
111+
>>> complex(np.round(iterate_function(eval_quadratic_polynomial,
112112
... 0,
113113
... 3,
114-
... np.array([0,1,2]))[2])
114+
... np.array([0,1,2]))[2]))
115115
(256+0j)
116116
"""
117117

graphics/bezier_curve.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ def basis_function(self, t: float) -> list[float]:
3030
returns the x, y values of basis function at time t
3131
3232
>>> curve = BezierCurve([(1,1), (1,2)])
33-
>>> curve.basis_function(0)
33+
>>> [float(x) for x in curve.basis_function(0)]
3434
[1.0, 0.0]
35-
>>> curve.basis_function(1)
35+
>>> [float(x) for x in curve.basis_function(1)]
3636
[0.0, 1.0]
3737
"""
3838
assert 0 <= t <= 1, "Time t must be between 0 and 1."
@@ -55,9 +55,9 @@ def bezier_curve_function(self, t: float) -> tuple[float, float]:
5555
The last point in the curve is when t = 1.
5656
5757
>>> curve = BezierCurve([(1,1), (1,2)])
58-
>>> curve.bezier_curve_function(0)
58+
>>> tuple(float(x) for x in curve.bezier_curve_function(0))
5959
(1.0, 1.0)
60-
>>> curve.bezier_curve_function(1)
60+
>>> tuple(float(x) for x in curve.bezier_curve_function(1))
6161
(1.0, 2.0)
6262
"""
6363

graphs/dijkstra_binary_grid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def dijkstra(
6969
x, y = predecessors[x, y]
7070
path.append(source) # add the source manually
7171
path.reverse()
72-
return matrix[destination], path
72+
return float(matrix[destination]), path
7373

7474
for i in range(len(dx)):
7575
nx, ny = x + dx[i], y + dy[i]

linear_algebra/src/power_iteration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def power_iteration(
7878
if is_complex:
7979
lambda_ = np.real(lambda_)
8080

81-
return lambda_, vector
81+
return float(lambda_), vector
8282

8383

8484
def test_power_iteration() -> None:

linear_programming/simplex.py

Lines changed: 16 additions & 16 deletions

0 commit comments

Comments
 (0)