class_docstr: Distribution over IID samples of a given shape.
  
  Given random variable `X`, one may make a new random variable by concatenating
  samples.  For example, if `X1` and `X2` are iid `Normal(0, 1)` samples then
  `[X1, X2]` is a bi-variate normal random vector.
  
  #### Mathematical Details
  
  With `p` the probability density/mass of the function being sampled, and
  `n` the samples taken, the density/mass of this distribution is
  
  ```none
  p(x) = prod{ p(x[i]) : i = 0, ..., (n - 1) }
  ```
  
  #### Examples
  
  ```python
  tfd = tfp.distributions
  
  # Example 1: Five scalar draws.
  
  s = tfd.Sample(
        tfd.Normal(loc=0, scale=1),
        sample_shape=5)
  x = s.sample()
  # ==> x.shape: [5]
  
  lp = s.log_prob(x)
  # ==> lp.shape: []
  #     Equivalently: tf.reduce_sum(s.distribution.log_prob(x), axis=0)
  #
  # `Sample.log_prob` computes the per-{sample, batch} `log_prob`s then sums
  # over the `Sample.sample_shape` dimensions. In the above example `log_prob`
  # dims `0` is summed out, since it is the `sample_shape` dimension.
  
  # Example 2: `[5, 4]`-draws of a bivariate Normal.
  
  mvn = tfd.MultivariateNormalDiag(loc=tf.zeros([3, 2]))
  mvn.batch_shape ==> [3]
  mvn.event_shape ==> [2]
  
  s = tfd.Sample(mvn, sample_shape=[5, 4])
  s.batch_shape ==> [3]
  s.event_shape ==> [5, 4, 2]
  
  x = s.sample([6, 1])
  # ==> x.shape: [6, 1, 3, 5, 4, 2]
  
  lp = s.log_prob(x)
  # ==> lp.shape: [6, 1, 3]
  #
  # `s.log_prob` will reduce over the event dims of `mvn`, i.e., dim `5`, then
  # sums over `s.sample_shape` dims `[3, 4]` corresponding to shape (slice)
  # `[5, 4]`.
  ```
class_docstr_tok: ["Distribution","over","IID","samples","of","a","given","shape",".","Given","random","variable","`","X","`",",","one","may","make","a","new","random","variable","by","concatenating","samples",".","For","example",",","if","`","X1","`","and","`","X2","`","are","iid","`","Normal","(","0",",","1",")","`","samples","then","`","[","X1",",","X2","]","`","is","a","bi-variate","normal","random","vector",".","#","#","#","#","Mathematical","Details","With","`","p","`","the","probability","density\/mass","of","the","function","being","sampled",",","and","`","n","`","the","samples","taken",",","the","density\/mass","of","this","distribution","is","``","`","none","p","(","x",")","=","prod","{","p","(","x","[","i","]",")",":","i","=","0",",","...",",","(","n","-","1",")","}","``","`","#","#","#","#","Examples","``","`","python","tfd","=","tfp.distributions","#","Example","1",":","Five","scalar","draws",".","s","=","tfd.Sample","(","tfd.Normal","(","loc=0",",","scale=1",")",",","sample_shape=5",")","x","=","s.sample","(",")","#","==",">","x.shape",":","[","5","]","lp","=","s.log_prob","(","x",")","#","==",">","lp.shape",":","[","]","#","Equivalently",":","tf.reduce_sum","(","s.distribution.log_prob","(","x",")",",","axis=0",")","#","#","`","Sample.log_prob","`","computes","the","per-","{","sample",",","batch","}","`","log_prob","`","s","then","sums","#","over","the","`","Sample.sample_shape","`","dimensions",".","In","the","above","example","`","log_prob","`","#","dims","`","0","`","is","summed","out",",","since","it","is","the","`","sample_shape","`","dimension",".","#","Example","2",":","`","[","5",",","4","]","`","-draws","of","a","bivariate","Normal",".","mvn","=","tfd.MultivariateNormalDiag","(","loc=tf.zeros","(","[","3",",","2","]",")",")","mvn.batch_shape","==",">","[","3","]","mvn.event_shape","==",">","[","2","]","s","=","tfd.Sample","(","mvn",",","sample_shape=","[","5",",","4","]",")","s.batch_shape","==",">","[","3","]","s.event_shape","==",">","[","5",",","4",",","2","]","x","=","s.sample","(","[","6",",","1","]",")","#","==",">","x.shape",":","[","6",",","1",",","3",",","5",",","4",",","2","]","lp","=","s.log_prob","(","x",")","#","==",">","lp.shape",":","[","6",",","1",",","3","]","#","#","`","s.log_prob","`","will","reduce","over","the","event","dims","of","`","mvn","`",",","i.e.",",","dim","`","5","`",",","then","#","sums","over","`","s.sample_shape","`","dims","`","[","3",",","4","]","`","corresponding","to","shape","(","slice",")","#","`","[","5",",","4","]","`",".","``","`"]
docstr: Construct the `Sample` distribution.
  
  The `event_shape` and `batch_shape` of the `Sample` distribution are
  determined by the args `distribution` and `sample_shape`:
  
  ```
  s = Sample(distribution, sample_shape)
  ==> s.batch_shape: distribution.batch_shape
  ==> s.event_shape: sample_shape + distribution.event_shape
  ```
  
  Args:
    distribution: The base distribution instance to transform. Typically an
      instance of `Distribution`.
    sample_shape: `int` scalar or vector `Tensor` representing the shape of a
      single sample.
    validate_args: Python `bool`.  Whether to validate input with asserts.
      If `validate_args` is `False`, and the inputs are invalid,
      correct behavior is not guaranteed.
    experimental_use_kahan_sum: Python `bool`. When `True`, we use Kahan
      summation to aggregate independent underlying log_prob values, which
      improves against the precision of a naive float32 sum. This can be
      noticeable in particular for large dimensions in float32. See CPU caveat
      on `tfp.math.reduce_kahan_sum`.
    name: The name for ops managed by the distribution.
      Default value: `None` (i.e., `'Sample' + distribution.name`).
