# scipy 1.18.1 (BSD-3-Clause), harvested by tools/harvest_corpus.py
=== input

    Construct a Sakurai matrix in various formats and its eigenvalues.

    Constructs the "Sakurai" matrix motivated by reference [1]_:
    square real symmetric positive definite and 5-diagonal
    with the main diagonal ``[5, 6, 6, ..., 6, 6, 5], the ``+1`` and ``-1``
    diagonals filled with ``-4``, and the ``+2`` and ``-2`` diagonals
    made of ``1``. Its eigenvalues are analytically known to be
    ``16. * np.power(np.cos(0.5 * k * np.pi / (n + 1)), 4)``.
    The matrix gets ill-conditioned with its size growing.
    It is useful for testing and benchmarking sparse eigenvalue solvers
    especially those taking advantage of its banded 5-diagonal structure.
    See the notes below for details.

    Parameters
    ----------
    n : int
        The size of the matrix.
    dtype : dtype
        Numerical type of the array. Default is ``np.int8``.

    Methods
    -------
    toarray()
        Construct a dense array from Laplacian data
    tosparse()
        Construct a sparse array from Laplacian data
    tobanded()
        The Sakurai matrix in the format for banded symmetric matrices,
        i.e., (3, n) ndarray with 3 upper diagonals
        placing the main diagonal at the bottom.
    eigenvalues
        All eigenvalues of the Sakurai matrix ordered ascending.

    Notes
    -----
    Reference [1]_ introduces a generalized eigenproblem for the matrix pair
    `A` and `B` where `A` is the identity so we turn it into an eigenproblem
    just for the matrix `B` that this function outputs in various formats
    together with its eigenvalues.

    .. versionadded:: 1.12.0

    References
    ----------
    .. [1] T. Sakurai, H. Tadano, Y. Inadomi, and U. Nagashima,
       "A moment-based method for large-scale generalized
       eigenvalue problems",
       Appl. Num. Anal. Comp. Math. Vol. 1 No. 2 (2004).

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.sparse.linalg._special_sparse_arrays import Sakurai
    >>> from scipy.linalg import eig_banded
    >>> n = 6
    >>> sak = Sakurai(n)

    Since all matrix entries are small integers, ``'int8'`` is
    the default dtype for storing matrix representations.

    >>> sak.toarray()
    array([[ 5, -4,  1,  0,  0,  0],
           [-4,  6, -4,  1,  0,  0],
           [ 1, -4,  6, -4,  1,  0],
           [ 0,  1, -4,  6, -4,  1],
           [ 0,  0,  1, -4,  6, -4],
           [ 0,  0,  0,  1, -4,  5]], dtype=int8)
    >>> sak.tobanded()
    array([[ 1,  1,  1,  1,  1,  1],
           [-4, -4, -4, -4, -4, -4],
           [ 5,  6,  6,  6,  6,  5]], dtype=int8)
    >>> sak.tosparse()
    <DIAgonal sparse array of dtype 'int8'
        with 24 stored elements (5 diagonals) and shape (6, 6)>
    >>> np.array_equal(sak.dot(np.eye(n)), sak.tosparse().toarray())
    True
    >>> sak.eigenvalues()
    array([0.03922866, 0.56703972, 2.41789479, 5.97822974,
           10.54287655, 14.45473055])
    >>> sak.eigenvalues(2)
    array([0.03922866, 0.56703972])

    The banded form can be used in scipy functions for banded matrices, e.g.,

    >>> e = eig_banded(sak.tobanded(), eigvals_only=True)
    >>> np.allclose(sak.eigenvalues(), e, atol= n * n * n * np.finfo(float).eps)
    True

    
=== parse numpydoc
short_description: 'Construct a Sakurai matrix in various formats and its eigenvalues.'
long_description: |
  Constructs the "Sakurai" matrix motivated by reference [1]_:
  square real symmetric positive definite and 5-diagonal
  with the main diagonal ``[5, 6, 6, ..., 6, 6, 5], the ``+1`` and ``-1``
  diagonals filled with ``-4``, and the ``+2`` and ``-2`` diagonals
  made of ``1``. Its eigenvalues are analytically known to be
  ``16. * np.power(np.cos(0.5 * k * np.pi / (n + 1)), 4)``.
  The matrix gets ill-conditioned with its size growing.
  It is useful for testing and benchmarking sparse eigenvalue solvers
  especially those taking advantage of its banded 5-diagonal structure.
  See the notes below for details.
