Skip to content

Fix usage of new .mT to older .transpose() #138

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

Merged
merged 2 commits into from
Mar 29, 2023
Merged
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
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
setup(
name="torch-hd", # use torch-hd on PyPi to install torchhd, torchhd is too similar according to PyPi
version=version["__version__"],
description="Torchhd is a Python library for Hyperdimensional Computing",
description="Torchhd is a Python library for Hyperdimensional Computing and Vector Symbolic Architectures",
long_description=open("README.md").read(),
long_description_content_type="text/markdown",
url="https://github.com/hyperdimensional-computing/torchhd",
Expand Down
8 changes: 6 additions & 2 deletions torchhd/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -1562,7 +1562,7 @@ def resonator(input: VSATensor, estimates: VSATensor, domains: VSATensor) -> VSA
new_estimates = bind(input.unsqueeze(-2), inv_others)

similarity = dot_similarity(new_estimates.unsqueeze(-2), domains)
output = dot_similarity(similarity, domains.mT).squeeze(-2)
output = dot_similarity(similarity, domains.transpose(-2, -1)).squeeze(-2)

# normalize the output vector with a non-linearity
return output.sign()
Expand Down Expand Up @@ -1591,7 +1591,11 @@ def ridge_regression(

variance = alpha * torch.diag(torch.var(samples, -2))

return labels.mT @ samples @ torch.linalg.pinv(samples.mT @ samples + variance)
return (
labels.transpose(-2, -1)
@ samples
@ torch.linalg.pinv(samples.transpose(-2, -1) @ samples + variance)
)


def map_range(
Expand Down
2 changes: 1 addition & 1 deletion torchhd/tensors/bsc.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ def dot_similarity(self, others: "BSCTensor") -> Tensor:
others_as_bipolar = torch.where(others.bool(), min_one, plus_one)

if others.dim() >= 2:
others_as_bipolar = others_as_bipolar.mT
others_as_bipolar = others_as_bipolar.transpose(-2, -1)
return torch.matmul(self_as_bipolar, others_as_bipolar)

def cosine_similarity(self, others: "BSCTensor") -> Tensor:
Expand Down
2 changes: 1 addition & 1 deletion torchhd/tensors/fhrr.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ def permute(self, shifts: int = 1) -> "FHRRTensor":
def dot_similarity(self, others: "FHRRTensor") -> Tensor:
"""Inner product with other hypervectors"""
if others.dim() >= 2:
others = others.mT
others = others.transpose(-2, -1)
return torch.real(torch.matmul(self, torch.conj(others)))

def cosine_similarity(self, others: "FHRRTensor", *, eps=1e-08) -> Tensor:
Expand Down
2 changes: 1 addition & 1 deletion torchhd/tensors/hrr.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ def permute(self, shifts: int = 1) -> "HRRTensor":
def dot_similarity(self, others: "HRRTensor") -> Tensor:
"""Inner product with other hypervectors"""
if others.dim() >= 2:
others = others.mT
others = others.transpose(-2, -1)
return torch.matmul(self, others)

def cosine_similarity(self, others: "HRRTensor", *, eps=1e-08) -> Tensor:
Expand Down
2 changes: 1 addition & 1 deletion torchhd/tensors/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ def dot_similarity(self, others: "MAPTensor") -> Tensor:
"""Inner product with other hypervectors"""
dtype = torch.get_default_dtype()
if others.dim() >= 2:
others = others.mT
others = others.transpose(-2, -1)
return torch.matmul(self.to(dtype), others.to(dtype))

def cosine_similarity(self, others: "MAPTensor", *, eps=1e-08) -> Tensor:
Expand Down