class_docstr: Constructs a multivariate normal random variable, based on mean and covariance.
  Can be multivariate, or a batch of multivariate normals
  
  Passing a vector mean corresponds to a multivariate normal.
  Passing a matrix mean corresponds to a batch of multivariate normals.
  
  :param mean: `... x N` mean of mvn distribution.
  :param covariance_matrix: `... x N X N` covariance matrix of mvn distribution.
  :param validate_args: If True, validate `mean` anad `covariance_matrix` arguments. (Default: False.)
  
  :ivar torch.Size base_sample_shape: The shape of a base sample (without
      batching) that is used to generate a single sample.
  :ivar torch.Tensor covariance_matrix: The covariance matrix, represented as a dense :class:`torch.Tensor`
  :ivar ~linear_operator.LinearOperator lazy_covariance_matrix: The covariance matrix, represented
      as a :class:`~linear_operator.LinearOperator`.
  :ivar torch.Tensor mean: The mean.
  :ivar torch.Tensor stddev: The standard deviation.
  :ivar torch.Tensor variance: The variance.
docstr: Generates a `sample_shape` shaped reparameterized sample or `sample_shape`
  shaped batch of reparameterized samples if the distribution parameters
  are batched.
  
  For the MultivariateNormal distribution, this is accomplished through:
  
  .. math::
      \boldsymbol \mu + \mathbf L \boldsymbol \epsilon
  
  where :math:`\boldsymbol \mu \in \mathcal R^N` is the MVN mean,
  :math:`\mathbf L \in \mathcal R^{N \times N}` is a "root" of the
  covariance matrix :math:`\mathbf K` (i.e. :math:`\mathbf L \mathbf
  L^\top = \mathbf K`), and :math:`\boldsymbol \epsilon \in \mathcal R^N` is a
  vector of (approximately) i.i.d. standard Normal random variables.
  
  :param sample_shape: The number of samples to generate. (Default: `torch.Size([])`.)
  :param base_samples: The `*sample_shape x *batch_shape x N` tensor of
      i.i.d. (or approximately i.i.d.) standard Normal samples to
      reparameterize. (Default: None.)
  :return: A `*sample_shape x *batch_shape x N` tensor of i.i.d. reparameterized samples.
