code: def sample_mvn(
      mean: tf.Tensor,
      cov: tf.Tensor,
      full_cov: bool,
      num_samples: Optional[int] = None,
  ) -> tf.Tensor:
      """
      Returns a sample from a D-dimensional Multivariate Normal distribution.
  
      :return: sample from the MVN
      """
      mean_shape = tf.shape(mean)
      S = num_samples if num_samples is not None else 1
      D = mean_shape[-1]
      leading_dims = mean_shape[:-2]
  
      if not full_cov:
          # mean: [..., N, D] and cov [..., N, D]
          eps_shape = tf.concat([leading_dims, [S], mean_shape[-2:]], 0)
          eps = tf.random.normal(
              eps_shape, dtype=default_float()
          )  # [..., S, N, D]
          samples = (
              mean[..., None, :, :]
              + tf.sqrt(cov)[..., None, :, :] * eps
          )  # [..., S, N, D]
  
      else:
          # mean: [..., N, D] and cov [..., N, D, D]
          jittermat = (
              tf.eye(
                  D, batch_shape=mean_shape[:-1], dtype=default_float()
              )
              * default_jitter()
          )  # [..., N, D, D]
          eps_shape = tf.concat([mean_shape, [S]], 0)
          eps = tf.random.normal(
              eps_shape, dtype=default_float()
          )  # [..., N, D, S]
          chol = tf.linalg.cholesky(cov + jittermat)  # [..., N, D, D]
          samples = mean[..., None] + tf.linalg.matmul(
              chol, eps
          )  # [..., N, D, S]
          samples = leading_transpose(
              samples, [..., -1, -3, -2]
          )  # [..., S, N, D]
  
      if num_samples is None:
          return tf.squeeze(samples, axis=-3)  # [..., N, D]
      return samples
  
file_path: GPflow/gpflow/conditionals/util.py
imports: from typing import Optional, Tuple
  import tensorflow
  from check_shapes import check_shape
  from check_shapes import check_shapes
  from ..base import MeanAndVariance
  from ..config import default_float, default_jitter
  from ..utilities.ops import leading_transpose
label_desc: Use image node_id 3 for calling a global function with example usage: sample_mvn(mean, cov, full_cov, num_samples) and returns: samples, tf