code: def test_diagonal(n, m, m_excluded):
      """Test ``m - m_excluded`` eigenvalues and eigenvectors of
      diagonal matrices of the size ``n`` varying matrix formats:
      dense array, spare matrix, and ``LinearOperator`` for both
      matrixes in the generalized eigenvalue problem ``Av = cBv``
      and for the preconditioner.
      """
      rnd = np.random.RandomState(0)
  
      # Define the generalized eigenvalue problem Av = cBv
      # where (c, v) is a generalized eigenpair,
      # A is the diagonal matrix whose entries are 1,...n,
      # B is the identity matrix.
      vals = np.arange(1, n + 1, dtype=float)
      A_s = diags([vals], [0], (n, n))
      A_a = A_s.toarray()
  
      def A_f(x):
          return A_s @ x
  
      A_lo = LinearOperator(
          matvec=A_f, matmat=A_f, shape=(n, n), dtype=float
      )
  
      B_a = eye(n)
      B_s = csr_matrix(B_a)
  
      def B_f(x):
          return B_a @ x
  
      B_lo = LinearOperator(
          matvec=B_f, matmat=B_f, shape=(n, n), dtype=float
      )
  
      # Let the preconditioner M be the inverse of A.
      M_s = diags([1.0 / vals], [0], (n, n))
      M_a = M_s.toarray()
  
      def M_f(x):
          return M_s @ x
  
      M_lo = LinearOperator(
          matvec=M_f, matmat=M_f, shape=(n, n), dtype=float
      )
  
      # Pick random initial vectors.
      X = rnd.normal(size=(n, m))
  
      # Require that the returned eigenvectors be in the orthogonal complement
      # of the first few standard basis vectors.
      if m_excluded > 0:
          Y = np.eye(n, m_excluded)
      else:
          Y = None
  
      for A in [A_a, A_s, A_lo]:
          for B in [B_a, B_s, B_lo]:
              for M in [M_a, M_s, M_lo]:
                  eigvals, vecs = lobpcg(
                      A, X, B, M=M, Y=Y, maxiter=40, largest=False
                  )
  
                  assert_allclose(
                      eigvals,
                      np.arange(1 + m_excluded, 1 + m_excluded + m),
                  )
                  _check_eigen(A, eigvals, vecs, rtol=1e-3, atol=1e-3)
  
imports: import itertools
  import platform
  import sys
  import pytest
  import numpy
  from numpy import ones, r_, diag
  from numpy.testing import assert_almost_equal, assert_equal, assert_allclose, assert_array_less
  from scipy import sparse
  from scipy.linalg import eig, eigh, toeplitz, orth
  from scipy.sparse import spdiags, diags, eye, csr_matrix
  from scipy.sparse.linalg import eigs, LinearOperator
  from scipy.sparse.linalg._eigen.lobpcg import lobpcg
  from scipy.sparse.linalg._eigen.lobpcg.lobpcg import _b_orthonormalize
  from scipy._lib._util import np_long, np_ulong
label_desc: Use image node_id 11 for calling a global function with example usage: test_diagonal(n, m, m_excluded) and returns: unknown, unknown, unknown