(X, distance_matrices=False, **kwargs)
return Xnew
Input validation on arrays or lists representing collections of point
    clouds or of distance/adjacency matrices.

    The input is checked to be either a single 3D array using a single call
    to :func:`sklearn.utils.validation.check_array`, or a list of 2D arrays by
    calling :func:`sklearn.utils.validation.check_array` on each entry.

    Parameters
    ----------
    X : object
        Input object to check / convert.

    distance_matrices : bool, optional, default: ``False``
        Whether the input represents a collection of distance matrices or of
        concrete point clouds in Euclidean space. In the first case, entries
        are allowed to be infinite unless otherwise specified in `kwargs`.

    **kwargs
        Keyword arguments accepted by
        :func:`sklearn.utils.validation.check_array`, with the following
        caveats: 1) `ensure_2d` and `allow_nd` are ignored; 2) if not passed
        explicitly, `force_all_finite` is set to be the boolean negation of
        `distance_matrices`; 3) when `force_all_finite` is set to ``False``,
        NaN inputs are not allowed; 4) `accept_sparse` and
        `accept_large_sparse` are only meaningful in the case of lists of 2D
        arrays, in which case they are passed to individual instances of
        :func:`sklearn.utils.validation.check_array` validating each entry
        in the list.

    Returns
    -------
    Xnew : ndarray or list
        The converted and validated object.
Input validation on arrays or lists representing collections of point
    clouds or of distance/adjacency matrices.
Input validation on arrays or lists representing collections of point clouds or of distance / adjacency matrices .
def check_point_clouds(X, distance_matrices=False, **kwargs):
    """Input validation on arrays or lists representing collections of point
    clouds or of distance/adjacency matrices.

    The input is checked to be either a single 3D array using a single call
    to :func:`sklearn.utils.validation.check_array`, or a list of 2D arrays by
    calling :func:`sklearn.utils.validation.check_array` on each entry.

    Parameters
    ----------
    X : object
        Input object to check / convert.

    distance_matrices : bool, optional, default: ``False``
        Whether the input represents a collection of distance matrices or of
        concrete point clouds in Euclidean space. In the first case, entries
        are allowed to be infinite unless otherwise specified in `kwargs`.

    **kwargs
        Keyword arguments accepted by
        :func:`sklearn.utils.validation.check_array`, with the following
        caveats: 1) `ensure_2d` and `allow_nd` are ignored; 2) if not passed
        explicitly, `force_all_finite` is set to be the boolean negation of
        `distance_matrices`; 3) when `force_all_finite` is set to ``False``,
        NaN inputs are not allowed; 4) `accept_sparse` and
        `accept_large_sparse` are only meaningful in the case of lists of 2D
        arrays, in which case they are passed to individual instances of
        :func:`sklearn.utils.validation.check_array` validating each entry
        in the list.

    Returns
    -------
    Xnew : ndarray or list
        The converted and validated object.

    """
    kwargs_ = {'force_all_finite': not distance_matrices}
    kwargs_.update(kwargs)
    kwargs_.pop('allow_nd', None)
    kwargs_.pop('ensure_2d', None)
    if hasattr(X, 'shape') and hasattr(X, 'ndim'):
        if X.ndim != 3:
            if X.ndim == 2:
                extra_2D = \
                    "\nReshape your input X using X.reshape(1, *X.shape) or " \
                    "X[None, :, :] if X is a single point cloud/distance " \
                    "matrix/adjacency matrix of a weighted graph."
            else:
                extra_2D = ""
            raise ValueError(
                f"Input must be a single 3D array or a list of 2D arrays or "
                f"sparse matrices. Structure of dimension {X.ndim} passed."
                + extra_2D
                )
        if (X.shape[1] != X.shape[2]) and distance_matrices:
            raise ValueError(
                f"Input array X must have X.shape[1] == X.shape[2]: "
                f"{X.shape[1]} != {X.shape[2]} passed.")
        elif (X.shape[1] == X.shape[2]) and not distance_matrices:
            warn(
                "Input array X has X.shape[1] == X.shape[2]. This is "
                "consistent with a collection of distance/adjacency "
                "matrices, but the input is being treated as a collection "
                "of vectors in Euclidean space.",
                DataDimensionalityWarning, stacklevel=2
                )
        Xnew = _check_array_mod(X, allow_nd=True, **kwargs_)
    else:
        has_check_failed = False
        messages = []
        Xnew = []
        for i, x in enumerate(X):
            try:
                xnew = _check_array_mod(x, ensure_2d=True, **kwargs_)
                if distance_matrices and not issparse(xnew):
                    if not x.shape[0] == x.shape[1]:
                        raise ValueError(
                            f"All arrays must be square: {x.shape[0]} rows "
                            f"and {x.shape[1]} columns found in this array."
                            )
                Xnew.append(xnew)
            except ValueError as e:
                has_check_failed = True
                messages.append(f"Entry {i}:\n{e}")
        if has_check_failed:
            raise ValueError(
                "The following errors were raised by the inputs:\n\n" +
                "\n\n".join(messages)
                )

        if not distance_matrices:
            if reduce(and_, (x.shape[0] == x.shape[1] for x in X), True):
                warn(
                    "All arrays/matrices are square. This is consistent with "
                    "a collection of distance/adjacency matrices, but the "
                    "entries will be treated as collections of vectors in "
                    "Euclidean space.", DataDimensionalityWarning,
                    stacklevel=2
                    )

        ref_dim = X[0].shape  # Shape of first sample
        if reduce(and_, (x.shape == ref_dim for x in X[1:]), True):
            Xnew = np.asarray(Xnew)

    return Xnew
