eigh_tridiagonal#

ivy.eigh_tridiagonal(alpha, beta, /, *, eigvals_only=True, select='a', select_range=None, tol=None)[source]#

Compute the eigenvalues and eigenvectors of a Hermitian tridiagonal matrix.

Parameters:
  • alpha (Union[Array, NativeArray]) – A real or complex array of shape (n), the diagonal elements of the matrix. If alpha is complex, the imaginary part is ignored (assumed zero) to satisfy the requirement that the matrix be Hermitian.

  • beta (Union[Array, NativeArray]) – A real or complex array of shape (n-1), containing the elements of the first super-diagonal of the matrix. If beta is complex, the first sub-diagonal of the matrix is assumed to be the conjugate of beta to satisfy the requirement that the matrix be Hermitian.

  • eigvals_only (bool, default: True) – If False, both eigenvalues and corresponding eigenvectors are computed. If True, only eigenvalues are computed. Default is True.

  • select (str, default: 'a') – Optional string with values in {‘a’, ‘v’, ‘i’} (default is ‘a’) that determines which eigenvalues to calculate: ‘a’: all eigenvalues. ‘v’: eigenvalues in the interval (min, max] given by select_range. ‘i’: eigenvalues with indices min <= i <= max.

  • select_range (Optional[Union[Tuple[int, int], List[int], Array, NativeArray]], default: None) – Size 2 tuple or list or array specifying the range of eigenvalues to compute together with select. If select is ‘a’, select_range is ignored.

  • tol (Optional[float], default: None) – Optional scalar. Ignored when backend is not Tensorflow. The absolute tolerance to which each eigenvalue is required. An eigenvalue (or cluster) is considered to have converged if it lies in an interval of this width. If tol is None (default), the value eps*|T|_2 is used where eps is the machine precision, and |T|_2 is the 2-norm of the matrix T.

Return type:

Union[Array, Tuple[Array, Array]]

Returns:

  • eig_vals – The eigenvalues of the matrix in non-decreasing order.

  • eig_vectors – If eigvals_only is False the eigenvectors are returned in the second output argument.

  • Both the description and the type hints above assumes an array input for

  • simplicity, but this function is *nestable, and therefore also accepts*

  • ivy.Container instances in place of any of the arguments.

Examples

With ivy.Array input:

>>> alpha = ivy.array([0., 1., 2.])
>>> beta = ivy.array([0., 1.])
>>> y = ivy.eigh_tridiagonal(alpha, beta)
>>> print(y)
ivy.array([0., 0.38196602, 2.61803389])
>>> alpha = ivy.array([0., 1., 2.])
>>> beta = ivy.array([0., 1.])
>>> y = ivy.eigh_tridiagonal(alpha,
...     beta, select='v',
...     select_range=[0.2,3.0])
>>> print(y)
ivy.array([0.38196602, 2.61803389])
>>> alpha = ivy.array([0., 1., 2., 3.])
>>> beta = ivy.array([2., 1., 2.])
>>> y = ivy.eigh_tridiagonal(alpha,
...     beta,
...     eigvals_only=False,
...     select='i',
...     select_range=[1,2],
...     tol=1.)
>>> print(y)
(ivy.array([0.38196602, 2.61803389]), ivy.array([[ 0.35048741, -0.56710052],
       [ 0.06693714, -0.74234426],
       [-0.74234426, -0.06693714],
       [ 0.56710052,  0.35048741]]))

With ivy.Container input:

>>> alpha = ivy.Container(a=ivy.array([0., 1., 2.]), b=ivy.array([2., 2., 2.]))
>>> beta = ivy.array([0.,2.])
>>> y = ivy.eigh_tridiagonal(alpha, beta)
>>> print(y)
{
    a: ivy.array([-0.56155282, 0., 3.56155276]),
    b: ivy.array([0., 2., 4.])
}
>>> alpha = ivy.Container(a=ivy.array([0., 1., 2.]), b=ivy.array([2., 2., 2.]))
>>> beta = ivy.Container(a=ivy.array([0.,2.]), b=ivy.array([2.,2.]))
>>> y = ivy.eigh_tridiagonal(alpha, beta)
>>> print(y)
{
    a: ivy.array([-0.56155282, 0., 3.56155276]),
    b: ivy.array([-0.82842714, 2., 4.82842731])
}
Array.eigh_tridiagonal(self, beta, /, *, eigvals_only=True, select='a', select_range=None, tol=None)[source]#

ivy.Array instance method variant of ivy.eigh_tridiagonal. This method simply wraps the function, and so the docstring for ivy.eigh_tridiagonal also applies to this method with minimal changes.

Parameters:
  • self (Union[Array, NativeArray]) – An array of real or complex arrays each of shape (n), the diagonal elements of the matrix.

  • beta (Union[Array, NativeArray]) – An array or of real or complex arrays each of shape (n-1), containing the elements of the first super-diagonal of the matrix.

  • eigvals_only (bool, default: True) – If False, both eigenvalues and corresponding eigenvectors are computed. If True, only eigenvalues are computed. Default is True.

  • select (str, default: 'a') – Optional string with values in {‘a’, ‘v’, ‘i’} (default is ‘a’) that determines which eigenvalues to calculate: ‘a’: all eigenvalues. ‘v’: eigenvalues in the interval (min, max] given by select_range. ‘i’: eigenvalues with indices min <= i <= max.

  • select_range (Optional[Union[Tuple[int, int], List[int], Array, NativeArray]], default: None) – Size 2 tuple or list or array specifying the range of eigenvalues to compute together with select. If select is ‘a’, select_range is ignored.

  • tol (Optional[float], default: None) – Optional scalar. Ignored when backend is not Tensorflow. The absolute tolerance to which each eigenvalue is required. An eigenvalue (or cluster) is considered to have converged if it lies in an interval of this width. If tol is None (default), the value eps*|T|_2 is used where eps is the machine precision, and |T|_2 is the 2-norm of the matrix T.

Return type:

Union[Array, Tuple[Array, Array]]

Returns:

  • eig_vals – The eigenvalues of the matrix in non-decreasing order.

  • eig_vectors – If eigvals_only is False the eigenvectors are returned in the second output argument.

Examples

>>> alpha = ivy.array([0., 1., 2.])
>>> beta = ivy.array([0., 1.])
>>> y = alpha.eigh_tridiagonal(beta)
>>> print(y)
ivy.array([0., 0.38196, 2.61803])
Container.eigh_tridiagonal(self, beta, /, *, eigvals_only=True, select='a', select_range=None, tol=None, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)[source]#

ivy.Container instance method variant of ivy.eigh_tridiagonal. This method simply wraps the function, and so the docstring for ivy.eigh_tridiagonal also applies to this method with minimal changes.

Parameters:
  • self (Container) – A container of real or complex arrays each of shape (n), the diagonal elements of the matrix.

  • beta (Union[Array, NativeArray, Container]) – An array or a container of real or complex arrays each of shape (n-1), containing the elements of the first super-diagonal of the matrix.

  • eigvals_only (Union[bool, Container], default: True) – If False, both eigenvalues and corresponding eigenvectors are computed. If True, only eigenvalues are computed. Default is True.

  • select (Union[str, Container], default: 'a') – Optional string with values in {‘a’, ‘v’, ‘i’} (default is ‘a’) that determines which eigenvalues to calculate: ‘a’: all eigenvalues. ‘v’: eigenvalues in the interval (min, max] given by select_range. ‘i’: eigenvalues with indices min <= i <= max.

  • select_range (Optional[Union[Tuple[int, int], List[int], Array, NativeArray, Container]], default: None) – Size 2 tuple or list or array specifying the range of eigenvalues to compute together with select. If select is ‘a’, select_range is ignored.

  • tol (Optional[Union[float, Container]], default: None) – Optional scalar. Ignored when backend is not Tensorflow. The absolute tolerance to which each eigenvalue is required. An eigenvalue (or cluster) is considered to have converged if it lies in an interval of this width. If tol is None (default), the value eps*|T|_2 is used where eps is the machine precision, and |T|_2 is the 2-norm of the matrix T.

Return type:

Union[Container, Tuple[Container, Container]]

Returns:

  • eig_vals – The eigenvalues of the matrix in non-decreasing order.

  • eig_vectors – If eigvals_only is False the eigenvectors are returned in the second output argument.

Examples

>>> alpha = ivy.Container(a=ivy.array([0., 1., 2.]), b=ivy.array([2., 2., 2.]))
>>> beta = ivy.array([0.,2.])
>>> y = alpha.eigh_tridiagonal(beta)
>>> print(y)
{
    a: ivy.array([-0.56155, 0., 3.56155]),
    b: ivy.array([0., 2., 4.])
}
>>> alpha = ivy.Container(a=ivy.array([0., 1., 2.]), b=ivy.array([2., 2., 2.]))
>>> beta = ivy.Container(a=ivy.array([0.,2.]), b=ivy.array([2.,2.]))
>>> y = alpha.eigh_tridiagonal(beta)
>>> print(y)
{
    a: ivy.array([-0.56155, 0., 3.56155]),
    b: ivy.array([-0.82842, 2., 4.82842])
}