Skip to content

Commit 5188462

Browse files
committed
Fix HRR inverse implementation
1 parent 890a502 commit 5188462

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

torchhd/tensors/hrr.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ def multibind(self) -> "HRRTensor":
253253

254254
def exact_inverse(self) -> "HRRTensor":
255255
"""Unstable, but exact, inverse"""
256-
result = ifft(1.0 / torch.conj(fft(self)))
256+
result = ifft(torch.reciprocal(fft(self)))
257257
result = torch.real(result)
258258
return torch.nan_to_num(result)
259259

@@ -281,7 +281,9 @@ def inverse(self) -> "HRRTensor":
281281
HRR([[ 0.0090, -0.1744, -0.2351, 0.0441, 0.0836, 0.2620]], dtype=torch.float64)
282282
283283
"""
284-
result = ifft(torch.conj(fft(self)))
284+
# the following two are equivalent, the last one is more efficient.
285+
# result = ifft(torch.conj(fft(self)))
286+
result = torch.roll(torch.flip(self, dims=[-1]), 1, dims=[-1])
285287
return torch.real(result)
286288

287289
def negative(self) -> "HRRTensor":

0 commit comments

Comments
 (0)