def check_point_clouds ( X , distance_matrices = False , * * kwargs ) : kwargs_ = { 'force_all_finite' : not distance_matrices } kwargs_ . update ( kwargs ) kwargs_ . pop ( 'allow_nd' , None ) kwargs_ . pop ( 'ensure_2d' , None ) if hasattr ( X , 'shape' ) and hasattr ( X , 'ndim' ) : if X . ndim != 3 : if X . ndim == 2 : extra_2D = "\nReshape your input X using X.reshape(1, *X.shape) or " "X[None, :, :] if X is a single point cloud/distance " "matrix/adjacency matrix of a weighted graph." else : extra_2D = "" raise ValueError ( f"Input must be a single 3D array or a list of 2D arrays or " f"sparse matrices. Structure of dimension {X.ndim} passed." + extra_2D ) if ( X . shape [ 1 ] != X . shape [ 2 ] ) and distance_matrices : raise ValueError ( f"Input array X must have X.shape[1] == X.shape[2]: " f"{X.shape[1]} != {X.shape[2]} passed." ) elif ( X . shape [ 1 ] == X . shape [ 2 ] ) and not distance_matrices : warn ( "Input array X has X.shape[1] == X.shape[2]. This is " "consistent with a collection of distance/adjacency " "matrices, but the input is being treated as a collection " "of vectors in Euclidean space." , DataDimensionalityWarning , stacklevel = 2 ) Xnew = _check_array_mod ( X , allow_nd = True , * * kwargs_ ) else : has_check_failed = False messages = [ ] Xnew = [ ] for i , x in enumerate ( X ) : try : xnew = _check_array_mod ( x , ensure_2d = True , * * kwargs_ ) if distance_matrices and not issparse ( xnew ) : if not x . shape [ 0 ] == x . shape [ 1 ] : raise ValueError ( f"All arrays must be square: {x.shape[0]} rows " f"and {x.shape[1]} columns found in this array." ) Xnew . append ( xnew ) except ValueError as e : has_check_failed = True messages . append ( f"Entry {i}:\n{e}" ) if has_check_failed : raise ValueError ( "The following errors were raised by the inputs:\n\n" + "\n\n" . join ( messages ) ) if not distance_matrices : if reduce ( and_ , ( x . shape [ 0 ] == x . shape [ 1 ] for x in X ) , True ) : warn ( "All arrays/matrices are square. This is consistent with " "a collection of distance/adjacency matrices, but the " "entries will be treated as collections of vectors in " "Euclidean space." , DataDimensionalityWarning , stacklevel = 2 ) ref_dim = X [ 0 ] . shape # Shape of first sample if reduce ( and_ , ( x . shape == ref_dim for x in X [ 1 : ] ) , True ) : Xnew = np . asarray ( Xnew ) return Xnew