Repository: scipy/scipy
File: scipy/spatial/distance.py (Python)

Code before:

        # Since the C code does not support striding using strides.
        # The dimensions are used instead.
        X = _copy_array_if_base_present(X)

        # Convert the vector to squareform.
        _distance_wrap.to_vector_from_squareform_wrap(X, v)
        return v
    else:
        raise ValueError("The first argument must be one or two dimensional "
                         f"array. A {len(s)}-dimensional array is not permitted")


def is_valid_dm(D, tol=0.0, throw=False, name="D", warning=False):
    """
    Return True if input array satisfies basic distance matrix properties
    (symmetry and zero diagonal).

    This function checks whether the input is a 2-dimensional square NumPy array
    with a zero diagonal and symmetry within a specified tolerance. These are
    necessary properties for a distance matrix but not sufficient -- in particular,
    this function does **not** check the triangle inequality, which is required
    for a true metric distance matrix.

    The triangle inequality states that for any three points i, j, and k:
    D[i,k] <= D[i,j] + D[j,k]
    
    Parameters
    ----------
    D : array_like
        The candidate object to test for basic distance matrix properties.
    tol : float, optional
        The distance matrix is considered symmetric if the absolute difference
        between entries ``ij`` and ``ji`` is less than or equal to `tol`. The same
        tolerance is used to determine whether diagonal entries are effectively zero.
    throw : bool, optional
        If True, raises an exception when the input is invalid.
    name : str, optional
        The name of the variable to check. This is used in exception messages when
        `throw` is True to identify the offending variable.
    warning : bool, optional
        If True, a warning message is raised instead of throwing an exception.
        
    Returns
    -------
    valid : bool
        True if the input satisfies the symmetry and zero-diagonal conditions.

    Raises
    ------
    ValueError

Review comment (suggestion):
```suggestion
    The triangle inequality states that for any three points ``i``, ``j``, and ``k``:
    ``D[i,k] <= D[i,j] + D[j,k]``
```

Code after:

        # Since the C code does not support striding using strides.
        # The dimensions are used instead.
        X = _copy_array_if_base_present(X)

        # Convert the vector to squareform.
        _distance_wrap.to_vector_from_squareform_wrap(X, v)
        return v
    else:
        raise ValueError("The first argument must be one or two dimensional "
                         f"array. A {len(s)}-dimensional array is not permitted")


def is_valid_dm(D, tol=0.0, throw=False, name="D", warning=False):
    """
    Return True if input array satisfies basic distance matrix properties
    (symmetry and zero diagonal).

    This function checks whether the input is a 2-dimensional square NumPy array
    with a zero diagonal and symmetry within a specified tolerance. These are
    necessary properties for a distance matrix but not sufficient -- in particular,
    this function does **not** check the triangle inequality, which is required
    for a true metric distance matrix.

    The triangle inequality states that for any three points ``i``, ``j``, and ``k``:
    ``D[i,k] <= D[i,j] + D[j,k]``
    
    Parameters
    ----------
    D : array_like
        The candidate object to test for basic distance matrix properties.
    tol : float, optional
        The distance matrix is considered symmetric if the absolute difference
        between entries ``ij`` and ``ji`` is less than or equal to `tol`. The same
        tolerance is used to determine whether diagonal entries are effectively zero.
    throw : bool, optional
        If True, raises an exception when the input is invalid.
    name : str, optional
        The name of the variable to check. This is used in exception messages when
        `throw` is True to identify the offending variable.
    warning : bool, optional
        If True, a warning message is raised instead of throwing an exception.
        
    Returns
    -------
    valid : bool
        True if the input satisfies the symmetry and zero-diagonal conditions.

    Raises
    ------
    ValueError