code: def is_valid_dm(D, tol=0.0, throw=False, name="D", warning=False):
      """
      Return True if input array is a valid distance matrix.
  
      Distance matrices must be 2-dimensional numpy arrays.
      They must have a zero-diagonal, and they must be symmetric.
  
      Parameters
      ----------
      D : ndarray
          The candidate object to test for validity.
      tol : float, optional
          The distance matrix should be symmetric. `tol` is the maximum
          difference between entries ``ij`` and ``ji`` for the distance
          metric to be considered symmetric.
      throw : bool, optional
          An exception is thrown if the distance matrix passed is not valid.
      name : str, optional
          The name of the variable to checked. This is useful if
          throw is set to True so the offending variable can be identified
          in the exception message when an exception is thrown.
      warning : bool, optional
          Instead of throwing an exception, a warning message is
          raised.
  
      Returns
      -------
      valid : bool
          True if the variable `D` passed is a valid distance matrix.
  
      Notes
      -----
      Small numerical differences in `D` and `D.T` and non-zeroness of
      the diagonal are ignored if they are within the tolerance specified
      by `tol`.
  
      """
      D = np.asarray(D, order="c")
      valid = True
      try:
          s = D.shape
          if len(D.shape) != 2:
              if name:
                  raise ValueError(
                      (
                          "Distance matrix '%s' must have shape=2 "
                          "(i.e. be two-dimensional)."
                      )
                      % name
                  )
              else:
                  raise ValueError(
                      "Distance matrix must have shape=2 (i.e. "
                      "be two-dimensional)."
                  )
          if tol == 0.0:
              if not (D == D.T).all():
                  if name:
                      raise ValueError(
                          ("Distance matrix '%s' must be " "symmetric.")
                          % name
                      )
                  else:
                      raise ValueError(
                          "Distance matrix must be symmetric."
                      )
              if not (D[xrange(0, s[0]), xrange(0, s[0])] == 0).all():
                  if name:
                      raise ValueError(
                          (
                              "Distance matrix '%s' diagonal must "
                              "be zero."
                          )
                          % name
                      )
                  else:
                      raise ValueError(
                          "Distance matrix diagonal must be zero."
                      )
          else:
              if not (D - D.T <= tol).all():
                  if name:
                      raise ValueError(
                          (
                              "Distance matrix '%s' must be "
                              "symmetric within tolerance %5.5f."
                          )
                          % (name, tol)
                      )
                  else:
                      raise ValueError(
                          "Distance matrix must be symmetric within"
                          " tolerance %5.5f." % tol
                      )
              if not (D[xrange(0, s[0]), xrange(0, s[0])] <= tol).all():
                  if name:
                      raise ValueError(
                          (
                              "Distance matrix '%s' diagonal must be"
                              " close to zero within tolerance %5.5f."
                          )
                          % (name, tol)
                      )
                  else:
                      raise ValueError(
                          (
                              "Distance matrix '%s' diagonal must be"
                              " close to zero within tolerance %5.5f."
                          )
                          % tol
                      )
      except Exception as e:
          if throw:
              raise
          if warning:
              warnings.warn(str(e))
          valid = False
      return valid
  
imports: from __future__ import division, print_function, absolute_import
  import warnings
  import numpy
  from functools import partial
  from collections import namedtuple
  from scipy._lib.six import callable, string_types
  from scipy._lib.six import xrange
  from scipy._lib._util import _asarray_validated
  from .None import _distance_wrap
  from .None import _hausdorff
  from ..linalg import norm
  from ..special import rel_entr
label_desc: Use image node_id 44 for calling a global function with example usage: is_valid_dm(D, tol, throw, name, warning) and returns: valid