Hi Pyro people,

I’m trying to implement Dirichlet process clustering in Pyro and started with inference by MCMC sampling. Sadly my code crashes every time, because starting from the second round of MCMC sampling, one of my samples starts changing in size and I cannot find the reason behind that. Here’s a somewhat minimal example:

```
import torch
import pyro
import pyro.distributions as dist
from pyro.infer.mcmc import MCMC, NUTS
data = torch.ones(10)
data[:5] = 0
def model(data):
alpha = pyro.sample("alpha", dist.Normal(5, 2)).expand(1)
counts = torch.empty(0) # atom counts
atoms = torch.empty(0)
saves = torch.zeros(len(data))
for i in range(len(data)):
print()
print(torch.cat((counts, alpha)))
print(dist.Categorical(torch.cat((counts, alpha)) / (torch.sum(counts) + alpha)).sample())
num = pyro.sample("num_{}".format(i), dist.Categorical(torch.cat((counts, alpha)) / (torch.sum(counts) + alpha)))
print(num)
print(num.shape)
if num == len(atoms):
atom = pyro.sample("atom_{}".format(atoms.size()[0]), dist.Normal(torch.zeros(1), 1))
atoms = torch.cat((atoms, atom))
counts = torch.cat((counts, torch.ones(1)))
else:
counts[num] += 1
atom = atoms[num]
saves[i] = pyro.sample("obs_{}".format(i), dist.Normal(atom, .1), obs=data[i])
return saves
nuts_kernel = NUTS(model, jit_compile=False,)
posterior = MCMC(nuts_kernel,
num_samples=500,
warmup_steps=500,
num_chains=1).run(data)
```

Everything starting with the if clause in the model function can be deleted and the problem still shows, it just looks differently so I kept it in for demonstration purpose. The important thing is, in the first round (with the first alpha sample), num is always a 0-d tensor, but with the second round (second alpha), num starts gaining dimensions, which doesn’t work with the num == x clause anymore. Is that a property of the MCMC sampler or did I understand something very wrong? I tried to stick to the MCMC tutorial as much as possible.

Thanks a lot for any help.