Skip to content
This repository has been archived by the owner on May 31, 2024. It is now read-only.

Commit

Permalink
Merge pull request #332 from PTB-M4D/fix_issue_331
Browse files Browse the repository at this point in the history
Add comparison against known example for Hadamar product
  • Loading branch information
BjoernLudwigPTB committed May 14, 2024
2 parents b9debd7 + fe783f9 commit c69dbc6
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions test/test_propagate_multiplication.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,56 @@ def test_hadamar_common_call(inputs):
assert hadamar_product(*input_1, *input_2)


def test_hadamar_known_result():
# test against a result calculated by hand (on paper)

x1 = np.array([1, 2, 3, 4], dtype=np.double)
U1 = scl.toeplitz(np.flip(x1))
x2 = x1 + 4
U2 = U1 - 2

r_known = np.array([-16, -20, 22, 40], dtype=np.double)
Ur_known = np.array(
[
[176, 104, -48, -160],
[104, 248, 56, -56],
[-48, 56, 456, 432],
[-160, -56, 432, 632],
],
dtype=np.double,
)

r, Ur = hadamar_product(x1=x1, U1=U1, x2=x2, U2=U2)
# check common execution of convolve_unc
assert_allclose(r, r_known)
assert_allclose(Ur, Ur_known)


def test_hadamar_known_result_real():
# test against a result calculated by hand (on paper)

x1 = np.array([1, 2, 3, 4], dtype=np.double)
U1 = scl.toeplitz(np.flip(x1))
x2 = x1 + 4
U2 = U1 - 2

r_known = np.array([5, 12, 21, 32], dtype=np.double)
Ur_known = np.array(
[
[102, 92, 70, 36],
[92, 152, 132, 96],
[70, 132, 214, 180],
[36, 96, 180, 288],
],
dtype=np.double,
)

r, Ur = hadamar_product(x1=x1, U1=U1, x2=x2, U2=U2, real_valued=True)
# check common execution of convolve_unc
assert_allclose(r, r_known)
assert_allclose(Ur, Ur_known)


@given(complex_x_and_Ux_and_real_window(reduced_set=True))
def test_window_application(inputs):
x, Ux = inputs[0]
Expand Down

0 comments on commit c69dbc6

Please sign in to comment.