Skip to content

Add scipy.linalg.lu() decomposition support#2787

Open
abagusetty wants to merge 24 commits intoIntelPython:masterfrom
abagusetty:linalg_lu
Open

Add scipy.linalg.lu() decomposition support#2787
abagusetty wants to merge 24 commits intoIntelPython:masterfrom
abagusetty:linalg_lu

Conversation

@abagusetty
Copy link

This PR adds dpnp.scipy.linalg.lu() with support for all three output modes: default (P, L, U), permute_l=True (PL, U), and p_indices=True (p, L, U), including batched inputs.

Fixes: #2786

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

@intel-python-devops
Copy link

Can one of the admins verify this patch?

@antonwolfy antonwolfy added this to the 0.20.0 release milestone Mar 2, 2026
Copy link
Contributor

@antonwolfy antonwolfy left a comment

Choose a reason for hiding this comment

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

@abagusetty, thank you for the contribution. I posted few comments below

abagusetty and others added 4 commits March 2, 2026 09:18
Co-authored-by: Anton <100830759+antonwolfy@users.noreply.github.com>
Co-authored-by: Anton <100830759+antonwolfy@users.noreply.github.com>
@abagusetty
Copy link
Author

@antonwolfy Thanks for taking time. All the suggestions were addressed. Please let me know

@coveralls
Copy link
Collaborator

coveralls commented Mar 3, 2026

Coverage Status

coverage: 81.163% (+0.04%) from 81.124%
when pulling aa00062 on abagusetty:linalg_lu
into 7803d3a on IntelPython:master.

Comment on lines +2976 to +2983
A_cast = a_dp.astype(
(
dpnp.complex128
if dpnp.issubdtype(dtype, dpnp.complexfloating)
else dpnp.float64
),
copy=False,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

A_cast seems never used

Suggested change
A_cast = a_dp.astype(
(
dpnp.complex128
if dpnp.issubdtype(dtype, dpnp.complexfloating)
else dpnp.float64
),
copy=False,
)

U_np = dpnp.asnumpy(U)
A_rec = L_np[p_np] @ U_np
A_cast = a_dp.astype(L.dtype, copy=False)
assert_allclose(A_rec, dpnp.asnumpy(A_cast), rtol=1e-6, atol=1e-6)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need to cast to numpy array? Can we use the assert like in above tests?

Suggested change
assert_allclose(A_rec, dpnp.asnumpy(A_cast), rtol=1e-6, atol=1e-6)
assert dpnp.allclose(A_rec, A_cast, rtol=1e-6, atol=1e-6)

if m == 1 and n == 1:
if check_finite:
if not dpnp.isfinite(a).all():
raise ValueError("array must not contain infs or NaNs")
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems there is no test covering that. Could you please add it?

abagusetty and others added 6 commits March 3, 2026 09:46
Co-authored-by: Anton <100830759+antonwolfy@users.noreply.github.com>
Co-authored-by: Anton <100830759+antonwolfy@users.noreply.github.com>
Co-authored-by: Anton <100830759+antonwolfy@users.noreply.github.com>
Co-authored-by: Anton <100830759+antonwolfy@users.noreply.github.com>
Co-authored-by: Anton <100830759+antonwolfy@users.noreply.github.com>
Co-authored-by: Anton <100830759+antonwolfy@users.noreply.github.com>
abagusetty and others added 3 commits March 3, 2026 09:47
Co-authored-by: Anton <100830759+antonwolfy@users.noreply.github.com>
Co-authored-by: Anton <100830759+antonwolfy@users.noreply.github.com>
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.

dpnp.scipy.linalg.lu missing although lu_factor / lu_solve are implemented

4 participants