Skip to content

matfree.eig

matfree.eig

Matrix-free eigenvalue and singular-value analysis.

matfree.eig.eig_partial(hessenberg: Callable) -> Callable

Partial eigenvalue decomposition.

Combines Hessenberg factorisation with a decomposition of the (small) Hessenberg matrix.

Parameters:

Name Type Description Default
hessenberg Callable

An implementation of Hessenberg factorisation. For example, the output of decomp.hessenberg.

required
Source code in matfree/eig.py
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
def eig_partial(hessenberg: Callable) -> Callable:
    """Partial eigenvalue decomposition.

    Combines Hessenberg factorisation with a decomposition
    of the (small) Hessenberg matrix.

    Parameters
    ----------
    hessenberg:
        An implementation of Hessenberg factorisation.
        For example, the output of
        [decomp.hessenberg][matfree.decomp.hessenberg].

    """

    def eig(Av: Callable, v0: Array, *parameters):
        # Flatten in- and outputs
        Av_flat, flattened = _partial_and_flatten_matvec(Av, v0, *parameters)
        _, (v0_flat, v_unravel) = flattened

        # Call the flattened eig
        vals, vecs = eig_flat(Av_flat, v0_flat)

        # Unravel the eigenvectors
        vecs = func.vmap(v_unravel)(vecs)
        return vals, vecs

    def eig_flat(Av: Callable, v0: Array):
        # Factorise the matrix
        Q, H, *_ = hessenberg(Av, v0)

        # Compute eig of factorisation
        vals, vecs = linalg.eig(H)
        vecs = Q @ vecs
        return vals, vecs.T

    return eig

matfree.eig.eigh_partial(tridiag_sym: Callable) -> Callable

Partial symmetric/Hermitian eigenvalue decomposition.

Combines tridiagonalization with a decomposition of the (small) tridiagonal matrix.

Parameters:

Name Type Description Default
tridiag_sym Callable

An implementation of tridiagonalization. For example, the output of decomp.tridiag_sym.

required
Source code in matfree/eig.py
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
def eigh_partial(tridiag_sym: Callable) -> Callable:
    """Partial symmetric/Hermitian eigenvalue decomposition.

    Combines tridiagonalization with a decomposition
    of the (small) tridiagonal matrix.

    Parameters
    ----------
    tridiag_sym:
        An implementation of tridiagonalization.
        For example, the output of
        [decomp.tridiag_sym][matfree.decomp.tridiag_sym].

    """

    def eigh(Av: Callable, v0: Array, *parameters):
        # Flatten in- and outputs
        Av_flat, flattened = _partial_and_flatten_matvec(Av, v0, *parameters)
        _, (v0_flat, v_unravel) = flattened

        # Call the flattened eigh
        vals, vecs = eigh_flat(Av_flat, v0_flat)

        # Unravel the eigenvectors
        vecs = func.vmap(v_unravel)(vecs)
        return vals, vecs

    def eigh_flat(Av: Callable, v0: Array):
        # Factorise the matrix
        Q, H, *_ = tridiag_sym(Av, v0)

        # Compute eigh of factorisation
        vals, vecs = linalg.eigh(H)
        vecs = Q @ vecs
        return vals, vecs.T

    return eigh

matfree.eig.svd_partial(bidiag: Callable) -> Callable

Partial singular value decomposition.

Combines bidiagonalisation with a full SVD of the (small) bidiagonal matrix.

Parameters:

Name Type Description Default
bidiag Callable

An implementation of bidiagonalisation. For example, the output of decomp.bidiag. Note how this function assumes that the bidiagonalisation materialises the bidiagonal matrix.

required
Source code in matfree/eig.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
def svd_partial(bidiag: Callable) -> Callable:
    """Partial singular value decomposition.

    Combines bidiagonalisation with a full SVD of the (small) bidiagonal matrix.

    Parameters
    ----------
    bidiag:
        An implementation of bidiagonalisation.
        For example, the output of
        [decomp.bidiag][matfree.decomp.bidiag].
        Note how this function assumes that the bidiagonalisation
        materialises the bidiagonal matrix.

    """

    def svd(Av: Callable, v0: Array, *parameters):
        # Flatten in- and outputs
        Av_flat, flattened = _partial_and_flatten_matvec(Av, v0, *parameters)
        (u0_flat, u_unravel), (v0_flat, v_unravel) = flattened

        # Call the flattened SVD
        ut, s, vt = svd_flat(Av_flat, v0_flat)

        # Unravel the singular vectors
        ut_tree = func.vmap(u_unravel)(ut)
        vt_tree = func.vmap(v_unravel)(vt)
        return ut_tree, s, vt_tree

    def svd_flat(Av: Callable, v0: Array):
        # Factorise the matrix
        (u, v), B, *_ = bidiag(Av, v0)

        # Compute SVD of factorisation
        U, S, Vt = linalg.svd(B, full_matrices=False)

        # Combine orthogonal transformations
        return (u @ U).T, S, Vt @ v.T

    return svd