Explicit construction of Krylov matrix [v A @ v A^2 @ v ... A^{n-1} @ v] where A = Z_f. This uses vectorized indexing and cumprod so it's much faster than using the Krylov function. Parameters: v: the starting vector of size n or (rank, n). f: real number Returns:
(v, f=0.0)
| 15 | |
| 16 | |
| 17 | def construct_toeplitz(v, f=0.0): |
| 18 | """Explicit construction of Krylov matrix [v A @ v A^2 @ v ... A^{n-1} @ v] |
| 19 | where A = Z_f. This uses vectorized indexing and cumprod so it's much |
| 20 | faster than using the Krylov function. |
| 21 | Parameters: |
| 22 | v: the starting vector of size n or (rank, n). |
| 23 | f: real number |
| 24 | Returns: |
| 25 | K: Krylov matrix of size (n, n) or (rank, n, n). |
| 26 | """ |
| 27 | n = v.shape[-1] |
| 28 | a = torch.arange(n, device=v.device) |
| 29 | b = -a |
| 30 | indices = a[:, None] + b[None] |
| 31 | K = v[..., indices] |
| 32 | K[..., indices < 0] *= f |
| 33 | return K |
| 34 | |
| 35 | def triangular_toeplitz_multiply_(u, v, sum=None): |
| 36 | n = u.shape[-1] |