Skip to content

Commit acde4fd

Browse files
committed
Changes 0 values to small values (avoid nan)
Signed-off-by: Flavia Beo <flavia.beo@ibm.com>
1 parent d2e3d98 commit acde4fd

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

aiu_fms_testing_utils/utils/metrics_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ def tensor_abs_diff(tensor1, tensor2):
4545
torch.tensor([3, 3, 3])
4646
"""
4747
abs_diff = torch.abs(tensor1 - tensor2)
48-
abs_diff[abs_diff == 0.0] = 1e-6
4948
return abs_diff
5049

5150
def tensor_cos_sim(tensor1, tensor2):
@@ -67,6 +66,7 @@ def tensor_cos_sim(tensor1, tensor2):
6766
>>> print(sim)
6867
"""
6968
cos = nn.CosineSimilarity(dim=-1)
69+
tensor1[tensor1 == 0.0] = 1e-6
70+
tensor2[tensor2 == 0.0] = 1e-6
7071
cos_sim = cos(tensor1, tensor2)
71-
cos_sim[cos_sim == 0.0] = 1e-6
7272
return cos_sim

0 commit comments

Comments
 (0)