code: def test_ndcg_custom_gain():
      def ndcg_gain(y: np.ndarray) -> np.ndarray:
          return np.exp2(y.astype(np.float64)) - 1.0
  
      X, y, q, w = tm.make_ltr(
          n_samples=1024, n_features=4, n_query_groups=3, max_rel=3
      )
      y_gain = ndcg_gain(y)
  
      byxgb = xgboost.XGBRanker(
          tree_method="hist", ndcg_exp_gain=True, n_estimators=10
      )
      byxgb.fit(
          X,
          y,
          qid=q,
          sample_weight=w,
          eval_set=[(X, y)],
          eval_qid=(q,),
          sample_weight_eval_set=(w,),
          verbose=True,
      )
      byxgb_json = json.loads(
          byxgb.get_booster().save_raw(raw_format="json")
      )
  
      bynp = xgboost.XGBRanker(
          tree_method="hist", ndcg_exp_gain=False, n_estimators=10
      )
      bynp.fit(
          X,
          y_gain,
          qid=q,
          sample_weight=w,
          eval_set=[(X, y_gain)],
          eval_qid=(q,),
          sample_weight_eval_set=(w,),
          verbose=True,
      )
      bynp_json = json.loads(
          bynp.get_booster().save_raw(raw_format="json")
      )
  
      # Remove the difference in parameter for comparison
      byxgb_json["learner"]["objective"]["lambdarank_param"][
          "ndcg_exp_gain"
      ] = "0"
      assert byxgb.evals_result() == bynp.evals_result()
      assert byxgb_json == bynp_json
  
imports: import itertools
  import json
  import os
  import shutil
  from typing import Optional
  import numpy
  import pytest
  from hypothesis import given, note, settings
  from scipy.sparse import csr_matrix
  import xgboost
  from xgboost import testing
  from xgboost.testing.data import RelDataCV, simulate_clicks, sort_ltr_samples
  from xgboost.testing.params import lambdarank_parameter_strategy
label_desc: Use image node_id 1 for calling a global function with example usage: test_ndcg_custom_gain() and returns: unknown