-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify_RDI.py
More file actions
54 lines (48 loc) · 2.26 KB
/
verify_RDI.py
File metadata and controls
54 lines (48 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import numpy as np
import os
RDI_TYPES = [
(os.path.join("dumps", "rdi_gen_frame"), "Generator Injected RDI (adc derived)"),
(os.path.join("dumps", "rdi_raw_frame"), "Raw FFT-based RDI (pre-pipeline)")
]
FRAME_INDICES = [0, 9, 19, 29, 39]
def compare_rdi_dumps():
all_match = True
for prefix, desc in RDI_TYPES:
print(f"\n--- Comparing {desc} ---")
for idx in FRAME_INDICES:
gen_file = f"{prefix}{idx}.npy"
con_file = f"{prefix}{idx}.npy"
if not os.path.exists(gen_file):
print(f"[ERROR] Missing file: {gen_file}")
all_match = False
continue
if not os.path.exists(con_file):
print(f"[ERROR] Missing file: {con_file}")
all_match = False
continue
gen_rdi = np.load(gen_file)
con_rdi = np.load(con_file)
# Print stats for generator and consumer RDI
print(f" [GEN] Frame {idx}: min={gen_rdi.min():.4f}, max={gen_rdi.max():.4f}, avg={gen_rdi.mean():.4f}, pow={np.mean(gen_rdi**2):.4f}")
print(f" [CON] Frame {idx}: min={con_rdi.min():.4f}, max={con_rdi.max():.4f}, avg={con_rdi.mean():.4f}, pow={np.mean(con_rdi**2):.4f}")
if gen_rdi.shape != con_rdi.shape:
print(f"[FAIL] Frame {idx}: Shape mismatch: generator {gen_rdi.shape}, consumer {con_rdi.shape}")
all_match = False
continue
diff = np.abs(gen_rdi - con_rdi)
max_diff = diff.max()
mean_diff = diff.mean()
if np.allclose(gen_rdi, con_rdi, atol=1e-3):
print(f"[OK] Frame {idx}: RDI match within tolerance.")
else:
num_diff = np.count_nonzero(diff > 1e-3)
print(f"[FAIL] Frame {idx}: RDI mismatch. Max abs diff: {max_diff:.4f}, mean abs diff: {mean_diff:.4f}, differing elements: {num_diff}/{gen_rdi.size}")
all_match = False
if all_match:
print("\nAll compared RDI frames match within tolerance!\n")
return 0
else:
print("\nSome RDI frames do not match. See details above.\n")
return 1
if __name__ == "__main__":
exit(compare_rdi_dumps())