Skip to content
Open
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
95f9490
Add StructuredSparseTensor
PierreQuinton Oct 20, 2025
1c86b79
Fix some Mypy errors.
PierreQuinton Nov 17, 2025
76bb476
Add `solve_int`
PierreQuinton Nov 19, 2025
96c54e4
Make linalg protected
ValerianRey Nov 19, 2025
3a8e684
Add intdiv_c and mod_c
ValerianRey Nov 19, 2025
ba6e65f
Remove mod_c and div_c
PierreQuinton Nov 21, 2025
f00377a
Add HNF decomposition, LCM and GCD.
PierreQuinton Nov 21, 2025
4f19317
Improve GCD for tall stride matrices.
PierreQuinton Nov 21, 2025
4dbce6d
Revamp `compute_gcd`
PierreQuinton Nov 21, 2025
35522f7
Remove mod_c and intdiv_c tests
ValerianRey Nov 22, 2025
131fbb4
Rename SST to SparseLatticedTensor
ValerianRey Nov 22, 2025
63549ca
Rename stride to basis
ValerianRey Nov 22, 2025
2e641c7
Rename SST to SLT
ValerianRey Nov 22, 2025
3e9e7d4
Fix usage of `unsqueeze` on SLT to call `unsqueeze_default` instead
PierreQuinton Nov 23, 2025
c6b19c7
Make `hnf_decomposition` return the reduced HNF rather than the HNF.
PierreQuinton Nov 23, 2025
80ffb14
Improve `hnf_decomposition` and add a test for it (failing)
PierreQuinton Nov 23, 2025
ba9bf21
Reduce range of basis values to make the test pass.
PierreQuinton Nov 24, 2025
20db2c0
Test additional properties of H.
PierreQuinton Nov 24, 2025
361a5f7
Add implementation explanation in `computer_gcd`
PierreQuinton Nov 24, 2025
f9c2cff
Add the `reduced` parameter to `hnf_decomposition`
PierreQuinton Nov 24, 2025
45d044d
Improve documentation of `compute_gcd`
PierreQuinton Nov 24, 2025
9c2d6e7
Add `get_hermit_factor_rank`
PierreQuinton Nov 24, 2025
73347c5
Test `reduced=False` in `hnf_decomposition`
PierreQuinton Nov 24, 2025
997acf7
Improve (or is it fix?) implementation of `compute_lcm` as well as im…
PierreQuinton Nov 24, 2025
8e17a77
Remove strides_v2
ValerianRey Nov 24, 2025
c4f7dfc
Add docstring to fix_dim_of_size_1 and fix_ungrouped_dims
ValerianRey Nov 24, 2025
731de15
Remove unsquash_pdim
ValerianRey Nov 24, 2025
db57111
Remove debug_info
ValerianRey Nov 24, 2025
5821346
Merge branch 'dev-new-engine' into squashed-sst
ValerianRey Nov 25, 2025
29c4448
WIP add offset and shape (still need to update tests, view, einsum fu…
ValerianRey Nov 25, 2025
112931f
Add default dim=0 in cat_default
ValerianRey Nov 25, 2025
840d035
Fix concat for cases where it has to densify
ValerianRey Nov 25, 2025
298daab
Fix test_hnf_decomposition
ValerianRey Nov 26, 2025
7fd6766
Fix comment about lower triangular check and improve code
ValerianRey Nov 26, 2025
c65069c
Remove check that pivots are positive (they aren't)
ValerianRey Nov 26, 2025
e3b687b
Add test_compute_lcm
ValerianRey Nov 26, 2025
153e3f8
Fix compute_lcm (no idea what i'm doing but it seems to work)
ValerianRey Nov 26, 2025
799c88f
Merge branch 'squashed-sst' into add-offset-and-shape
ValerianRey Nov 26, 2025
6ada564
Finish switching to offset and shape
ValerianRey Dec 3, 2025
5956d82
Rename padding to margin
ValerianRey Dec 3, 2025
ac7e7c1
Use margin instead of offset and shape in SLT constructor
ValerianRey Dec 3, 2025
35270e4
Remove solve_int
PierreQuinton Dec 5, 2025
ea897c9
Fix remaining mypy errors
ValerianRey Dec 12, 2025
5671500
Reorder lines in src/torchjd/sparse/_linalg.py
ValerianRey Dec 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/torchjd/sparse/linalg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import torch
from torch import Tensor


def solve_int(A: Tensor, B: Tensor, tol=1e-9) -> Tensor | None:
"""
Solve A X = B where A, B and X have integer dtype.
Return X if such a matrix exists and otherwise None.
"""

A_ = A.to(torch.float64)
B_ = B.to(torch.float64)

try:
X = torch.linalg.solve(A_, B_)
except RuntimeError:
return None

X_rounded = X.round()
if not torch.all(torch.isclose(X, X_rounded, atol=tol)):
return None

# TODO: Verify that the round operation cannot fail
return X_rounded.to(torch.int64)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In the short term this seems good enough, but in the long term I think we'd want to either use another library to solve integer linear equations (SymPy, maybe others) or to implement our own solver in torch.

The reason is that computations with floating point numbers may be wrong with large stride values, and it's probably faster to solve something with the extra knowledge that it's integer.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We'll probably end up coding that in C.

Loading