eigvalsh#

ivy.eigvalsh(x, /, *, UPLO='L', out=None)[source]#

Return the eigenvalues of a symmetric matrix (or a stack of symmetric matrices) x.

Note

The function eig will be added in a future version of the specification, as it requires complex number support, once complex numbers are supported, each square matrix must be Hermitian.

Note

Whether an array library explicitly checks whether an input array is a symmetric matrix (or a stack of symmetric matrices) is implementation-defined.

Parameters:
  • x (Union[Array, NativeArray]) – input array having shape (…, M, M) and whose innermost two dimensions form square matrices. Must have floating-point data type.

  • UPLO (str, default: 'L') – optional string being ‘L’ or ‘U’, specifying whether the calculation is done with the lower triangular part of x (‘L’, default) or the upper triangular part (‘U’).

  • out (Optional[Array], default: None) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

Array

Returns:

ret – an array containing the computed eigenvalues. The returned array must have shape (…, M) and and must have a real-valued floating-point data type whose precision matches the precision of x (e.g., if x is complex128, then the eigenvalues must be float64).

This function conforms to the Array API Standard. This docstring is an extension of the docstring in the standard.

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 inputs:

>>> x = ivy.array([[[1.0,2.0],[2.0,1.0]]])
>>> y = ivy.eigvalsh(x)
>>> print(y)
ivy.array([[-1.,  3.]])
>>> x = ivy.array([[[3.0,2.0],[2.0,3.0]]])
>>> y = ivy.zeros([1,2])
>>> ivy.eigvalsh(x, out=y)
>>> print(y)
ivy.array([[1., 5.]])
>>> x = ivy.array([[[3.0,2.0],[2.0,3.0]]])
>>> ivy.eigvalsh(x, out=x)
>>> print(x)
ivy.array([[1., 5.]])
>>> x = ivy.array([[[2.0,3.0,6.0],[3.0,4.0,5.0],[6.0,5.0,9.0]],
...                [[1.0,1.0,1.0],[1.0,2.0,2.0],[1.0,2.0,2.0]]])
>>> y = ivy.eigvalsh(x, UPLO="U")
>>> print(y)
ivy.array([[-1.45033181e+00,  1.02829754e+00,  1.54220343e+01],
   [-1.12647155e-15,  4.38447177e-01,  4.56155300e+00]])

With ivy.NativeArray inputs:

>>> x = ivy.native_array([[[1., 1., 2.], [1., 2., 1.], [1., 1., 2]]])
>>> y = ivy.eigvalsh(x)
>>> print(y)
ivy.array([[0.26794919, 1.        , 3.7320509 ]])

With ivy.Container inputs:

>>> x = ivy.Container(a=ivy.array([[[1.,2.,3.],[2.,4.,5.],[3.,5.,6.]]]),
...                      b=ivy.array([[[1.,1.,2.],[1.,2.,1.],[2.,1.,1.]]]),
...                      c=ivy.array([[[2.,2.,2.],[2.,3.,3.],[2.,3.,3.]]]))
>>> y = ivy.eigvalsh(x)
>>> print(y)
{
    a: ivy.array([[-0.51572949, 0.17091519, 11.3448143]]),
    b: ivy.array([[-1., 1., 4.]]),
    c: ivy.array([[-8.88178420e-16, 5.35898387e-01, 7.46410179e+00]])
}
Array.eigvalsh(self, /, *, UPLO='L', out=None)[source]#

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

Parameters:
  • x – input array having shape (…, M, M) and whose innermost two dimensions form square matrices. Must have floating-point data type.

  • out (Optional[Array], default: None) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

Array

Returns:

ret – an array containing the computed eigenvalues. The returned array must have shape (…, M) and have the same data type as x.

This function conforms to the Array API Standard. This docstring is an extension of the docstring in the standard.

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 inputs:

>>> x = ivy.array([[[1.0,2.0],[2.0,1.0]]])
>>> y = ivy.eigvalsh(x)
>>> print(y)
ivy.array([[-1.,  3.]])
Container.eigvalsh(self, /, *, UPLO='L', key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#

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

Parameters:
  • self (Container) – Ivy container having shape (..., M, M) and whose innermost two dimensions form square matrices. Should have a floating-point data type.

  • key_chains (Optional[Union[List[str], Dict[str, str], Container]], default: None) – The key-chains to apply or not apply the method to. Default is None.

  • to_apply (Union[bool, Container], default: True) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is True.

  • prune_unapplied (Union[bool, Container], default: False) – Whether to prune key_chains for which the function was not applied. Default is False.

  • map_sequences (Union[bool, Container], default: False) – Whether to also map method to sequences (lists, tuples). Default is False.

  • out (Optional[Container], default: None) – optional output container, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

Container

Returns:

ret – a container containing the computed eigenvalues. The returned array must have shape (…, M) and have the same data type as x.

Examples

With ivy.Container inputs:

>>> x = ivy.Container(a=ivy.array([[[1.,2.],[2.,1.]]]),
...                   b=ivy.array([[[2.,4.],[4.,2.]]]))
>>> y = ivy.eigvalsh(x)
>>> print(y)
{
    a: ivy.array([[-1., 3.]]),
    b: ivy.array([[-2., 6.]])
}