Ejemplo n.º 1
0
def sym_eig(A, dt=None):
    """Compute the eigenvalues and right eigenvectors of a real symmetric matrix.

    Mathematical concept refers to https://en.wikipedia.org/wiki/Eigendecomposition_of_a_matrix.
    2D implementation refers to :func:`taichi.lang.linalg.sym_eig2x2`.

    Args:
        A (ti.Matrix(n, n)): Symmetric Matrix for which the eigenvalues and right eigenvectors will be computed.
        dt (DataType): The datatype for the eigenvalues and right eigenvectors.

    Returns:
        eigenvalues (ti.Vector(n)): The eigenvalues. Each entry store one eigen value.
        eigenvectors (ti.Matrix(n, n)): The eigenvectors. Each column stores one eigenvector.
    """
    assert all(A == A.transpose()), "A needs to be symmetric"
    if dt is None:
        dt = impl.get_runtime().default_fp
    from taichi.lang import linalg
    if A.n == 2:
        return linalg.sym_eig2x2(A, dt)
    raise Exception("Symmetric eigen solver only supports 2D matrices.")
Ejemplo n.º 2
0
def sym_eig(A, dt=None):
    """Compute the eigenvalues and right eigenvectors of a real symmetric matrix.

    Parameters
    ----------
    A: ti.Matrix(n, n)
        Symmetric Matrix for which the eigenvalues and right eigenvectors will be computed.
    dt: Optional[DataType]
        The datatype for the eigenvalues and right eigenvectors

    Returns
    -------
    eigenvalues: ti.Vector(n)
        The eigenvalues. Each entry store one eigen value.
    eigenvectors: ti.Matrix(n, n)
        The eigenvectors. Each column stores one eigenvector.
    """
    assert all(A == A.transpose()), "A needs to be symmetric"
    if dt is None:
        dt = impl.get_runtime().default_fp
    from taichi.lang import linalg
    if A.n == 2:
        return linalg.sym_eig2x2(A, dt)
    raise Exception("Symmetric eigen solver only supports 2D matrices.")