Skip to content

Clamp similarity values between -1.0 and 1.0 to avoid NaNs from acos - #9

Open
zolastro wants to merge 1 commit into
sramshetty:mainfrom
zolastro:patch-1
Open

Clamp similarity values between -1.0 and 1.0 to avoid NaNs from acos#9
zolastro wants to merge 1 commit into
sramshetty:mainfrom
zolastro:patch-1

Conversation

@zolastro

@zolastro zolastro commented Oct 9, 2025

Copy link
Copy Markdown

This pull request makes a minor adjustment to the similarity calculation in the block_influence function to ensure numerical stability when using angular metrics.

  • Metrics calculation:
    • Added a torch.clamp operation to restrict the values of sim between -1.0 and 1.0 before applying the arccosine function in the angular metric computation. This prevents errors due to floating point inaccuracies.

I have noticed some NaNs while testing the function, mainly numbers slightly above 1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant