Skip to content

Conversation

@jokasimr
Copy link
Contributor

@jokasimr jokasimr commented Aug 9, 2024

Fixes #3507

I think most of the cases in the issue are fine except:

sc.scalar(0.0, variance=0.0)**0.5
# and
sc.scalar(0.0, variance=1.0)**0.5

because in those cases the value of the result should just be 0.0 and not nan.

@jokasimr
Copy link
Contributor Author

jokasimr commented Aug 9, 2024

I wasn't able to locate where we test the values / variances of arithmetic operations.
Does anyone have a link to the file where it would be suitable to test this?

@SimonHeybrock
Copy link
Member

SimonHeybrock commented Aug 15, 2024

I wasn't able to locate where we test the values / variances of arithmetic operations. Does anyone have a link to the file where it would be suitable to test this?

These should generally all be here: https://github.com/scipp/scipp/blob/main/lib/core/test/value_and_variance_test.cpp. If there is more logic in the kernel than implemented in ValueAndVariance itself, see the files prefixed with element_ in https://github.com/scipp/scipp/tree/main/lib/core/test

Comment on lines 74 to 75
const auto pow_0 = (base.value == 0 && exponent >= 0 && exponent < 1)
? 0
Copy link
Member

Choose a reason for hiding this comment

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

  • Shouldn't 0**0 give 1?
  • Why do we need the exponent < 1, or the sign check? Isn't it just zero everywhere if the base is zero (except of the exponent also is)?

Copy link
Contributor Author

@jokasimr jokasimr Aug 15, 2024

Choose a reason for hiding this comment

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

  1. Good catch.
  2. Yeah that's probably right, it's unnecessary to check if exponent < 1. But we need to check the sign because if exponent is negative the result should be nan and not 0.

@jokasimr jokasimr force-pushed the fix-pow-variance-bug branch from 88fb96d to 46e7f56 Compare August 16, 2024 08:47
@jokasimr jokasimr merged commit 96da009 into main Aug 19, 2024
@jokasimr jokasimr deleted the fix-pow-variance-bug branch August 19, 2024 07:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

NaN result when applying non-integer power to scalar of 0 when variance is present

3 participants