fix(mypy): type annotations for linear algebra algorithms (#4317)

* fix(mypy): type annotations for linear algebra algorithms

* refactor: remove linear algebra directory from mypy exclude
This commit is contained in:
Dhruv Manilawala
2021-04-05 19:07:38 +05:30
committed by GitHub
parent 20c7518028
commit 8c2986026b
8 changed files with 100 additions and 74 deletions

View File

@ -1,6 +1,3 @@
from __future__ import annotations
def points_to_polynomial(coordinates: list[list[int]]) -> str:
"""
coordinates is a two dimensional matrix: [[x, y], [x, y], ...]
@ -55,12 +52,12 @@ def points_to_polynomial(coordinates: list[list[int]]) -> str:
if check == 1:
count_of_line = 0
matrix = []
matrix: list[list[float]] = []
# put the x and x to the power values in a matrix
while count_of_line < x:
count_in_line = 0
a = coordinates[count_of_line][0]
count_line: list[int] = []
count_line: list[float] = []
while count_in_line < x:
count_line.append(a ** (x - (count_in_line + 1)))
count_in_line += 1
@ -69,7 +66,7 @@ def points_to_polynomial(coordinates: list[list[int]]) -> str:
count_of_line = 0
# put the y values into a vector
vector: list[int] = []
vector: list[float] = []
while count_of_line < x:
vector.append(coordinates[count_of_line][1])
count_of_line += 1
@ -96,14 +93,14 @@ def points_to_polynomial(coordinates: list[list[int]]) -> str:
# make solutions
solution: list[str] = []
while count < x:
solution.append(vector[count] / matrix[count][count])
solution.append(str(vector[count] / matrix[count][count]))
count += 1
count = 0
solved = "f(x)="
while count < x:
remove_e: list[str] = str(solution[count]).split("E")
remove_e: list[str] = solution[count].split("E")
if len(remove_e) > 1:
solution[count] = remove_e[0] + "*10^" + remove_e[1]
solved += "x^" + str(x - (count + 1)) + "*" + str(solution[count])