Skip to content
This repository was archived by the owner on Feb 6, 2026. It is now read-only.

Commit 8890c75

Browse files
committed
TST: Add matlab orthogonalization comparison
1 parent 3856e52 commit 8890c75

4 files changed

Lines changed: 65 additions & 0 deletions

File tree

tests/matlab/ortho-in.mat

42.2 KB
Binary file not shown.

tests/matlab/ortho-out.mat

42.8 KB
Binary file not shown.

tests/matlab/ortho_test.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import core.*
2+
3+
pd = makedist('Normal');
4+
5+
x0 = cast(random(pd, [32, 32, 5]) + 1i * random(pd, [32, 32, 5]), 'single');
6+
7+
[x1, I_n, eval] = probe_modes_ortho(x0);
8+
9+
save('ortho-in.mat', 'x0', '-v7.3');
10+
11+
save('ortho-out.mat', 'I_n', 'eval', 'x1', '-v7.3');

tests/matlab/ortho_test.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import os
2+
3+
import cupy as cp
4+
import h5py
5+
import matplotlib.pyplot as plt
6+
import numpy as np
7+
import tike.ptycho.probe
8+
import tike.view
9+
10+
11+
_dir = os.path.dirname(__file__)
12+
13+
def test_ortho():
14+
15+
with (
16+
h5py.File(os.path.join(_dir, 'ortho-in.mat'), 'r') as input,
17+
h5py.File(os.path.join(_dir, 'ortho-out.mat'), 'r') as output,
18+
):
19+
print(input.keys())
20+
print(output.keys())
21+
x0 = input['x0'][...].view('complex64')
22+
final0 = output['x1'][...].view('complex64')
23+
24+
assert x0.shape == (5, 32, 32)
25+
assert final0.shape == (5, 32, 32)
26+
27+
final1 = cp.asnumpy(tike.ptycho.probe.orthogonalize_eig(cp.asarray(x0)))
28+
29+
for i in range(len(final0)):
30+
31+
plt.figure()
32+
tike.view.plot_complex(final0[i] - final1[i])
33+
plt.suptitle('error')
34+
35+
plt.figure()
36+
tike.view.plot_complex(final0[i] + final1[i])
37+
plt.suptitle('error opposite')
38+
39+
plt.figure()
40+
tike.view.plot_complex(final0[i])
41+
plt.suptitle('original')
42+
43+
plt.figure()
44+
tike.view.plot_complex(final1[i])
45+
plt.suptitle('tike')
46+
47+
# Each mode is either the same or opposite magnitude (which is
48+
# equivalent orthogonalization)
49+
assert (
50+
np.allclose(final0[i], final1[i], atol=1e-4)
51+
or np.allclose(final0[i], -final1[i], atol=1e-4)
52+
)
53+
54+
# plt.show()

0 commit comments

Comments
 (0)