/// <summary> /// Returns a new distribution instance (or populates an existing instance provided by a derived class) with batch dimensions expanded to /// `batch_shape`. This method calls `torch.Tensor.expand()` on the distribution's parameters. As such, this does not allocate new /// memory for the expanded distribution instance. /// </summary> /// <param name="batch_shape">Tthe desired expanded size.</param> /// <param name="instance">new instance provided by subclasses that need to override `.expand`.</param> public override distributions.Distribution expand(long[] batch_shape, distributions.Distribution instance = null) { if (instance != null && !(instance is Multinomial)) { throw new ArgumentException("expand(): 'instance' must be a Multinomial distribution"); } var newDistribution = ((instance == null) ? new Multinomial(total_count, categorical.expand(batch_shape) as Categorical) : instance) as Multinomial; if (newDistribution == instance) { newDistribution.total_count = total_count; newDistribution.categorical = categorical.expand(batch_shape) as Categorical; newDistribution.batch_shape = newDistribution.categorical.batch_shape; var ps = newDistribution.categorical.param_shape; newDistribution.event_shape = new long[] { ps[ps.Length - 1] }; } return(newDistribution); }