blank_after_short_description: True
blank_after_long_description: True
style: numpydoc
- DocstringParam
  description: 'The size of the matrix.'
  kind: param
  key: 'param'
  arg_name: 'n'
  type_name: 'int'
  is_optional: False
- DocstringParam
  description: 'Numerical type of the array. Default is ``np.int8``.'
  kind: param
  key: 'param'
  arg_name: 'dtype'
  type_name: 'dtype'
  is_optional: True
  default: 'np.int8'
- DocstringMethod
  description: 'Construct a dense array from Laplacian data'
  kind: method
  key: 'methods'
  name: 'toarray()'
- DocstringMethod
  description: 'Construct a sparse array from Laplacian data'
  kind: method
  key: 'methods'
  name: 'tosparse()'
- DocstringMethod
  description: |
    The Sakurai matrix in the format for banded symmetric matrices,
    i.e., (3, n) ndarray with 3 upper diagonals
    placing the main diagonal at the bottom.
  kind: method
  key: 'methods'
  name: 'tobanded()'
- DocstringMethod
  description: 'All eigenvalues of the Sakurai matrix ordered ascending.'
  kind: method
  key: 'methods'
  name: 'eigenvalues'
- DocstringMeta
  description: |
    Reference [1]_ introduces a generalized eigenproblem for the matrix pair
    `A` and `B` where `A` is the identity so we turn it into an eigenproblem
    just for the matrix `B` that this function outputs in various formats
    together with its eigenvalues.
    
    .. versionadded:: 1.12.0
  kind: text
  key: 'notes'
  title: 'Notes'
- DocstringMeta
  description: |
    .. [1] T. Sakurai, H. Tadano, Y. Inadomi, and U. Nagashima,
       "A moment-based method for large-scale generalized
       eigenvalue problems",
       Appl. Num. Anal. Comp. Math. Vol. 1 No. 2 (2004).
  kind: text
  key: 'references'
  title: 'References'
- DocstringExample
  kind: examples
  key: 'examples'
  snippet: '>>> import numpy as np'
- DocstringExample
  kind: examples
  key: 'examples'
  snippet: '>>> from scipy.sparse.linalg._special_sparse_arrays import Sakurai'
- DocstringExample
  kind: examples
  key: 'examples'
  snippet: '>>> from scipy.linalg import eig_banded'
- DocstringExample
  kind: examples
  key: 'examples'
  snippet: '>>> n = 6'
- DocstringExample
  kind: examples
  key: 'examples'
  snippet: '>>> sak = Sakurai(n)'
- DocstringExample
  description: |
    Since all matrix entries are small integers, ``'int8'`` is
    the default dtype for storing matrix representations.
  kind: examples
  key: 'examples'
  snippet: |
    >>> sak.toarray()
    array([[ 5, -4,  1,  0,  0,  0],
           [-4,  6, -4,  1,  0,  0],
           [ 1, -4,  6, -4,  1,  0],
           [ 0,  1, -4,  6, -4,  1],
           [ 0,  0,  1, -4,  6, -4],
           [ 0,  0,  0,  1, -4,  5]], dtype=int8)
- DocstringExample
  kind: examples
  key: 'examples'
  snippet: |
    >>> sak.tobanded()
    array([[ 1,  1,  1,  1,  1,  1],
           [-4, -4, -4, -4, -4, -4],
           [ 5,  6,  6,  6,  6,  5]], dtype=int8)
- DocstringExample
  kind: examples
  key: 'examples'
  snippet: |
    >>> sak.tosparse()
    <DIAgonal sparse array of dtype 'int8'
        with 24 stored elements (5 diagonals) and shape (6, 6)>
- DocstringExample
  kind: examples
  key: 'examples'
  snippet: |
    >>> np.array_equal(sak.dot(np.eye(n)), sak.tosparse().toarray())
    True
- DocstringExample
  kind: examples
  key: 'examples'
  snippet: |
    >>> sak.eigenvalues()
    array([0.03922866, 0.56703972, 2.41789479, 5.97822974,
           10.54287655, 14.45473055])
