From e6f4cb3b88f0fad4883da411801e2af86be9348e Mon Sep 17 00:00:00 2001 From: steph Date: Thu, 15 Oct 2026 13:29:45 +0200 Subject: [PATCH] The Start of Matrix Mania --- .gitignore | 3 + .idea/.gitignore | 8 ++ .idea/MatrixMania.iml | 10 ++ .idea/inspectionProfiles/Project_Default.xml | 12 +++ .../inspectionProfiles/profiles_settings.xml | 6 ++ .idea/misc.xml | 7 ++ .idea/modules.xml | 8 ++ .idea/vcs.xml | 6 ++ AGENTS.md | 4 + compute.py | 100 ++++++++++++++++++ pyproject.toml | 3 + 11 files changed, 167 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 .idea/MatrixMania.iml create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 AGENTS.md create mode 100644 compute.py create mode 100644 pyproject.toml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d1eb6e8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.venv/ +__pycache__/ +.env \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/MatrixMania.iml b/.idea/MatrixMania.iml new file mode 100644 index 0000000..56657b0 --- /dev/null +++ b/.idea/MatrixMania.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..d222b10 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,12 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..3770ad7 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..55c2805 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..79a2eba --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,4 @@ +# Regeln für dieses Projekt +- Code nach PEP 8, Zeilenlänge maximal 88 Zeichen. +- Jede Funktion und Methode hat einen Docstring und Type Hints. +- Vor jedem Commit: `ruff check` und `ruff format`. \ No newline at end of file diff --git a/compute.py b/compute.py new file mode 100644 index 0000000..8eaa557 --- /dev/null +++ b/compute.py @@ -0,0 +1,100 @@ +import math + +def matmul(matrix_a:list[list[float]], matrix_b: list[list[float]]) -> list[list[float]]: + """ + Add two numbers together. + :param matrix_a: The first Matrix + :type matrix_a: list[list[float]] + :param matrix_b: The second Matrix + :type matrix_b: list[list[float]] + :return: The Matrix Multiplication of matrix_a and matrix_b + :rtype: list[list[float]] + """ + try: + if len(matrix_a[0]) != len(matrix_b): + raise ValueError("Differing Matrix Size") + target_height = len(matrix_a) + target_width = len(matrix_b[0]) + + end_matrix : list[list[float]]= [] + + + for height in range(target_height): + end_matrix.append([]) + for width in range(target_width): + row = matrix_a[height] + column_ = [] + for b in matrix_b: + column_.append(b[width]) + result_quarter = 0 + for i in range(len(row)): + result_quarter += row[i] * column_[i] + end_matrix[height].append(float(result_quarter)) + + return end_matrix + except ValueError: + print("An Error has occurred") + except IndexError: + print("Tried to call non-existing Index") + except TypeError: + print("Tried to insert not a Number") + + + +def transpose(matrix:list[list[float]]) -> list[list[float]]: + """ + Transposes a matrix. + :param matrix: The Matrix, that will be transposed + :type matrix: list[list[float]] + :return: The transposed matrix + :rtype: list[list[float]] + """ + + transposed_matrix = [] + for x in range(len(matrix[0])): + column = [] + for b in matrix: + column.append(b[x]) + transposed_matrix.append(column) + + return transposed_matrix + +def rot_2d(angle:float) -> list[list[float]]: + """ + Creates a Rotation Matrix out of the given angle + :param angle: The rotation in radians + :type angle: float + :return: The Rotation Matrix + :rtype: list[list[float]] + """ + sin = round(math.sin(angle), 4) + cos = round(math.cos(angle), 4) + return [[cos, -sin], + [sin, cos]] + + + + +def print_matrix(matrix:list[list[float]]) -> None: + for row in matrix: + print(row) + +if __name__ == "__main__": + matrix_bsp_a = [[1, 2, 3], [4, 5, 6]] + matrix_bsp_b = [[1, 2], [3, 4], [5, 6]] + matrix_bsp_c = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] + matrix_bsp_d = [[1, 4, 7], [2, 5, 8], [3, 6, 9]] + + if False: + matrix_bsp_result = matmul(matrix_bsp_c, matrix_bsp_d) + print_matrix(matrix_bsp_result) + + if False: + matrix_bsp_result = transpose(matrix_bsp_d) + #print_matrix(matrix_bsp_c) + print_matrix(matrix_bsp_result) + + if True: + print_matrix(rot_2d(math.pi*.25)) + + print("Done") diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..46e3b47 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,3 @@ +[project] +name = "matrixmania" +version = "0.1.0" \ No newline at end of file