From a1e041c1f0cdd93fe6e59c676c0556ce2f9d76a3 Mon Sep 17 00:00:00 2001 From: ndem0 Date: Mon, 26 Aug 2024 08:49:18 +0000 Subject: [PATCH] :art: Format Python code with psf/black --- pina/model/layers/orthogonal.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/pina/model/layers/orthogonal.py b/pina/model/layers/orthogonal.py index 6296502..66be5c2 100644 --- a/pina/model/layers/orthogonal.py +++ b/pina/model/layers/orthogonal.py @@ -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,21 +31,25 @@ 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 X_0 = torch.select(X, self.dim, 0) result_0 = torch.select(result, self.dim, 0) - result_0 += X_0/torch.norm(X_0) + result_0 += X_0 / torch.norm(X_0) # iterate over the rest of the basis with Gram-Schmidt 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 \ No newline at end of file + result_i += v / torch.norm(v) + return result