Skip to content

dpnp.linalg.lu_factor() - Feature request. Implemeted but not a public method #2498

Closed

Description

@abagusetty

I was looking for a port of from cupyx.scipy.linalg import lu_factor, lu_solve for LU factorization & eq. solve via LU factorization

Apparently `lu_factor does exist luckily (thanks!) but not exposed since it is a private function: https://github.com/IntelPython/dpnp/blob/master/dpnp/linalg/dpnp_utils_linalg.py#L874

I would like to request a feature to expose this method and also implement a lu_solve feature possibly via getrs: Ref: https://github.com/cupy/cupy/blob/v13.4.1/cupyx/scipy/linalg/_decomp_lu.py#L259

Activity

  1. abagusetty commented on Jun 24, 2025

    @abagusetty
    ContributorAuthor

    With the following, the results differ between the L, U and pivots. This is sort of expected as it depends on the pivoting steps. If there is a way to support similar to scipy API (ie., the args): lu_factor(a, overwrite_a=False, check_finite=True)

    import dpnp as dp
    A = dp.array([[2, 5, 8, 7], [5, 2, 2, 8], [7, 5, 6, 6], [5, 4, 4, 8]], dtype=dp.float64)
    lu, piv, dev_info = dp.linalg.dpnp_utils_linalg._lu_factor(A, A.dtype)
    print("LU from dpnp:\n", lu)
    print("Pivots from dpnp:\n", piv)
    print("Dev info:\n", dev_info)
    
    
    import numpy as np
    from scipy.linalg import lu_factor
    Anp = np.array([[2, 5, 8, 7], [5, 2, 2, 8], [7, 5, 6, 6], [5, 4, 4, 8]])
    lu_np, piv_np = lu_factor(Anp)
    print("LU from scipy:\n", lu_np)
    print("Pivots from scipy:\n", piv_np)

    output:

    LU from dpnp:
     [[8.         0.875      0.25       0.625     ]
     [2.         6.25       0.72       0.12      ]
     [6.         0.75       4.96       0.23387097]
     [4.         4.5        0.76       0.78225806]]
    Pivots from dpnp:
     [3 4 3 4]
    Dev info:
     [0]
    LU from scipy:
     [[ 7.          5.          6.          6.        ]
     [ 0.28571429  3.57142857  6.28571429  5.28571429]
     [ 0.71428571  0.12       -1.04        3.08      ]
     [ 0.71428571 -0.44       -0.46153846  7.46153846]]
    Pivots from scipy:
     [2 2 3 3]
    
  2. vlad-perevezentsev commented on Jun 25, 2025

    @vlad-perevezentsev
    Contributor

    Hi @abagusetty and thank you for the feature request

    The function _lu_factor() was originally designed for internal use in dpnp.linalg.det() and dpnp.linalg.slogdet() so we did not make it public.
    To maintain functional completeness of DPNP with CuPy and SciPy where lu_factor is part of the public API, we plan to add dpnp.linalg.lu_factor as a public function in a future release including support for arguments like overwrite_a and check_finite

    Your request for lu_solve() makes sense as the next logical step and will be implemented in the same upcoming release.

    Regarding the differences in LU and pivot outputs. This is expected.
    LU factorization is not unique and results may vary depending on the pivoting strategy used by the underlying library

    I will keep this issue updated as soon as development begins.

  3. vlad-perevezentsev commented on Oct 14, 2025

    @vlad-perevezentsev
    Contributor

    @abagusetty
    The functions dpnp.scipy.linalg.lu_factor() #2557 , #2565 and dpnp.scipy.linalg.lu_solve() #2575 have been implemented and are now available in the latest release v.0.19.0
    Batch support for dpnp.scipy.linalg.lu_solve() #2619 has been merged and will be included in the next release.

    These functions are part of the new dpnp.scipy submodule #2603 and mimic the behavior of their SciPy equivalents including full support for all standard arguments and 0-based pivot indexing

    I am closing this issue.
    Feel free to open a new one for any further feature requests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

enhancementNew feature or request

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions