diff --git a/semester3/numcs/numcs-summary.pdf b/semester3/numcs/numcs-summary.pdf index 2dc3d2c..28e796e 100644 Binary files a/semester3/numcs/numcs-summary.pdf and b/semester3/numcs/numcs-summary.pdf differ diff --git a/semester3/numcs/parts/00_introduction/02_matrix-multiplication.tex b/semester3/numcs/parts/00_introduction/02_matrix-multiplication.tex index 4a28269..b484382 100644 --- a/semester3/numcs/parts/00_introduction/02_matrix-multiplication.tex +++ b/semester3/numcs/parts/00_introduction/02_matrix-multiplication.tex @@ -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.