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

Filling tensor containing f32::NEG_INFINITY will result in NaN #2094

Closed
antimora opened this issue Aug 3, 2024 · 0 comments · Fixed by #2095
Closed

Filling tensor containing f32::NEG_INFINITY will result in NaN #2094

antimora opened this issue Aug 3, 2024 · 0 comments · Fixed by #2095

Comments

@antimora
Copy link
Collaborator

antimora commented Aug 3, 2024

Describe the bug
Filling tensor containing f32::NEG_INFINITY will result in NaN for burn-ndarray backend.

To Reproduce
This test will fail:

 #[test]
  fn float_mask_fill_infinit() {
      let device = Default::default();
      let tensor = Tensor::<TestBackend, 2>::from_data(
          [
              [f32::NEG_INFINITY, f32::NEG_INFINITY],
              [f32::NEG_INFINITY, f32::NEG_INFINITY],
          ],
          &device,
      );
      let mask = Tensor::<TestBackend, 2, Bool>::from_bool(
          TensorData::from([[true, false], [false, true]]),
          &device,
      );

      let output = tensor.mask_fill(mask, 10.0f32);
      let expected = TensorData::from([[10f32, f32::NEG_INFINITY], [f32::NEG_INFINITY, 10f32]]);

      output.into_data().assert_eq(&expected, false);
  }

Expected behavior
Shouldn't fail

Screenshots

Output:

Tensor { primitive: Float(NdArrayTensor { array: [[NaN, -inf],
 [-inf, NaN]], shape=[2, 2], strides=[2, 1], layout=Cc (0x5), dynamic ndim=2 }) }
thread 'tests::mask::tests::float_mask_fill_infinit' panicked at crates/burn-ndarray/src/lib.rs:41:5:
Tensors are not eq:
  => Position 0: NaN != 10
  => Position 3: NaN != 10
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
test tests::mask::tests::float_mask_fill_infinit ... FAILED

antimora added a commit to antimora/burn that referenced this issue Aug 3, 2024
laggui pushed a commit that referenced this issue Aug 5, 2024
…aN for burn-ndarray (#2095)

* Fix #2094 bug

* Fix typo

* Fix mask broadcasting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant