commit aa94d993764d79659e41b1723eca7dfe0aceba3e Author: Anna Date: Thu Oct 15 15:16:06 2026 +0200 1 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..30cf57e --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Ignored default folder with query files +/queries/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml 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/matrixmania.iml b/.idea/matrixmania.iml new file mode 100644 index 0000000..9497d65 --- /dev/null +++ b/.idea/matrixmania.iml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..bd2b627 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..7b1daae --- /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..387ef5b --- /dev/null +++ b/compute.py @@ -0,0 +1,101 @@ +"""Matrix multiplication with explicit dimension checks.""" + +from __future__ import annotations + +from collections.abc import Sequence + +Matrix = Sequence[Sequence[float]] + + +def matmul(left: Matrix, right: Matrix) -> list[list[float]]: + """Multiply two matrices and return a new matrix. + + Args: + left: Matrix of shape (rows_left, cols_left). + right: Matrix of shape (rows_right, cols_right). + + Returns: + A new matrix of shape (rows_left, cols_right). + + Raises: + ValueError: If either input is empty, ragged, or if + cols_left != rows_right. + """ + _validate(left, "left") + _validate(right, "right") + + cols_left = len(left[0]) + rows_right = len(right) + if cols_left != rows_right: + raise ValueError( + f"dimension mismatch: left has {cols_left} columns, " + f"right has {rows_right} rows" + ) + + cols_right = len(right[0]) + result: list[list[float]] = [] + for i in range(len(left)): + row: list[float] = [] + for j in range(cols_right): + total = 0.0 + for k in range(cols_left): + total += left[i][k] * right[k][j] + row.append(total) + result.append(row) + return result + + +def _validate(matrix: Matrix, name: str) -> None: + """Check that *matrix* is a non-empty, rectangular 2D sequence.""" + if len(matrix) == 0: + raise ValueError(f"{name} matrix is empty") + width = len(matrix[0]) + if width == 0: + raise ValueError(f"{name} matrix has no columns") + for index, row in enumerate(matrix): + if len(row) != width: + raise ValueError( + f"{name} matrix is ragged: row 0 has {width} columns, " + f"row {index} has {len(row)}" + ) + + +if __name__ == "__main__": + # Example 1: standard 2x3 * 3x2 multiplication. + a = [ + [1, 2, 3], + [4, 5, 6], + ] + b = [ + [7, 8], + [9, 10], + [11, 12], + ] + expected = [ + [58, 64], + [139, 154], + ] + assert matmul(a, b) == expected, f"example 1 failed: {matmul(a, b)}" + print("example 1 passed:", matmul(a, b)) + + # Example 2: multiplication with the identity matrix changes nothing. + identity = [ + [1, 0, 0], + [0, 1, 0], + [0, 0, 1], + ] + c = [ + [2, -1, 0], + [0, 3, 4], + [5, 6, -2], + ] + assert matmul(c, identity) == c, "example 2 failed" + print("example 2 passed:", matmul(c, identity)) + + # Example 3: mismatched dimensions must raise ValueError. + try: + matmul([[1, 2, 3]], [[1, 2]]) + except ValueError as error: + print("example 3 passed:", error) + else: + raise AssertionError("example 3 failed: no ValueError raised") diff --git a/main.py b/main.py new file mode 100644 index 0000000..5596b44 --- /dev/null +++ b/main.py @@ -0,0 +1,16 @@ +# This is a sample Python script. + +# Press Shift+F10 to execute it or replace it with your code. +# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings. + + +def print_hi(name): + # Use a breakpoint in the code line below to debug your script. + print(f'Hi, {name}') # Press Ctrl+F8 to toggle the breakpoint. + + +# Press the green button in the gutter to run the script. +if __name__ == '__main__': + print_hi('PyCharm') + +# See PyCharm help at https://www.jetbrains.com/help/pycharm/ diff --git a/opencode.json b/opencode.json new file mode 100644 index 0000000..15be39d --- /dev/null +++ b/opencode.json @@ -0,0 +1,16 @@ +{ + "$schema": "https://opencode.ai/config.json", + "provider": { + "thn": { + "npm": "@ai-sdk/openai-compatible", + "options": { + "baseURL": "http://141.75.33.244:8000/v1", + "apiKey": "sk-QXj1p40XOwNSze_5-eYrBzVh3qIgAfqoWPkAjNVqOS8" + }, + "models": { + "gpt-oss:20b": { "name": "GPT-OSS 20B" } + } + } + }, + "model": "thn/gpt-oss:20b" +} \ No newline at end of file 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