code: def test_diagonal():
      # This test was moved from '__main__' in lobpcg.py.
      # Coincidentally or not, this is the same eigensystem
      # required to reproduce arpack bug
      # https://forge.scilab.org/p/arpack-ng/issues/1397/
      # even using the same n=100.
  
      np.random.seed(1234)
  
      # The system of interest is of size n x n.
      n = 100
  
      # We care about only m eigenpairs.
      m = 4
  
      # Define the generalized eigenvalue problem Av = cBv
      # where (c, v) is a generalized eigenpair,
      # and where we choose A to be the diagonal matrix whose entries are 1..n
      # and where B is chosen to be the identity matrix.
      vals = np.arange(1, n + 1, dtype=float)
      A = scipy.sparse.diags([vals], [0], (n, n))
      B = scipy.sparse.eye(n)
  
      # Let the preconditioner M be the inverse of A.
      M = scipy.sparse.diags([np.reciprocal(vals)], [0], (n, n))
  
      # Pick random initial vectors.
      X = np.random.rand(n, m)
  
      # Require that the returned eigenvectors be in the orthogonal complement
      # of the first few standard basis vectors.
      m_excluded = 3
      Y = np.eye(n, m_excluded)
  
      eigs, vecs = lobpcg(
          A, X, B, M=M, Y=Y, tol=1e-4, maxiter=40, largest=False
      )
  
      assert_allclose(
          eigs, np.arange(1 + m_excluded, 1 + m_excluded + m)
      )
      _check_eigen(A, eigs, vecs, rtol=1e-3, atol=1e-3)
  
imports: from __future__ import division, print_function, absolute_import
  import itertools
  import numpy
  from numpy.testing import assert_almost_equal, assert_equal, assert_allclose, assert_array_less
  from scipy import ones, rand, r_, diag, linalg, eye
  from scipy.linalg import eig, eigh, toeplitz
  import scipy.sparse
  from scipy.sparse.linalg.eigen.lobpcg import lobpcg
  from scipy.sparse.linalg import eigs
  from scipy.sparse import spdiags
  import pytest
label_desc: Use image node_id 9 for calling a global function with example usage: test_diagonal() without return types