[NumCS] Remove imports from code listings

This commit is contained in:
2025-10-06 15:14:24 +02:00
parent 5634009e6b
commit 788704de45
2 changed files with 6 additions and 10 deletions

View File

@@ -64,8 +64,6 @@ Da die Matrix $R$ eine obere Dreiecksmatrix ist, ist das Ergebnis die Teilsummen
Das \verb|[::-1]| dient hier lediglich dazu, den Vektor $x$ umzudrehen, sodass das richtige Resultat entsteht.
Die vollständige Implementation sieht so aus:
\begin{code}{python}
import numpy as np
def low_rank_matrix_vector_product(A: np.ndarray, B: np.ndarray, x: np.ndarray):
n, _ = A.shape
y = np.zeros(n)
@@ -97,14 +95,12 @@ Die vollständige Implementation sieht so aus:
Die vollständige Implementation ist auch hier nicht schwer und sieht folgendermassen aus:
\begin{code}{python}
import numpy as np
def fast_kron_vector_product(A: np.ndarray, B: np.ndarray, x: np.ndarray):
# First multiply Bx_i, (and define x_i as a reshaped numpy array to save cost (as that will create a valid array))
# This will actually crash if x.shape[0] is not divisible by A.shape[0]
bx = B * x.reshape(A.shape[0], round(x.shape[0] / A.shape[0]))
# Then multiply a with the resulting vector
y = A @ bx
def fast_kron_vector_product(A: np.ndarray, B: np.ndarray, x: np.ndarray):
# First multiply Bx_i, (and define x_i as a reshaped numpy array to save cost (as that will create a valid array))
# This will actually crash if x.shape[0] is not divisible by A.shape[0]
bx = B * x.reshape(A.shape[0], round(x.shape[0] / A.shape[0]))
# Then multiply a with the resulting vector
y = A @ bx
\end{code}
Um die oben erwähnte Laufzeit zu erreichen muss erst ein neuer Vektor berechnet werden, oben im Code \verb|bx| genannt, der eine Multiplikation von \verb|Bx_i| als Einträge hat.