code: def test_tweedie_log_identity_consistency(p):
      """Test for identical losses when only the link function is different."""
      half_tweedie_log = HalfTweedieLoss(power=p)
      half_tweedie_identity = HalfTweedieLossIdentity(power=p)
      n_samples = 10
      y_true, raw_prediction = random_y_true_raw_prediction(
          loss=half_tweedie_log, n_samples=n_samples, seed=42
      )
      y_pred = half_tweedie_log.link.inverse(
          raw_prediction
      )  # exp(raw_prediction)
  
      # Let's compare the loss values, up to some constant term that is dropped
      # in HalfTweedieLoss but not in HalfTweedieLossIdentity.
      loss_log = half_tweedie_log.loss(
          y_true=y_true, raw_prediction=raw_prediction
      ) + half_tweedie_log.constant_to_optimal_zero(y_true)
      loss_identity = half_tweedie_identity.loss(
          y_true=y_true, raw_prediction=y_pred
      ) + half_tweedie_identity.constant_to_optimal_zero(y_true)
      # Note that HalfTweedieLoss ignores different constant terms than
      # HalfTweedieLossIdentity. Constant terms means terms not depending on
      # raw_prediction. By adding these terms, `constant_to_optimal_zero`, both losses
      # give the same values.
      assert_allclose(loss_log, loss_identity)
  
      # For gradients and hessians, the constant terms do not matter. We have, however,
      # to account for the chain rule, i.e. with x=raw_prediction
      #     gradient_log(x) = d/dx loss_log(x)
      #                     = d/dx loss_identity(exp(x))
      #                     = exp(x) * gradient_identity(exp(x))
      # Similarly,
      #     hessian_log(x) = exp(x) * gradient_identity(exp(x))
      #                    + exp(x)**2 * hessian_identity(x)
      gradient_log, hessian_log = half_tweedie_log.gradient_hessian(
          y_true=y_true, raw_prediction=raw_prediction
      )
      (
          gradient_identity,
          hessian_identity,
      ) = half_tweedie_identity.gradient_hessian(
          y_true=y_true, raw_prediction=y_pred
      )
      assert_allclose(gradient_log, y_pred * gradient_identity)
      assert_allclose(
          hessian_log,
          y_pred * gradient_identity + y_pred**2 * hessian_identity,
      )
  
imports: import pickle
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_equal
  from pytest import approx
  from scipy.optimize import LinearConstraint, minimize, minimize_scalar, newton
  from scipy.special import logsumexp
  from sklearn._loss.link import IdentityLink, _inclusive_low_high
  from sklearn._loss.loss import _LOSSES, AbsoluteError, BaseLoss, HalfBinomialLoss, HalfGammaLoss, HalfMultinomialLoss, HalfPoissonLoss, HalfSquaredError, HalfTweedieLoss, HalfTweedieLossIdentity, HuberLoss, PinballLoss
  from sklearn.utils import _IS_WASM, assert_all_finite
  from sklearn.utils._testing import create_memmap_backed_data, skip_if_32bit
label_desc: Use image node_id 26 for calling a global function with example usage: test_tweedie_log_identity_consistency(p) without return types