Skip to content

Instantly share code, notes, and snippets.

@pashu123
Created April 23, 2025 23:41
Show Gist options
  • Select an option

  • Save pashu123/8db65894a7b0c695052801b5d931cc89 to your computer and use it in GitHub Desktop.

Select an option

Save pashu123/8db65894a7b0c695052801b5d931cc89 to your computer and use it in GitHub Desktop.
import numpy as np
# Load arrays with FP16 data type
old = np.load('old.npy').astype(np.float16)
new = np.load('new.npy').astype(np.float16)
print(old.shape)
print(new.shape)
# Check shape compatibility
if old.shape != new.shape:
raise ValueError("Arrays have different shapes")
# Set comparison parameters
atol = 1e-3 # Absolute tolerance
rtol = 1e-5 # Relative tolerance
# Find positions where values differ beyond tolerance thresholds
diff_mask = ~np.isclose(old, new, atol=atol, rtol=rtol)
differ_indices = np.argwhere(diff_mask)
print(f"Found {len(differ_indices)} differing elements:")
for idx in differ_indices[:100]:
idx_tuple = tuple(idx)
old_val = old[idx_tuple]
new_val = new[idx_tuple]
print(f"\nIndex: {idx_tuple}")
print(f"Old: {old_val:.4f} | New: {new_val:.4f}")
print(f"Absolute difference: {abs(old_val - new_val):.4e}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment