-
Notifications
You must be signed in to change notification settings - Fork 15
Add SparseLatticedTensor #484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ValerianRey
wants to merge
44
commits into
dev-new-engine
Choose a base branch
from
squashed-sst
base: dev-new-engine
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
95f9490
Add StructuredSparseTensor
PierreQuinton 1c86b79
Fix some Mypy errors.
PierreQuinton 76bb476
Add `solve_int`
PierreQuinton 96c54e4
Make linalg protected
ValerianRey 3a8e684
Add intdiv_c and mod_c
ValerianRey ba6e65f
Remove mod_c and div_c
PierreQuinton f00377a
Add HNF decomposition, LCM and GCD.
PierreQuinton 4f19317
Improve GCD for tall stride matrices.
PierreQuinton 4dbce6d
Revamp `compute_gcd`
PierreQuinton 35522f7
Remove mod_c and intdiv_c tests
ValerianRey 131fbb4
Rename SST to SparseLatticedTensor
ValerianRey 63549ca
Rename stride to basis
ValerianRey 2e641c7
Rename SST to SLT
ValerianRey 3e9e7d4
Fix usage of `unsqueeze` on SLT to call `unsqueeze_default` instead
PierreQuinton c6b19c7
Make `hnf_decomposition` return the reduced HNF rather than the HNF.
PierreQuinton 80ffb14
Improve `hnf_decomposition` and add a test for it (failing)
PierreQuinton ba9bf21
Reduce range of basis values to make the test pass.
PierreQuinton 20db2c0
Test additional properties of H.
PierreQuinton 361a5f7
Add implementation explanation in `computer_gcd`
PierreQuinton f9c2cff
Add the `reduced` parameter to `hnf_decomposition`
PierreQuinton 45d044d
Improve documentation of `compute_gcd`
PierreQuinton 9c2d6e7
Add `get_hermit_factor_rank`
PierreQuinton 73347c5
Test `reduced=False` in `hnf_decomposition`
PierreQuinton 997acf7
Improve (or is it fix?) implementation of `compute_lcm` as well as im…
PierreQuinton 8e17a77
Remove strides_v2
ValerianRey c4f7dfc
Add docstring to fix_dim_of_size_1 and fix_ungrouped_dims
ValerianRey 731de15
Remove unsquash_pdim
ValerianRey db57111
Remove debug_info
ValerianRey 5821346
Merge branch 'dev-new-engine' into squashed-sst
ValerianRey 29c4448
WIP add offset and shape (still need to update tests, view, einsum fu…
ValerianRey 112931f
Add default dim=0 in cat_default
ValerianRey 840d035
Fix concat for cases where it has to densify
ValerianRey 298daab
Fix test_hnf_decomposition
ValerianRey 7fd6766
Fix comment about lower triangular check and improve code
ValerianRey c65069c
Remove check that pivots are positive (they aren't)
ValerianRey e3b687b
Add test_compute_lcm
ValerianRey 153e3f8
Fix compute_lcm (no idea what i'm doing but it seems to work)
ValerianRey 799c88f
Merge branch 'squashed-sst' into add-offset-and-shape
ValerianRey 6ada564
Finish switching to offset and shape
ValerianRey 5956d82
Rename padding to margin
ValerianRey ac7e7c1
Use margin instead of offset and shape in SLT constructor
ValerianRey 35270e4
Remove solve_int
PierreQuinton ea897c9
Fix remaining mypy errors
ValerianRey 5671500
Reorder lines in src/torchjd/sparse/_linalg.py
ValerianRey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.