Skip to content

Replace deprecated libtorch APIs with torch::linalg equivalents#1528

Open
alinpahontu2912 wants to merge 2 commits intodotnet:mainfrom
alinpahontu2912:fix_deprecated
Open

Replace deprecated libtorch APIs with torch::linalg equivalents#1528
alinpahontu2912 wants to merge 2 commits intodotnet:mainfrom
alinpahontu2912:fix_deprecated

Conversation

@alinpahontu2912
Copy link
Member

  • 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

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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() and tensor->lu_solve() with torch::linalg_cholesky and torch::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.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

alinpahontu2912 and others added 2 commits February 27, 2026 10:19
- 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>
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