Skip to content
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

Fixed factorial bug with torch tensors in rsh.py #2

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 10 additions & 4 deletions torch_gauge/o3/rsh.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@
import torch
from joblib import Memory
from scipy.special import binom, factorial

from torch_gauge import ROOT_DIR
from torch_gauge.o3.spherical import SphericalTensor

memory = Memory(os.path.join(ROOT_DIR, ".o3_cache"), verbose=0)

def torch_factorial(x):
if x.dim() == 0:
x = x.unsqueeze(-1)
out = factorial(x)
return torch.from_numpy(out).squeeze()
out = factorial(x)
return torch.from_numpy(out)

def vm(m):
return (1 / 2) * (m < 0).long()
Expand All @@ -39,10 +45,10 @@ def get_c_lmtuv(l, m, t, u, v):

@memory.cache
def get_ns_lm(l, m):
return (1 / (2 ** torch.abs(m) * factorial(l))) * torch.sqrt(
return (1 / (2 ** torch.abs(m) * torch_factorial(l))) * torch.sqrt(
2
* factorial(l + torch.abs(m))
* factorial(l - torch.abs(m))
* torch_factorial(l + torch.abs(m))
* torch_factorial(l - torch.abs(m))
/ (2 ** (m == 0).long())
)

Expand Down
2 changes: 1 addition & 1 deletion torch_gauge/o3/spherical.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ def invariant(self, mode="l2") -> torch.Tensor:
invariant2d = NormContraction2d.apply(
self.ten, idx_tens, norm_shape, self.rep_dims, self._norm_eps
)
if mode == "uest":
elif mode == "uest":
invariant2d = NormContraction2d.apply(
self.ten, idx_tens, norm_shape, self.rep_dims, 1.0
)
Expand Down