- DocstringExample
  kind: examples
  key: 'examples'
  snippet: |
    >>> sak.eigenvalues(2)
    array([0.03922866, 0.56703972])
- DocstringExample
  description: 'The banded form can be used in scipy functions for banded matrices, e.g.,'
  kind: examples
  key: 'examples'
  snippet: '>>> e = eig_banded(sak.tobanded(), eigvals_only=True)'
- DocstringExample
  kind: examples
  key: 'examples'
  snippet: |
    >>> np.allclose(sak.eigenvalues(), e, atol= n * n * n * np.finfo(float).eps)
    True
=== detect
numpydoc
=== compose numpydoc
Construct a Sakurai matrix in various formats and its eigenvalues.

Constructs the "Sakurai" matrix motivated by reference [1]_:
square real symmetric positive definite and 5-diagonal
with the main diagonal ``[5, 6, 6, ..., 6, 6, 5], the ``+1`` and ``-1``
diagonals filled with ``-4``, and the ``+2`` and ``-2`` diagonals
made of ``1``. Its eigenvalues are analytically known to be
``16. * np.power(np.cos(0.5 * k * np.pi / (n + 1)), 4)``.
The matrix gets ill-conditioned with its size growing.
It is useful for testing and benchmarking sparse eigenvalue solvers
especially those taking advantage of its banded 5-diagonal structure.
See the notes below for details.

Parameters
----------
n : int
    The size of the matrix.
dtype : dtype
    Numerical type of the array. Default is ``np.int8``.

Methods
-------
toarray()
    Construct a dense array from Laplacian data
tosparse()
    Construct a sparse array from Laplacian data
tobanded()
    The Sakurai matrix in the format for banded symmetric matrices,
    i.e., (3, n) ndarray with 3 upper diagonals
    placing the main diagonal at the bottom.
eigenvalues
    All eigenvalues of the Sakurai matrix ordered ascending.

Notes
-----
Reference [1]_ introduces a generalized eigenproblem for the matrix pair
`A` and `B` where `A` is the identity so we turn it into an eigenproblem
just for the matrix `B` that this function outputs in various formats
together with its eigenvalues.

.. versionadded:: 1.12.0

References
----------
.. [1] T. Sakurai, H. Tadano, Y. Inadomi, and U. Nagashima,
   "A moment-based method for large-scale generalized
   eigenvalue problems",
   Appl. Num. Anal. Comp. Math. Vol. 1 No. 2 (2004).

Examples
--------
>>> import numpy as np
>>> from scipy.sparse.linalg._special_sparse_arrays import Sakurai
>>> from scipy.linalg import eig_banded
>>> n = 6
>>> sak = Sakurai(n)

Since all matrix entries are small integers, ``'int8'`` is
the default dtype for storing matrix representations.

>>> sak.toarray()
array([[ 5, -4,  1,  0,  0,  0],
       [-4,  6, -4,  1,  0,  0],
       [ 1, -4,  6, -4,  1,  0],
       [ 0,  1, -4,  6, -4,  1],
       [ 0,  0,  1, -4,  6, -4],
       [ 0,  0,  0,  1, -4,  5]], dtype=int8)
>>> sak.tobanded()
array([[ 1,  1,  1,  1,  1,  1],
       [-4, -4, -4, -4, -4, -4],
       [ 5,  6,  6,  6,  6,  5]], dtype=int8)
>>> sak.tosparse()
<DIAgonal sparse array of dtype 'int8'
    with 24 stored elements (5 diagonals) and shape (6, 6)>
>>> np.array_equal(sak.dot(np.eye(n)), sak.tosparse().toarray())
True
>>> sak.eigenvalues()
array([0.03922866, 0.56703972, 2.41789479, 5.97822974,
       10.54287655, 14.45473055])
>>> sak.eigenvalues(2)
array([0.03922866, 0.56703972])

The banded form can be used in scipy functions for banded matrices, e.g.,

>>> e = eig_banded(sak.tobanded(), eigvals_only=True)
>>> np.allclose(sak.eigenvalues(), e, atol= n * n * n * np.finfo(float).eps)
True
