Replace deprecated libtorch APIs with torch::linalg equivalents#1528
Replace deprecated libtorch APIs with torch::linalg equivalents#1528alinpahontu2912 wants to merge 3 commits intodotnet:mainfrom
Conversation
alinpahontu2912
commented
Feb 13, 2026
- THSTensor_cholesky: Replace tensor->cholesky(upper) with torch::linalg_cholesky, using .mH() for upper-triangular results
- THSTensor_lu_solve: Replace tensor->lu_solve() with torch::linalg_lu_solve
- Fix THSLinalg_lu_solve naming bug (was incorrectly named THSTensor_lu_solve)
- Add [Obsolete] attributes to C# wrappers for cholesky() and lu_solve()
- Update tests to use linalg.lu_solve instead of deprecated lu_solve
There was a problem hiding this comment.
Pull request overview
This pull request modernizes the TorchSharp codebase by replacing deprecated libtorch APIs with their torch::linalg equivalents. The changes ensure compatibility with future versions of PyTorch while maintaining backward compatibility through obsolete warnings.
Changes:
- Replace deprecated
tensor->cholesky()andtensor->lu_solve()withtorch::linalg_choleskyandtorch::linalg_lu_solve - Fix function naming bug where THSLinalg_lu_solve was incorrectly named THSTensor_lu_solve (duplicate name)
- Mark deprecated C# wrapper methods with [Obsolete] attributes to guide users toward modern alternatives
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/Native/LibTorchSharp/THSLinearAlgebra.cpp | Updated C++ implementations to use torch::linalg APIs; fixed THSLinalg_lu_solve function name; implemented upper triangular cholesky using .mH() |
| src/TorchSharp/Tensor/torch.cs | Added Obsolete attribute to torch.cholesky overload with pragma directives |
| src/TorchSharp/Tensor/torch.BlasAndLapackOperations.cs | Added Obsolete attributes to torch.cholesky and torch.lu_solve methods |
| src/TorchSharp/Tensor/Tensor.LinearAlgebra.cs | Added Obsolete attribute to Tensor.cholesky method |
| test/TorchSharpTest/LinearAlgebra.cs | Updated tests to use linalg.lu_solve with correct parameter order (LU, pivots, b) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
fd4c019 to
ea04581
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- THSTensor_cholesky: Replace tensor->cholesky(upper) with torch::linalg_cholesky, using .mH() for upper-triangular results - THSTensor_lu_solve: Replace tensor->lu_solve() with torch::linalg_lu_solve - Fix THSLinalg_lu_solve naming bug (was incorrectly named THSTensor_lu_solve) - Add [Obsolete] attributes to C# wrappers for cholesky() and lu_solve() - Update tests to use linalg.lu_solve instead of deprecated lu_solve
- Reword THSTensor_cholesky comment to clarify we use the default lower-triangular form and conjugate-transpose for upper=true - Add CholeskyUpperTest to validate upper=true path after migration from deprecated torch::cholesky to torch::linalg_cholesky Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1192657 to
5768b9f
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>