code: def test_broadcasting_mix_latent_gps(
      full_cov: bool, full_output_cov: bool
  ) -> None:
      S, N = 7, 20  # batch size, num data points
      P, L = 10, 5  # observation dimensionality, num latent GPs
      W = np.random.randn(P, L)  # mixing matrix
      g_mu = np.random.randn(S, N, L)  # mean of the L latent GPs
  
      g_sqrt_diag: AnyNDArray = np.tril(
          np.random.randn(S * L, N, N), -1
      )  # [L*S, N, N]
      g_sqrt_diag = np.reshape(g_sqrt_diag, [L, S, N, N])
      g_var_diag: AnyNDArray = g_sqrt_diag @ np.transpose(
          g_sqrt_diag, [0, 1, 3, 2]
      )  # [L, S, N, N]
      g_var = np.zeros([S, N, L, N, L])
      for l in range(L):
          g_var[:, :, l, :, l] = g_var_diag[
              l, :, :, :
          ]  # replace diagonal elements by g_var_diag
  
      # reference numpy implementation for mean
      f_mu_ref: AnyNDArray = g_mu @ W.T  # [S, N, P]
  
      # reference numpy implementation for variance
      g_var_tmp = np.transpose(
          g_var, [0, 1, 3, 2, 4]
      )  # [S, N, N, L, L]
      f_var_ref: AnyNDArray = W @ g_var_tmp @ W.T  # [S, N, N, P, P]
      f_var_ref = np.transpose(
          f_var_ref, [0, 1, 3, 2, 4]
      )  # [S, N, P, N, P]
  
      if not full_cov:
          g_var_diag = np.array(
              [g_var_diag[:, :, n, n] for n in range(N)]
          )  # [N, L, S]
          g_var_diag = np.transpose(g_var_diag, [2, 0, 1])  # [S, N, L]
  
      # run gpflow's implementation
      f_mu, f_var = mix_latent_gp(
          tf.convert_to_tensor(W),
          tf.convert_to_tensor(g_mu),
          tf.convert_to_tensor(g_var_diag),
          full_cov,
          full_output_cov,
      )
  
      # we strip down f_var_ref to the elements we need
      if not full_output_cov and not full_cov:
          f_var_ref = np.array(
              [f_var_ref[:, :, p, :, p] for p in range(P)]
          )  # [P, S, N, N]
          f_var_ref = np.array(
              [f_var_ref[:, :, n, n] for n in range(N)]
          )  # [N, P, S]
          f_var_ref = np.transpose(f_var_ref, [2, 0, 1])  # [S, N, P]
  
      elif not full_output_cov and full_cov:
          f_var_ref = np.array(
              [f_var_ref[:, :, p, :, p] for p in range(P)]
          )  # [P, S, N, N]
          f_var_ref = np.transpose(
              f_var_ref, [1, 0, 2, 3]
          )  # [S, P, N, N]
  
      elif full_output_cov and not full_cov:
          f_var_ref = np.array(
              [f_var_ref[:, n, :, n, :] for n in range(N)]
          )  # [N, S, P, P]
          f_var_ref = np.transpose(
              f_var_ref, [1, 0, 2, 3]
          )  # [S, N, P, P]
  
      else:
          pass  # f_var_ref has shape [..., N, P, N, P] as expected
  
      # check equality for mean and variance of f
      assert_allclose(f_mu_ref, f_mu)
      assert_allclose(f_var_ref, f_var)
  
file_path: GPflow/tests/gpflow/conditionals/test_broadcasted_conditionals.py
imports: from typing import cast
  import numpy
  import pytest
  import tensorflow
  from numpy.testing import assert_allclose
  import gpflow
  import gpflow.inducing_variables.multioutput
  import gpflow.kernels.multioutput
  from gpflow.base import AnyNDArray, SamplesMeanAndVariance
  from gpflow.conditionals import sample_conditional
  from gpflow.conditionals.util import mix_latent_gp
label_desc: Use image node_id 2 for calling a global function with example usage: test_broadcasting_mix_latent_gps(full_cov, full_output_cov) without return types