-
Notifications
You must be signed in to change notification settings - Fork 2
Take integer and index tensors from the configured int dtype #75
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
base: dev
Are you sure you want to change the base?
Changes from all commits
3662297
2422bba
560d3f9
b78a89d
c447afe
b4d6f91
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,7 @@ class through | |
|
|
||
| import torch | ||
|
|
||
| from torchref.config import canonical_device | ||
| from torchref.config import canonical_device, get_int_dtype | ||
| from torchref.utils.autograd_ops import gather_with_index_add | ||
| from torchref.utils.device_mixin import DeviceMixin | ||
|
|
||
|
|
@@ -45,13 +45,14 @@ def _equiv_hkls_to_flat_indices( | |
| Returns | ||
| ------- | ||
| torch.Tensor | ||
| Flat indices, shape ``(n_ops * N,)``, dtype ``int64``, wrapped modulo the grid. | ||
| Flat indices, shape ``(n_ops * N,)``, in the configured int dtype, wrapped | ||
| modulo the grid. | ||
| """ | ||
| all_hkl = equiv_hkls.reshape(-1, 3) | ||
| hi = torch.remainder(all_hkl[:, 0], Nx) | ||
| ki = torch.remainder(all_hkl[:, 1], Ny) | ||
| li = torch.remainder(all_hkl[:, 2], Nz) | ||
| return (hi * (Ny * Nz) + ki * Nz + li).to(torch.int64) # dtype-ok: flat HKL grid index; int64 avoids overflow, used for indexing | ||
| return (hi * (Ny * Nz) + ki * Nz + li).to(get_int_dtype()) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For a reciprocal grid containing more than AGENTS.md reference: AGENTS.md:L54-L59 Useful? React with 👍 / 👎. |
||
|
|
||
|
|
||
| class ReciprocalSymmetryExtractor(DeviceMixin): | ||
|
|
||
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.
When the default integer configuration is int32 and
Nx * Ny * Nzexceeds2**31 - 1, this packed grid-index expression overflows before the final.to(get_int_dtype());index_addthen receives negative or aliased indices, so large reciprocal grids either fail or place structure factors in the wrong voxels. Computelinandlin_symin int64, which is precisely the packed-key exception to the configured-dtype policy.AGENTS.md reference: AGENTS.md:L54-L59
Useful? React with 👍 / 👎.