code: def cosine_distances(X, Y=None):
      """Compute cosine distance between samples in X and Y.
  
      Cosine distance is defined as 1.0 minus the cosine similarity.
  
      Read more in the :ref:`User Guide <metrics>`.
  
      Parameters
      ----------
      X : {array-like, sparse matrix} of shape (n_samples_X, n_features)
          Matrix `X`.
  
      Y : {array-like, sparse matrix} of shape (n_samples_Y, n_features), \
              default=None
          Matrix `Y`.
  
      Returns
      -------
      distances : ndarray of shape (n_samples_X, n_samples_Y)
          Returns the cosine distance between samples in X and Y.
  
      See Also
      --------
      cosine_similarity : Compute cosine similarity between samples in X and Y.
      scipy.spatial.distance.cosine : Dense matrices only.
  
      Examples
      --------
      >>> from sklearn.metrics.pairwise import cosine_distances
      >>> X = [[0, 0, 0], [1, 1, 1]]
      >>> Y = [[1, 0, 0], [1, 1, 0]]
      >>> cosine_distances(X, Y)
      array([[1.     , 1.     ],
             [0.42..., 0.18...]])
      """
      # 1.0 - cosine_similarity(X, Y) without copy
      S = cosine_similarity(X, Y)
      S *= -1
      S += 1
      np.clip(S, 0, 2, out=S)
      if X is Y or Y is None:
          # Ensure that distances between vectors and themselves are set to 0.0.
          # This may not be the case due to floating point rounding errors.
          np.fill_diagonal(S, 0.0)
      return S
  
imports: import itertools
  import warnings
  from functools import partial
  from numbers import Integral, Real
  import numpy
  from joblib import effective_n_jobs
  from scipy.sparse import csr_matrix, issparse
  from scipy.spatial import distance
  from ..None import config_context
  from ..exceptions import DataConversionWarning
  from ..preprocessing import normalize
  from ..utils import check_array, gen_batches, gen_even_slices, get_chunk_n_rows, is_scalar_nan
  from ..utils._mask import _get_mask
  from ..utils._param_validation import Hidden, Interval, MissingValues, Options, StrOptions, validate_params
  from ..utils.extmath import row_norms, safe_sparse_dot
  from ..utils.fixes import parse_version, sp_base_version
  from ..utils.parallel import Parallel, delayed
  from ..utils.validation import _num_samples, check_non_negative
  from ._pairwise_distances_reduction import ArgKmin
  from ._pairwise_fast import _chi2_kernel_fast, _sparse_manhattan
label_desc: Use image node_id 14 for calling a global function with example usage: cosine_distances(X, Y) and returns: S