code: def test_diagonal_data_types():
      """Check lobpcg for diagonal matrices for all matrix types."""
      np.random.seed(1234)
      n = 40
      m = 4
      # Define the generalized eigenvalue problem Av = cBv
      # where (c, v) is a generalized eigenpair,
      # and where we choose A  and B to be diagonal.
      vals = np.arange(1, n + 1)
  
      list_sparse_format = [
          "bsr",
          "coo",
          "csc",
          "csr",
          "dia",
          "dok",
          "lil",
      ]
      sparse_formats = len(list_sparse_format)
      for s_f_i, s_f in enumerate(list_sparse_format):
          As64 = diags([vals * vals], [0], (n, n), format=s_f)
          As32 = As64.astype(np.float32)
          Af64 = As64.toarray()
          Af32 = Af64.astype(np.float32)
          listA = [Af64, As64, Af32, As32]
  
          Bs64 = diags([vals], [0], (n, n), format=s_f)
          Bf64 = Bs64.toarray()
          listB = [Bf64, Bs64]
  
          # Define the preconditioner function as LinearOperator.
          Ms64 = diags([1.0 / vals], [0], (n, n), format=s_f)
  
          def Ms64precond(x):
              return Ms64 @ x
  
          Ms64precondLO = LinearOperator(
              matvec=Ms64precond,
              matmat=Ms64precond,
              shape=(n, n),
              dtype=float,
          )
          Mf64 = Ms64.toarray()
  
          def Mf64precond(x):
              return Mf64 @ x
  
          Mf64precondLO = LinearOperator(
              matvec=Mf64precond,
              matmat=Mf64precond,
              shape=(n, n),
              dtype=float,
          )
          Ms32 = Ms64.astype(np.float32)
  
          def Ms32precond(x):
              return Ms32 @ x
  
          Ms32precondLO = LinearOperator(
              matvec=Ms32precond,
              matmat=Ms32precond,
              shape=(n, n),
              dtype=np.float32,
          )
          Mf32 = Ms32.toarray()
  
          def Mf32precond(x):
              return Mf32 @ x
  
          Mf32precondLO = LinearOperator(
              matvec=Mf32precond,
              matmat=Mf32precond,
              shape=(n, n),
              dtype=np.float32,
          )
          listM = [
              None,
              Ms64precondLO,
              Mf64precondLO,
              Ms32precondLO,
              Mf32precondLO,
          ]
  
          # Setup matrix of the initial approximation to the eigenvectors
          # (cannot be sparse array).
          Xf64 = np.random.rand(n, m)
          Xf32 = Xf64.astype(np.float32)
          listX = [Xf64, Xf32]
  
          # Require that the returned eigenvectors be in the orthogonal complement
          # of the first few standard basis vectors (cannot be sparse array).
          m_excluded = 3
          Yf64 = np.eye(n, m_excluded, dtype=float)
          Yf32 = np.eye(n, m_excluded, dtype=np.float32)
          listY = [Yf64, Yf32]
  
          tests = list(
              itertools.product(listA, listB, listM, listX, listY)
          )
          # This is one of the slower tests because there are >1,000 configs
          # to test here, instead of checking product of all input, output types
          # test each configuration for the first sparse format, and then
          # for one additional sparse format. this takes 2/7=30% as long as
          # testing all configurations for all sparse formats.
          if s_f_i > 0:
              tests = tests[s_f_i - 1 :: sparse_formats - 1]
  
          for A, B, M, X, Y in tests:
              eigvals, _ = lobpcg(
                  A,
                  X,
                  B=B,
                  M=M,
                  Y=Y,
                  tol=1e-4,
                  maxiter=100,
                  largest=False,
              )
              assert_allclose(
                  eigvals, np.arange(1 + m_excluded, 1 + m_excluded + m)
              )
  
imports: import itertools
  import platform
  import numpy
  from numpy.testing import assert_almost_equal, assert_equal, assert_allclose, assert_array_less
  import pytest
  from numpy import ones, r_, diag
  from numpy.random import rand
  from scipy.linalg import eig, eigh, toeplitz, orth
  from scipy.sparse import spdiags, diags, eye
  from scipy.sparse.linalg import eigs, LinearOperator
  from scipy.sparse.linalg.eigen.lobpcg import lobpcg
label_desc: Use image node_id 19 for calling a global function with example usage: test_diagonal_data_types() and returns: unknown, unknown, unknown, unknown