MCPcopy Create free account
hub / github.com/apple/ml-sharp / project

Function project

src/sharp/utils/linalg.py:100–104  ·  view source on GitHub ↗

Project tensor u to unit basis a.

(u: torch.Tensor, basis: torch.Tensor)

Source from the content-addressed store, hash-verified

98
99
100def project(u: torch.Tensor, basis: torch.Tensor) -> torch.Tensor:
101 """Project tensor u to unit basis a."""
102 unit_u = F.normalize(u, dim=-1)
103 inner_prod = (unit_u * basis).sum(dim=-1, keepdim=True)
104 return inner_prod * u

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected