code: def test_masked_mixture_multivariate(sample_shape, batch_shape):
      event_shape = torch.Size((8,))
      component0 = dist.MultivariateNormal(
          torch.zeros(event_shape), torch.eye(event_shape[0])
      )
      component1 = dist.Uniform(
          torch.zeros(event_shape), torch.ones(event_shape)
      ).to_event(1)
      if batch_shape:
          component0 = component0.expand_by(batch_shape)
          component1 = component1.expand_by(batch_shape)
      mask = torch.empty(batch_shape).bernoulli_(0.5).bool()
      d = dist.MaskedMixture(mask, component0, component1)
      assert d.batch_shape == batch_shape
      assert d.event_shape == event_shape
  
      assert d.sample().shape == batch_shape + event_shape
      assert d.mean.shape == batch_shape + event_shape
      assert d.variance.shape == batch_shape + event_shape
      x = d.sample(sample_shape)
      assert x.shape == sample_shape + batch_shape + event_shape
  
      log_prob = d.log_prob(x)
      assert log_prob.shape == sample_shape + batch_shape
      assert not torch_isnan(log_prob)
      log_prob_0 = component0.log_prob(x)
      log_prob_1 = component1.log_prob(x)
      mask = mask.expand(sample_shape + batch_shape)
      assert_equal(log_prob[mask], log_prob_1[mask])
      assert_equal(log_prob[~mask], log_prob_0[~mask])
  
file_path: pyro/tests/distributions/test_mixture.py
imports: import pytest
  import torch
  import pyro.distributions
  from pyro.distributions.util import broadcast_shape
  from pyro.util import torch_isnan
  from tests.common import assert_equal
label_desc: Use image node_id 2 for calling a global function with example usage: test_masked_mixture_multivariate(sample_shape, batch_shape) without return types