code: def block_diag(mats, format=None, dtype=None):
      """
      Build a block diagonal sparse matrix from provided matrices.
  
      Parameters
      ----------
      mats : sequence of matrices
          Input matrices.
      format : str, optional
          The sparse format of the result (e.g., "csr"). If not given, the matrix
          is returned in "coo" format.
      dtype : dtype specifier, optional
          The data-type of the output matrix. If not given, the dtype is
          determined from that of `blocks`.
  
      Returns
      -------
      res : sparse matrix
  
      Notes
      -----
  
      .. versionadded:: 0.11.0
  
      See Also
      --------
      bmat, diags
  
      Examples
      --------
      >>> from scipy.sparse import coo_matrix, block_diag
      >>> A = coo_matrix([[1, 2], [3, 4]])
      >>> B = coo_matrix([[5], [6]])
      >>> C = coo_matrix([[7]])
      >>> block_diag((A, B, C)).toarray()
      array([[1, 2, 0, 0],
             [3, 4, 0, 0],
             [0, 0, 5, 0],
             [0, 0, 6, 0],
             [0, 0, 0, 7]])
  
      """
      row = []
      col = []
      data = []
      r_idx = 0
      c_idx = 0
      for a in mats:
          if isinstance(a, (list, numbers.Number)):
              a = coo_matrix(a)
          nrows, ncols = a.shape
          if issparse(a):
              a = a.tocoo()
              row.append(a.row + r_idx)
              col.append(a.col + c_idx)
              data.append(a.data)
          else:
              a_row, a_col = np.divmod(np.arange(nrows * ncols), ncols)
              row.append(a_row + r_idx)
              col.append(a_col + c_idx)
              data.append(a.ravel())
          r_idx += nrows
          c_idx += ncols
      row = np.concatenate(row)
      col = np.concatenate(col)
      data = np.concatenate(data)
      return coo_matrix(
          (data, (row, col)), shape=(r_idx, c_idx), dtype=dtype
      ).asformat(format)
  
imports: import numbers
  from functools import partial
  import numpy
  from scipy._lib._util import check_random_state, rng_integers
  from .sputils import upcast, get_index_dtype, isscalarlike
  from .csr import csr_matrix
  from .csc import csc_matrix
  from .bsr import bsr_matrix
  from .coo import coo_matrix
  from .dia import dia_matrix
  from .base import issparse
label_desc: Use image node_id 11 for calling a global function with example usage: block_diag(mats, format, dtype) and returns: coo_matrix