code: def test_cross_validation_manual_vs_scikit(
      estimator, build_dataset, with_preprocessor
  ):
      """Tests that if we make a manual cross-validation, the result will be the
      same as scikit-learn's cross-validation (some code for generating the
      folds is taken from scikit-learn).
      """
      if any(
          hasattr(estimator, method) for method in ["predict", "score"]
      ):
          input_data, labels, preprocessor, _ = build_dataset(
              with_preprocessor
          )
          estimator = clone(estimator)
          estimator.set_params(preprocessor=preprocessor)
          set_random_state(estimator)
          n_splits = 3
          kfold = KFold(shuffle=False, n_splits=n_splits)
          n_samples = input_data.shape[0]
          fold_sizes = (n_samples // n_splits) * np.ones(
              n_splits, dtype=np.int64
          )
          fold_sizes[: n_samples % n_splits] += 1
          current = 0
          scores, predictions = [], np.zeros(input_data.shape[0])
          for fold_size in fold_sizes:
              start, stop = current, current + fold_size
              current = stop
              test_slice = slice(start, stop)
              train_mask = np.ones(input_data.shape[0], bool)
              train_mask[test_slice] = False
              y_train, y_test = labels[train_mask], labels[test_slice]
              estimator.fit(
                  *remove_y(estimator, input_data[train_mask], y_train)
              )
              if hasattr(estimator, "score"):
                  scores.append(
                      estimator.score(
                          *remove_y(
                              estimator, input_data[test_slice], y_test
                          )
                      )
                  )
              if hasattr(estimator, "predict"):
                  predictions[test_slice] = estimator.predict(
                      input_data[test_slice]
                  )
          if hasattr(estimator, "score"):
              assert all(
                  scores
                  == cross_val_score(
                      estimator,
                      *remove_y(estimator, input_data, labels),
                      cv=kfold,
                  )
              )
          if hasattr(estimator, "predict"):
              assert all(
                  predictions
                  == cross_val_predict(
                      estimator,
                      *remove_y(estimator, input_data, labels),
                      cv=kfold,
                  )
              )
  
imports: import pytest
  import unittest
  from sklearn.utils.estimator_checks import check_estimator
  from sklearn.base import TransformerMixin
  from sklearn.pipeline import make_pipeline
  from sklearn.utils import check_random_state
  from metric_learn.sklearn_shims import assert_allclose_dense_sparse, set_random_state, _get_args, is_public_parameter, get_scorer
  from metric_learn import Covariance, LFDA, LMNN, MLKR, NCA, ITML_Supervised, LSML_Supervised, MMC_Supervised, RCA_Supervised, SDML_Supervised, SCML_Supervised
  from sklearn import clone
  import numpy
  from sklearn.model_selection import cross_val_score, cross_val_predict, train_test_split, KFold
  from test.test_utils import metric_learners, ids_metric_learners, mock_preprocessor, tuples_learners, ids_tuples_learners, pairs_learners, ids_pairs_learners, remove_y, metric_learners_pipeline, ids_metric_learners_pipeline
label_desc: Use image node_id 6 for calling a global function with example usage: test_cross_validation_manual_vs_scikit(estimator, build_dataset, with_preprocessor) without return types