Skip to content

Commit 4e2456f

Browse files
committed
Done with the required changes
1 parent 9ffd634 commit 4e2456f

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

maths/fibonacci.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from time import time
2121

2222
import numpy as np
23+
from numpy import ndarray
2324

2425

2526
def time_func(func, *args, **kwargs):
@@ -247,8 +248,7 @@ def matrix_mult_np(a, b):
247248
"""
248249
return np.dot(a, b)
249250

250-
251-
def matrix_pow_np(m: int, power: int) -> int:
251+
def matrix_pow_np(m: ndarray, power: int) -> ndarray:
252252
"""
253253
Raises a matrix to the power of 'power' using binary exponentiation.
254254
@@ -259,12 +259,12 @@ def matrix_pow_np(m: int, power: int) -> int:
259259
Returns:
260260
The matrix raised to the power.
261261
"""
262-
result = np.identity(2, dtype=int) # Identity matrix
262+
result = np.array([[1, 0], [0, 1]], dtype=int) # Identity matrix
263263
base = m
264264
while power:
265265
if power % 2 == 1:
266-
result = matrix_mult_np(result, base)
267-
base = matrix_mult_np(base, base)
266+
result = np.dot(result, base)
267+
base = np.dot(base, base)
268268
power //= 2
269269
return result
270270

0 commit comments

Comments
 (0)