# Buggy code
def __init__(
    self,
    n,
    initial_mean,
    initial_diag=None,
    initial_weight=0,
    adaptation_window=100,
    dtype=None,
):
    """Set up a diagonal mass matrix."""
    if initial_diag is not None and initial_diag.ndim != 1:
        raise ValueError("Initial diagonal must be one-dimensional.")
    if initial_mean.ndim != 1:
        raise ValueError("Initial mean must be one-dimensional.")
    if initial_diag is not None and len(initial_diag) != n:
        raise ValueError(
            "Wrong shape for initial_diag: expected %s got %s" % (n, len(initial_diag))
        )
    if len(initial_mean) != n:
        raise ValueError(
            "Wrong shape for initial_mean: expected %s got %s" % (n, len(initial_mean))
        )

    if initial_diag is None:
        initial_diag = np.ones(n, dtype=theano.config.floatX)
        initial_weight = 1

    if dtype is None:
        dtype = theano.config.floatX
    self.dtype = dtype
    self._n = n
    self._var = np.array(initial_diag, dtype=self.dtype, copy=True)
    self._var_theano = theano.shared(self._var)
    self._stds = np.sqrt(initial_diag)
    self._inv_stds = floatX(1.0) / self._stds
    self._foreground_var = _WeightedVariance(
        self._n, initial_mean, initial_diag, initial_weight, self.dtype
    )
    self._background_var = _WeightedVariance(self._n, dtype=self.dtype)
    self._n_samples = 0
    self.adaptation_window = adaptation_window


# Traceback (MissingInputError)
Traceback (most recent call last):

File "<ipython-input-10-aea93a5e8087>", line 5, in <module>
pm.sample(init='adapt_diag')

File "/home/laoj/Documents/Github/pymc3/pymc3/sampling.py", line 247, in sample
progressbar=progressbar, **args)

File "/home/laoj/Documents/Github/pymc3/pymc3/sampling.py", line 729, in init_nuts
vals = distribution.draw_values(model.free_RVs)

File "/home/laoj/Documents/Github/pymc3/pymc3/distributions/distribution.py", line 194, in draw_values
values.append(_draw_value(param, point=point, givens=givens.values()))

File "/home/laoj/Documents/Github/pymc3/pymc3/distributions/distribution.py", line 258, in _draw_value
func = _compile_theano_function(param, variables)

File "/home/laoj/Documents/Github/pymc3/pymc3/memoize.py", line 16, in memoizer
cache[key] = obj(*args, **kwargs)

File "/home/laoj/Documents/Github/pymc3/pymc3/distributions/distribution.py", line 220, in _compile_theano_function
allow_input_downcast=True)

File "/usr/local/lib/python3.5/dist-packages/theano/compile/function.py", line 326, in function
output_keys=output_keys)

File "/usr/local/lib/python3.5/dist-packages/theano/compile/pfunc.py", line 486, in pfunc
output_keys=output_keys)

File "/usr/local/lib/python3.5/dist-packages/theano/compile/function_module.py", line 1808, in orig_function
output_keys=output_keys)

File "/usr/local/lib/python3.5/dist-packages/theano/compile/function_module.py", line 1446, in __init__
accept_inplace)

File "/usr/local/lib/python3.5/dist-packages/theano/compile/function_module.py", line 177, in std_fgraph
update_mapping=update_mapping)

File "/usr/local/lib/python3.5/dist-packages/theano/gof/fg.py", line 175, in __init__
self.__import_r__(output, reason="init")

File "/usr/local/lib/python3.5/dist-packages/theano/gof/fg.py", line 356, in __import_r__
raise MissingInputError("Undeclared input", variable=variable)

MissingInputError: Undeclared input

# Fixed code
def __init__(
    self,
    n,
    initial_mean,
    initial_diag=None,
    initial_weight=0,
    adaptation_window=100,
    dtype=None,
):
    """Set up a diagonal mass matrix."""
    if initial_diag is not None and initial_diag.ndim != 1:
        raise ValueError("Initial diagonal must be one-dimensional.")
    if initial_mean.ndim != 1:
        raise ValueError("Initial mean must be one-dimensional.")
    if initial_diag is not None and len(initial_diag) != n:
        raise ValueError(
            "Wrong shape for initial_diag: expected %s got %s" % (n, len(initial_diag))
        )
    if len(initial_mean) != n:
        raise ValueError(
            "Wrong shape for initial_mean: expected %s got %s" % (n, len(initial_mean))
        )

    if dtype is None:
        dtype = theano.config.floatX

    if initial_diag is None:
        initial_diag = np.ones(n, dtype=dtype)
        initial_weight = 1

    self.dtype = dtype
    self._n = n
    self._var = np.array(initial_diag, dtype=self.dtype, copy=True)
    self._var_theano = theano.shared(self._var)
    self._stds = np.sqrt(initial_diag)
    self._inv_stds = floatX(1.0) / self._stds
    self._foreground_var = _WeightedVariance(
        self._n, initial_mean, initial_diag, initial_weight, self.dtype
    )
    self._background_var = _WeightedVariance(self._n, dtype=self.dtype)
    self._n_samples = 0
    self.adaptation_window = adaptation_window