code: def test_switched_likelihood_with_vgp() -> None:
      """
      Reproduces the bug in https://github.com/GPflow/GPflow/issues/951
      """
      X = np.random.randn(12 + 15, 1)
      Y = np.random.randn(12 + 15, 1)
      idx: AnyNDArray = np.array([0] * 12 + [1] * 15)
      Y_aug = np.c_[Y, idx]
      assert Y_aug.shape == (12 + 15, 2)
  
      kernel = gpflow.kernels.Matern32()
      likelihood = gpflow.likelihoods.SwitchedLikelihood(
          [StudentT(), StudentT()]
      )
      model = gpflow.models.VGP(
          (X, Y_aug), kernel=kernel, likelihood=likelihood
      )
      # without bugfix, optimization errors out
      opt = gpflow.optimizers.Scipy()
      opt.minimize(
          model.training_loss,
          model.trainable_variables,
          options=dict(maxiter=1),
      )
  
file_path: GPflow/tests/gpflow/likelihoods/test_switched_likelihood.py
imports: from typing import Sequence
  import numpy
  import pytest
  import tensorflow
  from numpy.testing import assert_allclose
  import gpflow
  from gpflow.base import AnyNDArray, Parameter, TensorType
  from gpflow.inducing_variables import InducingPoints
  from gpflow.likelihoods import Gaussian, StudentT, SwitchedLikelihood
label_desc: Use image node_id 4 for calling a global function with example usage: test_switched_likelihood_with_vgp() without return types