🎨 Format Python code with psf/black
This commit is contained in:
@@ -9,6 +9,7 @@ class OrthogonalBlock(torch.nn.Module):
|
||||
The module takes a tensor of size [N, M] and returns a tensor of
|
||||
size [N, M] where the columns are orthonormal.
|
||||
"""
|
||||
|
||||
def __init__(self, dim=-1):
|
||||
"""
|
||||
Initialize the OrthogonalBlock module.
|
||||
@@ -30,8 +31,10 @@ class OrthogonalBlock(torch.nn.Module):
|
||||
"""
|
||||
# check dim is less than all the other dimensions
|
||||
if X.shape[self.dim] > min(X.shape):
|
||||
raise Warning("The dimension where to orthogonalize is greater\
|
||||
than the other dimensions")
|
||||
raise Warning(
|
||||
"The dimension where to orthogonalize is greater\
|
||||
than the other dimensions"
|
||||
)
|
||||
|
||||
result = torch.zeros_like(X)
|
||||
# normalize first basis
|
||||
@@ -42,9 +45,11 @@ class OrthogonalBlock(torch.nn.Module):
|
||||
for i in range(1, X.shape[self.dim]):
|
||||
v = torch.select(X, self.dim, i)
|
||||
for j in range(i):
|
||||
v -= torch.sum(v * torch.select(result, self.dim, j),
|
||||
dim=self.dim, keepdim=True) * torch.select(
|
||||
result, self.dim, j)
|
||||
v -= torch.sum(
|
||||
v * torch.select(result, self.dim, j),
|
||||
dim=self.dim,
|
||||
keepdim=True,
|
||||
) * torch.select(result, self.dim, j)
|
||||
result_i = torch.select(result, self.dim, i)
|
||||
result_i += v / torch.norm(v)
|
||||
return result
|
||||
Reference in New Issue
Block a user