# SPDX-FileCopyrightText: (c) 2026 Tenstorrent AI ULC # SPDX-License-Identifier: Apache-2.0 """PCC utilities — standalone replacements for tests.ttnn.utils_for_testing.""" import torch def comp_pcc(a: torch.Tensor, b: torch.Tensor, pcc_threshold: float = 0.99): """Compute Pearson correlation coefficient between two tensors. Returns: (bool, float): (passes_threshold, pcc_value) """ a = a.detach().double().flatten() b = b.detach().double().flatten() a = a - a.mean() b = b - b.mean() denom = (a.norm() * b.norm()).item() + 1e-12 pcc_val = float((a @ b).item() / denom) return pcc_val >= pcc_threshold, pcc_val def assert_with_pcc(a: torch.Tensor, b: torch.Tensor, pcc: float = 0.99): """Assert PCC between two tensors meets threshold.""" passes, pcc_val = comp_pcc(a, b, pcc) assert passes, f"PCC {pcc_val:.6f} < {pcc}" return passes, pcc_val