code: def _check_matrix(op):
      """Check that if the operation says it has a matrix, it does. Otherwise a ``MatrixUndefinedError`` should be raised."""
      if op.has_matrix:
          mat = op.matrix()
          assert isinstance(
              mat, qml.typing.TensorLike
          ), "matrix must be a TensorLike"
          l = 2 ** len(op.wires)
          failure_comment = (
              f"matrix must be two dimensional with shape ({l}, {l})"
          )
          assert qml.math.shape(mat) == (l, l), failure_comment
      else:
          failure_comment = "If has_matrix is False, the matrix method must raise a ``MatrixUndefinedError``."
          _assert_error_raised(
              op.matrix,
              qml.operation.MatrixUndefinedError,
              failure_comment=failure_comment,
          )()
  
file_path: pennylane/pennylane/ops/functions/assert_valid.py
imports: from string import ascii_lowercase
  import copy
  import pickle
  import numpy
  import pennylane
  from pennylane.operation import EigvalsUndefinedError
label_desc: Use image node_id 3 for calling a global function with example usage: _check_matrix(op) without return types