Repository navigation
Open
Description
Motivation
dpnp.linalg.cholesky computes the Cholesky factor on the device via oneMKL potrf, but dpnp currently offers no way to use that factor to solve a linear system: there is no cho_solve and no solve_triangular. dpnp.linalg.solve follows NumPy and always uses LU (getrf + getrs), so symmetric positive-definite (SPD) systems cannot take advantage of Cholesky.
This matters in particular:
- Cholesky needs about half the flops of LU (n³/3 vs 2n³/3) and no pivoting.
- According to the oneMKL DPC++ documentation,
getrfon GPU is hybrid ("some computations are performed on the CPU"), whilepotrf,potrsandtrtrsrun on the device. - Since SciPy 1.17,
scipy.linalg.solvewith the defaultassume_a=Nonetries Cholesky first for exactly symmetric/Hermitian input.
Proposal
Add SciPy-compatible functions to dpnp.scipy.linalg, with batched input support like the existing lu_factor/lu_solve:
-
cho_factor(a, lower=False, overwrite_a=False, check_finite=True)->(c, lower), based on oneMKLpotrf/potrf_batch. As in SciPy, the unused triangle ofcmay contain arbitrary data, so the extra pass that zeroes the other triangle indpnp.linalg.choleskyis not needed. -
cho_solve(c_and_lower, b, overwrite_b=False, check_finite=True), based on oneMKLpotrs/potrs_batch. -
solve_triangular(a, b, trans=0, lower=False, unit_diagonal=False, overwrite_b=False, check_finite=True), based on oneMKL LAPACKtrtrsor BLAStrsm/trsm_batch. -
solve(a, b, lower=False, overwrite_a=False, overwrite_b=False, check_finite=True, assume_a=None, transposed=False), dispatching onassume_a:'general'->getrf/getrs,'positive definite'->potrf/potrs,'lower triangular'/'upper triangular'->solve_triangular.
Implementation notes
potrf/potrf_batchbindings already exist (dpnp/backend/extensions/lapack/potrf.cpp,potrf_batch.cpp), including the mapping toLinAlgError("Matrix is not positive definite."), and can be reused bycho_factor.potrs/potrs_batchneed new bindings;getrs.cpp/getrs_batch.cppcan serve as templates.solve_triangular:trtrsreports exactly singular matrices viainfo(SciPy raisesLinAlgErrorin that case), whiletrsmhas a strided batch variant but does not check for singularity. The choice can be made during implementation.- Structure detection in
solve(..., assume_a=None)(symmetry check, then trypotrfand fall back to LU) is proposed as a follow-up. On GPU it adds an O(n²) check, a host synchronization to choose the path, and a wastedpotrfcall for symmetric matrices that are not positive definite, so its cost should be measured first. Until then,assume_a=Nonecan behave as'general', which gives the same results as SciPy. Structures not covered above ('sym','her','diagonal','tridiagonal','banded') can also fall back to'general'initially. - Add the new functions to
doc/reference/scipy_linalg.rst.
References
- SciPy:
cho_factor,cho_solve,solve_triangular,solve - oneMKL DPC++:
potrf,potrs,getrf
Metadata
Metadata
Assignees
Labels
No labels
Activity
david-cortes-intel commentedon Oct 14, 2026
ref scipy/scipy#24596
antonwolfy commentedon Oct 16, 2026
@david-cortes-intel thanks for the link.
Could you share how high a priority this is for you?
0.21.0 is close and its scope is already set, so we'd like to put this in the next release after it (0.22.0). Would that work for you?
If you only need part of it, which piece matters most? I think
cho_factor/cho_solvetogether withsolve(assume_a="positive definite")would be the most useful to deliver first, withsolve_triangularand the otherassume_aoptions coming afterwards. What do you think?david-cortes-intel commentedon Oct 16, 2026
It's not a high priority, but would be a useful thing for GPU users once other libraries start adopting it, particularly SciPy and scikit-learn. Would be nice to have it in 0.22.
Add `cho_factor` and `cho_solve` to `dpnp.scipy.linalg`
Add `cho_factor` and `cho_solve` to `dpnp.scipy.linalg`
Add `cho_factor` and `cho_solve` to `dpnp.scipy.linalg` (#3116)
Add `cho_factor` and `cho_solve` to `dpnp.scipy.linalg` (#3116)
antonwolfy commentedon Nov 16, 2026
cho_factorandcho_solveare now indpnp.scipy.linalg, merged in #3116 and planned for 0.22.0. Both support batched input as in SciPy 1.18. The differences from SciPy are listed in the docstrings and in the PR description.