|
1 | 1 | import torch |
2 | | -import math |
3 | 2 | from .psd import PSD |
4 | 3 | from .skew import Skew |
5 | 4 | from .product import ProductManifold |
@@ -89,16 +88,8 @@ def submersion_inv(self, A: torch.Tensor, check_in_manifold=True, rho=1, tol=1e- |
89 | 88 | A_shifted = A + self.alpha * self.In |
90 | 89 | A_shifted_T = A_shifted.mT.contiguous() |
91 | 90 |
|
92 | | - # Batched Kronecker product using vmap for cleaner implementation |
93 | | - def _single_kron_sum(A_single): |
94 | | - I_single = torch.eye(self.n, device=A.device, dtype=A.dtype) |
95 | | - return torch.kron(I_single, A_single) + torch.kron(A_single, I_single) |
96 | | - |
97 | | - flat_batch_size = math.prod(self.tensorial_size) |
98 | | - A_flat = A_shifted_T.reshape(flat_batch_size, self.n, self.n) |
99 | | - |
100 | | - M_flat = torch.vmap(_single_kron_sum)(A_flat) |
101 | | - M = M_flat.reshape(*self.tensorial_size, self.n * self.n, self.n * self.n) |
| 91 | + identity = torch.eye(self.n, device=A.device, dtype=A.dtype) |
| 92 | + M = torch.kron(identity, A_shifted_T) + torch.kron(A_shifted_T, identity) |
102 | 93 |
|
103 | 94 | Q = rho * self.In |
104 | 95 | flat_Q = Q.flatten(-2, -1) |
@@ -157,7 +148,7 @@ def sample(self, init_=torch.nn.init.xavier_normal_): |
157 | 148 | with torch.no_grad(): |
158 | 149 | P = self[0].sample(init_) + self.In |
159 | 150 | Q = self[1].sample(init_) + self.In |
160 | | - S = self[2](init_(torch.empty_like(P))) |
| 151 | + S = self[2].sample(init_) |
161 | 152 |
|
162 | 153 | A = self.submersion(Q, P, S) |
163 | 154 | return A |
|
0 commit comments