code: def _smart_matrix_product(A, B, alpha=None, structure=None):
      """
      A matrix product that knows about sparse and structured matrices.
  
      Parameters
      ----------
      A : 2d ndarray
          First matrix.
      B : 2d ndarray
          Second matrix.
      alpha : float
          The matrix product will be scaled by this constant.
      structure : str, optional
          A string describing the structure of both matrices `A` and `B`.
          Only `upper_triangular` is currently supported.
  
      Returns
      -------
      M : 2d ndarray
          Matrix product of A and B.
  
      """
      if len(A.shape) != 2:
          raise ValueError("expected A to be a rectangular matrix")
      if len(B.shape) != 2:
          raise ValueError("expected B to be a rectangular matrix")
      f = None
      if structure == UPPER_TRIANGULAR:
          if not isspmatrix(A) and not isspmatrix(B):
              (f,) = scipy.linalg.get_blas_funcs(("trmm",), (A, B))
      if f is not None:
          if alpha is None:
              alpha = 1.0
          out = f(alpha, A, B)
      else:
          if alpha is None:
              out = A.dot(B)
          else:
              out = alpha * A.dot(B)
      return out
  
imports: from __future__ import division, print_function, absolute_import
  import math
  import numpy
  import scipy.special
  from scipy.linalg.basic import solve, solve_triangular
  from scipy.sparse.base import isspmatrix
  from scipy.sparse.construct import eye
  from scipy.sparse.linalg import spsolve
  import scipy.sparse
  import scipy.sparse.linalg
  from scipy.sparse.linalg.interface import LinearOperator
label_desc: Use image node_id 6 for calling a global function with example usage: _smart_matrix_product(A, B, alpha, structure) and returns: out