Dritter Stand: compute.py
This commit is contained in:
1 parent
ed3f3fdfd3
commit
eb6225d194
4 files changed
+68
-8
No files matched your search
+65
-4
@@ -10,8 +10,11 @@ The functions perform validity checks on the dimensions:
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import math
|
||||
|
||||
from tabulate import tabulate
|
||||
|
||||
|
||||
def matmul(a: list[list[float]], b: list[list[float]]) -> list[list[float]]:
|
||||
"""Multiply two 2‑D matrices."""
|
||||
@@ -86,21 +89,79 @@ if __name__ == "__main__":
|
||||
# Valid example: multiplication
|
||||
matrix_a = [[1, 2, 3], [4, 5, 6]]
|
||||
matrix_b = [[7, 8], [9, 10], [11, 12]]
|
||||
|
||||
print("Valid multiplication result:")
|
||||
print(matmul(matrix_a, matrix_b))
|
||||
result_mul = matmul(matrix_a, matrix_b)
|
||||
print(tabulate(result_mul, tablefmt="grid"))
|
||||
|
||||
# Valid example: transposition
|
||||
print("\nTransposed matrix_a result:")
|
||||
print(transpose(matrix_a))
|
||||
result_trans = transpose(matrix_a)
|
||||
print(tabulate(result_trans, tablefmt="grid"))
|
||||
|
||||
# Valid example: rotation (2D)
|
||||
print("\nRotated 2D matrix (theta = 0.5) result:")
|
||||
print(rot_2D(0.5))
|
||||
result_rot = rot_2D(0.5)
|
||||
print(tabulate(result_rot, tablefmt="fancy_grid"))
|
||||
|
||||
# Example that raises ValueError
|
||||
try:
|
||||
invalid_b = [[1, 2], [3, 4]]
|
||||
print("\nThis should raise an error:")
|
||||
print(matmul(matrix_a, invalid_b))
|
||||
matmul(matrix_a, invalid_b)
|
||||
except ValueError as e:
|
||||
print("Caught ValueError as expected:", e)
|
||||
|
||||
|
||||
# Ruff-Analyse:
|
||||
#
|
||||
# --> To_the_moon\compute.py:12:1
|
||||
# |
|
||||
# 10 | """
|
||||
# 11 |
|
||||
# 12 | / from __future__ import annotations
|
||||
# 13 | | import math
|
||||
# 14 | | from tabulate import tabulate
|
||||
# | |_____________________________^
|
||||
# help: Organize imports
|
||||
# |
|
||||
# 12 | from __future__ import annotations
|
||||
# 13 +
|
||||
# 14 | import math
|
||||
# 15 +
|
||||
# 16 | from tabulate import tabulate
|
||||
# |
|
||||
#
|
||||
# SIM103 Return the condition `event.type != pygame.QUIT` directly
|
||||
# --> To_the_moon\game.py:78:9
|
||||
# |
|
||||
# 76 | ``False`` bei ``pygame.QUIT``, sonst ``True``.
|
||||
# 77 | """
|
||||
# 78 | / if event.type == pygame.QUIT:
|
||||
# 79 | | return False
|
||||
# 80 | | return True
|
||||
# | |___________________^
|
||||
# 81 |
|
||||
# 82 | def update_game(self) -> bool:
|
||||
# |
|
||||
# help: Replace with `return event.type != pygame.QUIT`
|
||||
#
|
||||
# I001 [*] Import block is un-sorted or un-formatted
|
||||
# --> To_the_moon\moon.py:1:1
|
||||
# |
|
||||
# 1 | / import pygame
|
||||
# 2 | |
|
||||
# 3 | | from compute import matmul, rot_2D, transpose
|
||||
# 4 | | from game import Game
|
||||
# | |_____________________^
|
||||
# 5 |
|
||||
# 6 | EARTH_RADIUS = 30
|
||||
# |
|
||||
# help: Organize imports
|
||||
# |
|
||||
# 1 | import pygame
|
||||
# -
|
||||
# 2 | from compute import matmul, rot_2D, transpose
|
||||
# |
|
||||
#
|
||||
# Found 3 errors.
|
||||
+2
-3
@@ -75,9 +75,8 @@ class Game:
|
||||
Returns:
|
||||
``False`` bei ``pygame.QUIT``, sonst ``True``.
|
||||
"""
|
||||
if event.type == pygame.QUIT:
|
||||
return False
|
||||
return True
|
||||
|
||||
return event.type != pygame.QUIT
|
||||
|
||||
def update_game(self) -> bool:
|
||||
"""Aktualisiert den Spielzustand um einen Frame.
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import pygame
|
||||
|
||||
from compute import matmul, rot_2D, transpose
|
||||
from game import Game
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
[project]
|
||||
name = "matrixmania"
|
||||
version = "0.1.0"
|
||||
dependencies = ["tabulate", "ruff"]
|
||||
Reference in new issue
Block a user