Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes bug introduced by #3596 when handling NaNs. #3600

Merged

Conversation

pepbos
Copy link
Contributor

@pepbos pepbos commented Nov 7, 2023

My Pr #3596 introduced a bug, or triggered a bug elsewhere, when handling NaN's in SmoothSegmentedFunction.

Not sure when NaNs will be injected, and if that even makes sense, but before #3596 that was OK, but currently main will raise an exception. This PR makes it fine again, as was before #3596.

I noticed when trying to visualize my result from a CMC, which raised an exception now.


This change is Reviewable

ctrlPtsY[idx],
order);
// In case of NaN return zero.
return 0.;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think this might be hiding another issue? Is it possible that your CMC simulation/visualization is feeding this function a NaN value for x which then gets masked by returning zero here. Or do you think the changes introduced new NaNs somewhere?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, this was the previous behavior of the function. In that case, this is probably fine.

@pepbos
Copy link
Contributor Author

pepbos commented Nov 9, 2023

Looks like the intention was for the smoothSegmentedFunction to return NaN for a NaN as input (which makes sense).
However it had three different cases:

  • calcValue(NaN) returned NaN
  • calcDerivative(NaN, 1) returned dydx1
  • calcDerivative(NaN, 2) returned 0

Changed this PR to fix always returning NaN when the input is NaN, so:

  • calcValue(NaN) return NaN
  • calcDerivative(NaN, 1) return NaN
  • calcDerivative(NaN, 2) return NaN

Note that without this PR an exception is raised if the input is NaN, which blows up some cases that were fine before.
I added the NaN case to the unittests.

Copy link
Member

@nickbianco nickbianco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for the clarification @pepbos.

@nickbianco
Copy link
Member

Also, you can ignore the Mac failures, that is an issue with the CI. Working on a fix for that.

@pepbos pepbos merged commit 7703592 into opensim-org:main Nov 10, 2023
5 of 6 checks passed
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.

2 participants