mirror of
https://github.com/janishutz/eth-summaries.git
synced 2025-11-25 10:34:23 +00:00
[NumCS] Remove imports from code listings
This commit is contained in:
Binary file not shown.
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user