code: def test_nodes_values(monotonic_cst, seed):
      # Build a single tree with only one feature, and make sure the nodes
      # values respect the monotonic constraints.
  
      # Considering the following tree with a monotonic POS constraint, we
      # should have:
      #
      #       root
      #      /    \
      #     5     10    # middle = 7.5
      #    / \   / \
      #   a  b  c  d
      #
      # a <= b and c <= d  (assert_children_values_monotonic)
      # a, b <= middle <= c, d (assert_children_values_bounded)
      # a <= b <= c <= d (assert_leaves_values_monotonic)
      #
      # The last one is a consequence of the others, but can't hurt to check
  
      rng = np.random.RandomState(seed)
      n_samples = 1000
      n_features = 1
      X_binned = rng.randint(
          0, 255, size=(n_samples, n_features), dtype=np.uint8
      )
      X_binned = np.asfortranarray(X_binned)
  
      gradients = rng.normal(size=n_samples).astype(G_H_DTYPE)
      hessians = np.ones(shape=1, dtype=G_H_DTYPE)
  
      grower = TreeGrower(
          X_binned,
          gradients,
          hessians,
          monotonic_cst=[monotonic_cst],
          shrinkage=0.1,
      )
      grower.grow()
  
      # grow() will shrink the leaves values at the very end. For our comparison
      # tests, we need to revert the shrinkage of the leaves, else we would
      # compare the value of a leaf (shrunk) with a node (not shrunk) and the
      # test would not be correct.
      for leave in grower.finalized_leaves:
          leave.value /= grower.shrinkage
  
      # We pass undefined binning_thresholds because we won't use predict anyway
      predictor = grower.make_predictor(
          binning_thresholds=np.zeros(
              (X_binned.shape[1], X_binned.max() + 1)
          )
      )
  
      # The consistency of the bounds can only be checked on the tree grower
      # as the node bounds are not copied into the predictor tree. The
      # consistency checks on the values of node children and leaves can be
      # done either on the grower tree or on the predictor tree. We only
      # do those checks on the predictor tree as the latter is derived from
      # the former.
      assert_children_values_monotonic(predictor, monotonic_cst)
      assert_children_values_bounded(grower, monotonic_cst)
      assert_leaves_values_monotonic(predictor, monotonic_cst)
  
file_path: scikit-learn/sklearn/ensemble/_hist_gradient_boosting/tests/test_monotonic_contraints.py
imports: import re
  import numpy
  import pytest
  from sklearn.ensemble import HistGradientBoostingClassifier, HistGradientBoostingRegressor
  from sklearn.ensemble._hist_gradient_boosting.common import G_H_DTYPE, X_BINNED_DTYPE, MonotonicConstraint
  from sklearn.ensemble._hist_gradient_boosting.grower import TreeGrower
  from sklearn.ensemble._hist_gradient_boosting.histogram import HistogramBuilder
  from sklearn.ensemble._hist_gradient_boosting.splitting import Splitter, compute_node_value
  from sklearn.utils._openmp_helpers import _openmp_effective_n_threads
  from sklearn.utils._testing import _convert_container
label_desc: Use image node_id 6 for calling a global function with example usage: test_nodes_values(monotonic_cst, seed) without return types