docstr_tok: ["Construct","the","`","Sample","`","distribution",".","The","`","event_shape","`","and","`","batch_shape","`","of","the","`","Sample","`","distribution","are","determined","by","the","args","`","distribution","`","and","`","sample_shape","`",":","``","`","s","=","Sample","(","distribution",",","sample_shape",")","==",">","s.batch_shape",":","distribution.batch_shape","==",">","s.event_shape",":","sample_shape","+","distribution.event_shape","``","`","Args",":","distribution",":","The","base","distribution","instance","to","transform",".","Typically","an","instance","of","`","Distribution","`",".","sample_shape",":","`","int","`","scalar","or","vector","`","Tensor","`","representing","the","shape","of","a","single","sample",".","validate_args",":","Python","`","bool","`",".","Whether","to","validate","input","with","asserts",".","If","`","validate_args","`","is","`","False","`",",","and","the","inputs","are","invalid",",","correct","behavior","is","not","guaranteed",".","experimental_use_kahan_sum",":","Python","`","bool","`",".","When","`","True","`",",","we","use","Kahan","summation","to","aggregate","independent","underlying","log_prob","values",",","which","improves","against","the","precision","of","a","naive","float32","sum",".","This","can","be","noticeable","in","particular","for","large","dimensions","in","float32",".","See","CPU","caveat","on","`","tfp.math.reduce_kahan_sum","`",".","name",":","The","name","for","ops","managed","by","the","distribution",".","Default","value",":","`","None","`","(","i.e.",",","`","'Sample","'","+","distribution.name","`",")","."]
code: def __init__(
      self,
      distribution,
      sample_shape=(),
      validate_args=False,
      experimental_use_kahan_sum=False,
      name=None,
  ):
      """Construct the `Sample` distribution.
  
      The `event_shape` and `batch_shape` of the `Sample` distribution are
      determined by the args `distribution` and `sample_shape`:
  
      ```
      s = Sample(distribution, sample_shape)
      ==> s.batch_shape: distribution.batch_shape
      ==> s.event_shape: sample_shape + distribution.event_shape
      ```
  
      Args:
        distribution: The base distribution instance to transform. Typically an
          instance of `Distribution`.
        sample_shape: `int` scalar or vector `Tensor` representing the shape of a
          single sample.
        validate_args: Python `bool`.  Whether to validate input with asserts.
          If `validate_args` is `False`, and the inputs are invalid,
          correct behavior is not guaranteed.
        experimental_use_kahan_sum: Python `bool`. When `True`, we use Kahan
          summation to aggregate independent underlying log_prob values, which
          improves against the precision of a naive float32 sum. This can be
          noticeable in particular for large dimensions in float32. See CPU caveat
          on `tfp.math.reduce_kahan_sum`.
        name: The name for ops managed by the distribution.
          Default value: `None` (i.e., `'Sample' + distribution.name`).
      """
      parameters = dict(locals())
      self._experimental_use_kahan_sum = experimental_use_kahan_sum
      with tf.name_scope(name or "Sample" + distribution.name) as name:
          self._distribution = distribution
          self._sample_shape = tensor_util.convert_nonref_to_tensor(
              sample_shape,
              dtype_hint=tf.int32,
              name="sample_shape",
              as_shape_tensor=True,
          )
          super(_Sample, self).__init__(
              dtype=self._distribution.dtype,
              reparameterization_type=self._distribution.reparameterization_type,
              validate_args=validate_args,
              allow_nan_stats=self._distribution.allow_nan_stats,
              parameters=parameters,
              name=name,
          )
  
imports: import functools
  import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.bijectors import bijector
  from tensorflow_probability.python.distributions import distribution
  from tensorflow_probability.python.distributions import kullback_leibler
  from tensorflow_probability.python.distributions import log_prob_ratio
  from tensorflow_probability.python.internal import assert_util
  from tensorflow_probability.python.internal import auto_composite_tensor
  from tensorflow_probability.python.internal import dtype_util
  from tensorflow_probability.python.internal import parameter_properties
  from tensorflow_probability.python.internal import prefer_static
  from tensorflow_probability.python.internal import tensor_util
  from tensorflow_probability.python.internal import tensorshape_util
  from tensorflow_probability.python.math import generic
label_desc: Use image node_id 1 to create a new _Sample object from inherited base classes: distribution_lib with example: obj = _Sample(distribution, sample_shape, validate_args, experimental_use_kahan_sum, name)