code: def base_conditional_with_lm(
      Kmn: tf.Tensor,
      Lm: tf.Tensor,
      Knn: tf.Tensor,
      f: tf.Tensor,
      *,
      full_cov: bool = False,
      q_sqrt: Optional[tf.Tensor] = None,
      white: bool = False,
  ) -> MeanAndVariance:
      r"""
      Has the same functionality as the `base_conditional` function, except that instead of
      `Kmm` this function accepts `Lm`, which is the Cholesky decomposition of `Kmm`.
  
      This allows `Lm` to be precomputed, which can improve performance.
      """
      if q_sqrt is not None:
          cs(
              q_sqrt,
              "[M, R]" if q_sqrt.shape.ndims == 2 else "[R, M, M]",
          )
  
      # compute kernel stuff
      num_func = tf.shape(f)[-1]  # R
      N = tf.shape(Kmn)[-1]
      M = tf.shape(f)[-2]
  
      # get the leading dims in Kmn to the front of the tensor
      # if Kmn has rank two, i.e. [M, N], this is the identity op.
      K = tf.rank(Kmn)
      perm = tf.concat(
          [
              tf.reshape(
                  tf.range(1, K - 1), [K - 2]
              ),  # leading dims (...)
              tf.reshape(0, [1]),  # [M]
              tf.reshape(K - 1, [1]),
          ],
          0,
      )  # [N]
      Kmn = tf.transpose(Kmn, perm)  # [..., M, N]
  
      leading_dims = tf.shape(Kmn)[:-2]
  
      # Compute the projection matrix A
      Lm = tf.broadcast_to(
          Lm, tf.concat([leading_dims, tf.shape(Lm)], 0)
      )  # [..., M, M]
      A = tf.linalg.triangular_solve(Lm, Kmn, lower=True)  # [..., M, N]
  
      # compute the covariance due to the conditioning
      if full_cov:
          fvar = Knn - tf.linalg.matmul(
              A, A, transpose_a=True
          )  # [..., N, N]
          cov_shape = tf.concat([leading_dims, [num_func, N, N]], 0)
          fvar = tf.broadcast_to(
              tf.expand_dims(fvar, -3), cov_shape
          )  # [..., R, N, N]
      else:
          fvar = Knn - tf.reduce_sum(tf.square(A), -2)  # [..., N]
          cov_shape = tf.concat(
              [leading_dims, [num_func, N]], 0
          )  # [..., R, N]
          fvar = tf.broadcast_to(
              tf.expand_dims(fvar, -2), cov_shape
          )  # [..., R, N]
  
      # another backsubstitution in the unwhitened case
      if not white:
          A = tf.linalg.triangular_solve(
              tf.linalg.adjoint(Lm), A, lower=False
          )
  
      # construct the conditional mean
      f_shape = tf.concat(
          [leading_dims, [M, num_func]], 0
      )  # [..., M, R]
      f = tf.broadcast_to(f, f_shape)  # [..., M, R]
      fmean = tf.linalg.matmul(A, f, transpose_a=True)  # [..., N, R]
  
      if q_sqrt is not None:
          q_sqrt_dims = q_sqrt.shape.ndims
          if q_sqrt_dims == 2:
              LTA = A * tf.expand_dims(
                  tf.transpose(q_sqrt), 2
              )  # [R, M, N]
          elif q_sqrt_dims == 3:
              L = tf.linalg.band_part(
                  q_sqrt, -1, 0
              )  # force lower triangle # [R, M, M]
              L_shape = tf.shape(L)
              L = tf.broadcast_to(
                  L, tf.concat([leading_dims, L_shape], 0)
              )
  
              shape = tf.concat(
                  [leading_dims, [num_func, M, N]], axis=0
              )
              A_tiled = tf.broadcast_to(tf.expand_dims(A, -3), shape)
              LTA = tf.linalg.matmul(
                  L, A_tiled, transpose_a=True
              )  # [R, M, N]
          else:  # pragma: no cover
              raise ValueError(
                  "Bad dimension for q_sqrt: %s"
                  % str(q_sqrt.shape.ndims)
              )
  
          if full_cov:
              fvar = fvar + tf.linalg.matmul(
                  LTA, LTA, transpose_a=True
              )  # [R, N, N]
          else:
              fvar = fvar + tf.reduce_sum(tf.square(LTA), -2)  # [R, N]
  
      if not full_cov:
          fvar = tf.linalg.adjoint(fvar)  # [N, R]
  
      return fmean, fvar
  
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 2 for calling a global function with example usage: base_conditional_with_lm(Kmn, Lm, Knn, f) and returns: fmean,  fvar