Skip to content

Commit 0324e60

Browse files
umutKaracelebipre-commit-ci[bot]MaximSmolskiy
authored
style: add type hints to matrix_exponentiation.py (#14288)
* style: add type hints to matrix_exponentiation.py * Refactor kth_permutation and fix linter errors * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Delete machine_learning/linear_discriminant_analysis.py * Revert "Delete machine_learning/linear_discriminant_analysis.py" This reverts commit de29647. * Update linear_discriminant_analysis.py * Update kth_lexicographic_permutation.py * Update matrix_exponentiation.py * Update matrix_exponentiation.py --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Maxim Smolskiy <mithridatus@mail.ru>
1 parent 8e70e2e commit 0324e60

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

maths/matrix_exponentiation.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111

1212

1313
class Matrix:
14-
def __init__(self, arg):
14+
def __init__(self, arg: list[list] | int) -> None:
1515
if isinstance(arg, list): # Initializes a matrix identical to the one provided.
1616
self.t = arg
1717
self.n = len(arg)
1818
else: # Initializes a square matrix of the given size and set values to zero.
1919
self.n = arg
2020
self.t = [[0 for _ in range(self.n)] for _ in range(self.n)]
2121

22-
def __mul__(self, b):
22+
def __mul__(self, b: Matrix) -> Matrix:
2323
matrix = Matrix(self.n)
2424
for i in range(self.n):
2525
for j in range(self.n):
@@ -28,7 +28,7 @@ def __mul__(self, b):
2828
return matrix
2929

3030

31-
def modular_exponentiation(a, b):
31+
def modular_exponentiation(a: Matrix, b: int) -> Matrix:
3232
matrix = Matrix([[1, 0], [0, 1]])
3333
while b > 0:
3434
if b & 1:
@@ -38,7 +38,7 @@ def modular_exponentiation(a, b):
3838
return matrix
3939

4040

41-
def fibonacci_with_matrix_exponentiation(n, f1, f2):
41+
def fibonacci_with_matrix_exponentiation(n: int, f1: int, f2: int) -> int:
4242
"""
4343
Returns the nth number of the Fibonacci sequence that
4444
starts with f1 and f2
@@ -64,7 +64,7 @@ def fibonacci_with_matrix_exponentiation(n, f1, f2):
6464
return f2 * matrix.t[0][0] + f1 * matrix.t[0][1]
6565

6666

67-
def simple_fibonacci(n, f1, f2):
67+
def simple_fibonacci(n: int, f1: int, f2: int) -> int:
6868
"""
6969
Returns the nth number of the Fibonacci sequence that
7070
starts with f1 and f2
@@ -95,7 +95,7 @@ def simple_fibonacci(n, f1, f2):
9595
return f2
9696

9797

98-
def matrix_exponentiation_time():
98+
def matrix_exponentiation_time() -> float:
9999
setup = """
100100
from random import randint
101101
from __main__ import fibonacci_with_matrix_exponentiation
@@ -106,7 +106,7 @@ def matrix_exponentiation_time():
106106
return exec_time
107107

108108

109-
def simple_fibonacci_time():
109+
def simple_fibonacci_time() -> float:
110110
setup = """
111111
from random import randint
112112
from __main__ import simple_fibonacci
@@ -119,7 +119,7 @@ def simple_fibonacci_time():
119119
return exec_time
120120

121121

122-
def main():
122+
def main() -> None:
123123
matrix_exponentiation_time()
124124
simple_fibonacci_time()
125125

0 commit comments

Comments
 (0)