Skip to content

Fix dpnp.linspace returning NaN for equal infinite endpoints - #3043

Open
antonwolfy wants to merge 1 commit into
masterfrom
fix-linspace-inf-endpoints
Open

Fix dpnp.linspace returning NaN for equal infinite endpoints#3043
antonwolfy wants to merge 1 commit into
masterfrom
fix-linspace-inf-endpoints

Conversation

@antonwolfy

@antonwolfy antonwolfy commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

dpnp.linspace returned NaN instead of the endpoint value when start and stop are equal and infinite — e.g. dpnp.linspace(inf, inf, 4) gave [nan inf inf nan].

The bug had two independent sources:

  • The array path in dpnp_linspace computed delta = stop - start, so inf - inf = NaN propagated through the whole result.
  • The scalar path delegates to dpnp.tensor.linspace, whose affine kernel LinearSequenceAffineFunctor evaluates start * w + stop * wc; at the endpoints one weight is 0, and inf * 0 = NaN.

The PR proposes to fix all the places.

Note, the tests compare against NumPy on versions that include the fix (NumPy >= 2.6.0) and fall back to explicit expected values on older NumPy.

  • Have you provided a meaningful PR description?
  • Have you added a test, reproducer or referred to an issue with a reproducer?
  • Have you tested your changes locally for CPU and GPU devices?
  • Have you made sure that new changes do not introduce compiler warnings?
  • Have you checked performance impact of proposed changes?
  • Have you added documentation for your changes, if necessary?
  • Have you added your changes to the changelog?

Backport numpy#31620: equal endpoints must produce a zero step instead
of evaluating inf - inf (or inf * 0), which yields NaN.

- dpnp_linspace: fill directly for equal scalar endpoints and zero the
  delta where array endpoints coincide
- LinearSequenceAffineFunctor: short-circuit to a constant sequence when
  start == stop, fixing dpnp.tensor.linspace at its root
@antonwolfy antonwolfy added this to the 0.21.0 release milestone Aug 26, 2026
@antonwolfy antonwolfy self-assigned this Aug 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Array API standard conformance tests for dpnp=0.21.0dev6=py314ha0e2e8e_18 ran successfully.
Passed: 1375
Failed: 0
Skipped: 7

@github-actions

Copy link
Copy Markdown
Contributor

View rendered docs @ https://intelpython.github.io/dpnp/pull/3043/index.html

@coveralls

Copy link
Copy Markdown
Collaborator

Coverage Status

coverage: 78.482% (-0.001%) from 78.483% — fix-linspace-inf-endpoints into master

@antonwolfy
antonwolfy marked this pull request as ready for review August 26, 2026 19:48
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