Skip to content

Support 'nuc' norm in dpnp.linalg.cond - #3084

Merged
antonwolfy merged 4 commits into
masterfrom
support-nuc-in-cond
Oct 6, 2026
Merged

antonwolfy merged 4 commits into
masterfrom
support-nuc-in-cond

Conversation

@antonwolfy

Copy link
Copy Markdown
Contributor

This PR adds the nuclear norm ("nuc") to the set of norms accepted by dpnp.linalg.cond, aligning its supported p values with dpnp.linalg.norm and with NumPy.

For "nuc" the condition number is computed through the existing inverse-based branch as norm(x, "nuc") * norm(inv(x), "nuc"), i.e. the product of the sums of the singular values of x and inv(x). This path was already functional (dpnp.linalg.norm supports "nuc" for matrices), so no change to the computation itself is required — the result matches NumPy for non-singular, batched, complex, boolean, empty, and strided inputs.

Consistent with the other inverse-based norms (1, -1, inf, -inf, "fro"), dpnp.linalg.cond raises LinAlgError on singular input when p="nuc", because dpnp.linalg.inv raises on singular matrices rather than filling the result with inf the way NumPy does.

  • 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?

Add the nuclear norm ('nuc') to the set of norms accepted by
dpnp.linalg.cond. The condition number for 'nuc' is already computed
correctly through the inverse-based branch (norm(x, 'nuc') *
norm(inv(x), 'nuc')); this change documents it as a supported value of
p and adds test coverage.

Unlike NumPy, dpnp.linalg.inv raises LinAlgError on singular input, so
cond with 'nuc' raises on singular matrices consistently with the other
inverse-based norms (1, -1, inf, -inf, 'fro'); no special NaN handling
is required.

Update the docstring (parameter set, norm table, Notes, example), add
'nuc' to the TestCond norm list and to the cond sycl-queue/usm-type
propagation tests, and add a CHANGELOG entry.
@antonwolfy antonwolfy added this to the 0.21.0 release milestone Oct 2, 2026
@antonwolfy antonwolfy self-assigned this Oct 2, 2026
@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

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

@coveralls

coveralls commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

Coverage Status

No base build to compare — support-nuc-in-cond into master

@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Array API standard conformance tests for dpnp=0.21.0dev12=np2py314h8d9cdd5_6 ran successfully.
Passed: 1376
Failed: 0
Skipped: 6

@ndgrigorian ndgrigorian left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Seems straight-forward, didn't see any issues when I ran some local tests, LGTM

@antonwolfy
antonwolfy merged commit 5bc6cb5 into master Oct 6, 2026
129 of 145 checks passed
@antonwolfy
antonwolfy deleted the support-nuc-in-cond branch October 6, 2026 09:25
github-actions Bot added a commit that referenced this pull request Oct 6, 2026
This PR adds the nuclear norm (`"nuc"`) to the set of norms accepted by
`dpnp.linalg.cond`, aligning its supported `p` values with
`dpnp.linalg.norm` and with NumPy.

For `"nuc"` the condition number is computed through the existing
inverse-based branch as `norm(x, "nuc") * norm(inv(x), "nuc")`, i.e. the
product of the sums of the singular values of `x` and `inv(x)`. This
path was already functional (`dpnp.linalg.norm` supports `"nuc"` for
matrices), so no change to the computation itself is required — the
result matches NumPy for non-singular, batched, complex, boolean, empty,
and strided inputs.

Consistent with the other inverse-based norms (`1`, `-1`, `inf`, `-inf`,
`"fro"`), `dpnp.linalg.cond` raises `LinAlgError` on singular input when
`p="nuc"`, because `dpnp.linalg.inv` raises on singular matrices rather
than filling the result with `inf` the way NumPy does. 5bc6cb5
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.

3 participants