Skip to content

Add cho_factor and cho_solve to dpnp.scipy.linalg - #3116

Draft
antonwolfy wants to merge 7 commits into
masterfrom
cho-factor-cho-solve
Draft

antonwolfy wants to merge 7 commits into
masterfrom
cho-factor-cho-solve

Conversation

@antonwolfy

Copy link
Copy Markdown
Contributor

Implement SciPy-compatible dpnp.scipy.linalg.cho_factor and dpnp.scipy.linalg.cho_solve with batched input support (#3096).

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

Implement SciPy-compatible `dpnp.scipy.linalg.cho_factor` and
`dpnp.scipy.linalg.cho_solve` with batched input support (gh-3096).

- `cho_factor` uses the existing `potrf` / `potrf_batch` bindings. Only
  the referenced triangle is copied into a zeroed C-order buffer, which
  matches the SciPy 1.18 output in a single pass. The input is factorized
  in place for `overwrite_a=True` when it is 2-D, writable, of the result
  dtype, and C- or F-contiguous.
- `cho_solve` uses a new LAPACK `potrs` binding for 2-D input and a new
  BLAS `trsm_batch` binding (two triangular solves) for batched input,
  since oneMKL `potrs_batch` is much slower. Batch dimensions are
  broadcast as in `lu_solve`.
- Add tests and API reference entries.
A C-order factor is passed to oneMKL transposed, so the solves are with
conj(A), and `b` and the solution are conjugated to compensate. This is
only needed for a complex factor. Decide it from the dtype of `c` rather
than the result dtype, so a real factor with a complex right-hand side no
longer conjugates `b` and the solution.

Add a test for a real factor with complex right-hand sides.
Add `tests/cupyx_tests/linalg_tests/test_solve.py` from CuPy as
`dpnp/tests/third_party/cupyx/linalg_tests/test_solve.py`, with
`TestChosolve` adapted to `dpnp.scipy.linalg.cho_solve`:

- pass `check_finite=False`, since dpnp checks the whole factor for
  infs and NaNs, as SciPy does, and the tests put NaNs in the unused
  triangle;
- pass a batch of vectors with a trailing axis, since dpnp follows
  SciPy's `(..., n, k)` rule for a batched right-hand side.

The `invh` tests are skipped, as `invh` is not supported.
@antonwolfy antonwolfy added this to the 0.22.0 release milestone Oct 20, 2026
@antonwolfy antonwolfy self-assigned this Oct 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

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

@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

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

@coveralls

coveralls commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

Coverage Status

coverage: 82.5% (-0.1%) from 82.615% — cho-factor-cho-solve into master

- Add See Also link from dpnp.linalg.cholesky to dpnp.scipy.linalg.cho_factor
- Fix the upper-triangular example output in dpnp.linalg.cholesky
- Remove stale linalg.lu_factor and linalg.lu_solve entries from linalg.rst
- Look up the order manager in _copy_rhs and _cho_solve_trsm instead of passing it
- Do not broadcast a 2-D factor `c` over a batched right-hand side:
  fold the batch into the RHS columns for one `potrs` call, or, for a
  real type on GPU with a small batch (batch * nrhs > 16, batch <= 32),
  where oneMKL potrs slows down above 16 columns, share the factor by
  all batch elements in `trsm_batch`
- Let `_trsm_batch` take a 2-D triangular matrix shared by the batch
  (stride 0)
- Submit both `check_finite` reductions before waiting for the first
  result
- Accept the batch-shaped `lower` array returned by SciPy >= 1.18 in
  `cho_solve`, if all its values are equal

This branch has not been deployed

No deployments
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