docstr_tok: ["Generates","a","`","sample_shape","`","shaped","reparameterized","sample","or","`","sample_shape","`","shaped","batch","of","reparameterized","samples","if","the","distribution","parameters","are","batched",".","For","the","MultivariateNormal","distribution",",","this","is","accomplished","through",":","..","math",":",":","\\boldsymbol","\\mu","+","\\mathbf","L","\\boldsymbol","\\epsilon","where",":","math",":","`","\\boldsymbol","\\mu","\\in","\\mathcal","R^N","`","is","the","MVN","mean",",",":","math",":","`","\\mathbf","L","\\in","\\mathcal","R^","{","N","\\times","N","}","`","is","a","``","root","''","of","the","covariance","matrix",":","math",":","`","\\mathbf","K","`","(","i.e",".",":","math",":","`","\\mathbf","L","\\mathbf","L^\\top","=","\\mathbf","K","`",")",",","and",":","math",":","`","\\boldsymbol","\\epsilon","\\in","\\mathcal","R^N","`","is","a","vector","of","(","approximately",")","i.i.d",".","standard","Normal","random","variables",".",":","param","sample_shape",":","The","number","of","samples","to","generate",".","(","Default",":","`","torch.Size","(","[","]",")","`",".",")",":","param","base_samples",":","The","`","*","sample_shape","x","*","batch_shape","x","N","`","tensor","of","i.i.d",".","(","or","approximately","i.i.d",".",")","standard","Normal","samples","to","reparameterize",".","(","Default",":","None",".",")",":","return",":","A","`","*","sample_shape","x","*","batch_shape","x","N","`","tensor","of","i.i.d",".","reparameterized","samples","."]
code: def rsample(
      self,
      sample_shape: torch.Size = torch.Size(),
      base_samples: Optional[Tensor] = None,
  ) -> Tensor:
      r"""
      Generates a `sample_shape` shaped reparameterized sample or `sample_shape`
      shaped batch of reparameterized samples if the distribution parameters
      are batched.
  
      For the MultivariateNormal distribution, this is accomplished through:
  
      .. math::
          \boldsymbol \mu + \mathbf L \boldsymbol \epsilon
  
      where :math:`\boldsymbol \mu \in \mathcal R^N` is the MVN mean,
      :math:`\mathbf L \in \mathcal R^{N \times N}` is a "root" of the
      covariance matrix :math:`\mathbf K` (i.e. :math:`\mathbf L \mathbf
      L^\top = \mathbf K`), and :math:`\boldsymbol \epsilon \in \mathcal R^N` is a
      vector of (approximately) i.i.d. standard Normal random variables.
  
      :param sample_shape: The number of samples to generate. (Default: `torch.Size([])`.)
      :param base_samples: The `*sample_shape x *batch_shape x N` tensor of
          i.i.d. (or approximately i.i.d.) standard Normal samples to
          reparameterize. (Default: None.)
      :return: A `*sample_shape x *batch_shape x N` tensor of i.i.d. reparameterized samples.
      """
      covar = self.lazy_covariance_matrix
      if base_samples is None:
          # Create some samples
          num_samples = sample_shape.numel() or 1
  
          # Get samples
          res = covar.zero_mean_mvn_samples(
              num_samples
          ) + self.loc.unsqueeze(0)
          res = res.view(sample_shape + self.loc.shape)
  
      else:
          covar_root = covar.root_decomposition().root
  
          # Make sure that the base samples agree with the distribution
          if (
              self.loc.shape != base_samples.shape[-self.loc.dim() :]
              and covar_root.shape[-1] < base_samples.shape[-1]
          ):
              raise RuntimeError(
                  "The size of base_samples (minus sample shape dimensions) should agree with the size "
                  "of self.loc. Expected ...{} but got {}".format(
                      self.loc.shape, base_samples.shape
                  )
              )
  
          # Determine what the appropriate sample_shape parameter is
          sample_shape = base_samples.shape[
              : base_samples.dim() - self.loc.dim()
          ]
  
          # Reshape samples to be batch_size x num_dim x num_samples
          # or num_bim x num_samples
          base_samples = base_samples.view(
              -1, *self.loc.shape[:-1], covar_root.shape[-1]
          )
          base_samples = base_samples.permute(
              *range(1, self.loc.dim() + 1), 0
          )
  
          # Now reparameterize those base samples
          # If necessary, adjust base_samples for rank of root decomposition
          if covar_root.shape[-1] < base_samples.shape[-2]:
              base_samples = base_samples[
                  ..., : covar_root.shape[-1], :
              ]
          elif covar_root.shape[-1] > base_samples.shape[-2]:
              # raise RuntimeError("Incompatible dimension of `base_samples`")
              covar_root = covar_root.transpose(-2, -1)
          res = covar_root.matmul(base_samples) + self.loc.unsqueeze(-1)
  
          # Permute and reshape new samples to be original size
          res = res.permute(-1, *range(self.loc.dim())).contiguous()
          res = res.view(sample_shape + self.loc.shape)
  
      return res
  
imports: from __future__ import annotations
  import math
  import warnings
  from numbers import Number
  from typing import Optional, Tuple, Union
  import torch
  from linear_operator import to_dense, to_linear_operator
  from linear_operator.operators import DiagLinearOperator, LinearOperator, RootLinearOperator
  from torch import Tensor
  from torch.distributions import MultivariateNormal
  from torch.distributions.kl import register_kl
  from torch.distributions.utils import _standard_normal, lazy_property
  from ..None import settings
  from ..utils.warnings import NumericalWarning
  from .distribution import Distribution
label_desc: Use image node_id 14 for calling the MultivariateNormal obj's underlying member method code with example usage: obj.rsample(sample_shape, base_samples) and returns: res