Newer
Older
input_samples = [Constant(waveform[i]) for i in range(points)]
sim = Simulation(schedule.sfg, input_samples)
sim.run_for(128)
exp_res = np.fft.fft(waveform)
res = sim.results
for i in range(points):
a = res[str(i)][delays[i] :]
b = exp_res[i]
assert np.all(np.isclose(a, b))
Simon Bjurek
committed
def _validate_recreated_sfg_ldlt_matrix_inverse(
schedule: Schedule, N: int, delays: list[int] | None = None
) -> None:
if delays is None:
num_of_outputs = N * (N + 1) // 2
delays = [0 for i in range(num_of_outputs)]
Simon Bjurek
committed
# random real s.p.d matrix
A = np.random.default_rng().random((N, N))
Simon Bjurek
committed
A = np.dot(A, A.T)
# iterate through the upper diagonal and construct the input to the SFG
input_signals = []
for i in range(N):
for j in range(i, N):
input_signals.append(Constant(A[i, j]))
A_inv = np.linalg.inv(A)
sim = Simulation(schedule.sfg, input_signals)
sim.run_for(128)
Simon Bjurek
committed
# iterate through the upper diagonal and check
count = 0
for i in range(N):
for j in range(i, N):
assert np.all(
np.isclose(sim.results[str(count)][delays[count] :], A_inv[i, j])
)