Skip to content

Commit

Permalink
pie: apply some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ognevny committed Aug 18, 2024
1 parent 7060f68 commit 98ba6f7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 32 deletions.
12 changes: 6 additions & 6 deletions pie/Matrix_dz.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def __rmul__(self, m: int | Matrix) -> Matrix | None:
return res

@staticmethod
def findpivot(matr: list, r: int, c: int) -> tuple: # нахождение "опорного элемента"
def findpivot(matr: list, r: int, c: int) -> tuple | None: # нахождение "опорного элемента"
for i in range(c, len(matr[0])):
for j in range(r, len(matr)):
if matr[j][i] != 0:
Expand Down Expand Up @@ -170,7 +170,7 @@ def transposition_new(self) -> Matrix:
def __str__(self) -> str:
res = ""
for i in range(self.rows):
res += str(self.matr[i]) + "\n"
res += f"{self.matr[i]}\n"
return res


Expand All @@ -179,13 +179,13 @@ def __str__(self) -> str:

# генерация наших точек, для удобства ограничиваем область, в которой можно получить эти точки
for i in range(10):
x = secrets.randbelow(0, 30) / 10
y = secrets.randbelow(0, 30) / 10
x = secrets.randbelow(30) / 10
y = secrets.randbelow(30) / 10

while True:
if x / sqrt(x**2 + y**2) < cos(pi / 4):
x = secrets.randbelow(0, 30) / 10
y = secrets.randbelow(0, 30) / 10
x = secrets.randbelow(30) / 10
y = secrets.randbelow(30) / 10
else:
break
matrix_array.append(Matrix(2, 1, [[x], [y]]))
Expand Down
50 changes: 26 additions & 24 deletions pie/complex_dz.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,27 @@ class CNumb:
def __init__(self, real: float = 1.0, im: float = 0.0) -> None:
self.real = real
self.im = im
self.mod: float = sqrt(real**2 + im**2)

if real > 0 and im >= 0:
self.arg: float = atan(im / real)
def mod(self) -> float:
return sqrt(self.real**2 + self.im**2)

elif real > 0 and im < 0:
self.arg: float = atan(im / real) + 2 * pi
def arg(self) -> float:
if self.real > 0 and self.im >= 0:
return atan(self.im / self.real)

elif real < 0:
self.arg: float = atan(im / real) + pi
if self.real > 0 and self.im < 0:
return atan(self.im / self.real) + 2 * pi

elif real == 0:
if im < 0:
self.arg: float = 2 * pi - 0
if self.real < 0:
return atan(self.im / self.real) + pi

elif im > 0:
self.arg: float = pi * 0
if self.im < 0:
return 1.5 * pi

if self.im > 0:
return pi * 0.5

return 0.0

def __add__(self, a: float | CNumb) -> CNumb:
if isinstance(a, CNumb):
Expand Down Expand Up @@ -74,23 +78,21 @@ def __rsub__(self, a: float | CNumb) -> CNumb:

def __pow__(self, a: float) -> CNumb:
return CNumb(
(self.mod**a) * (cos(atan(a * self.arg))),
(self.mod**a) * (sin(atan(a * self.arg))),
(self.mod() ** a) * (cos(atan(a * self.arg()))),
(self.mod() ** a) * (sin(atan(a * self.arg()))),
)

def rad(self, a: int) -> list[str]:
resultc = []
for j in range(a):
resultc += [
str((self.mod ** (1 / a)) * (cos(atan((self.arg + 2 * pi * j) / a))))
+ "+"
+ str((self.mod ** (1 / a)) * (sin(atan((self.arg + 2 * pi * j) / a))))
+ "i",
]
return resultc
return [
str((self.mod() ** (1 / a)) * (cos(atan((self.arg() + 2 * pi * j) / a))))
+ "+"
+ str((self.mod() ** (1 / a)) * (sin(atan((self.arg() + 2 * pi * j) / a))))
+ "i"
for j in range(a)
]

def __str__(self) -> str:
return str(self.real) + "+" + str(self.im) + "i"
return f"{self.real}+{self.im}i"


n = CNumb(1, 2)
Expand Down
4 changes: 2 additions & 2 deletions pie/merge_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ def merge_sort(arr: list[int]) -> list[int]:


def generation(length: int) -> list[int]:
return [randbelow(10000) for _ in range(length)]
return [(randbelow(1000) + 1) * 10 for _ in range(length)]


if __name__ == "__main__":
data1 = map(generation, [randbelow(100000) for _ in range(100)])
data1 = map(generation, [(randbelow(10000) + 1) * 10 for _ in range(100)])
data2 = copy.deepcopy(data1)
start = perf_counter()
with mlp.Pool(processes=mlp.cpu_count()) as pool:
Expand Down

0 comments on commit 98ba6f7

Please sign in to comment.