# Path: gelato/specs/dist.py
# def get_default_spec(testval=None):
#     # to avoid init collision
#     cp = copy.deepcopy(_default_spec)
#     if testval is None and cp.testval is None:
#         cp.testval = get_default_testval()
#     elif testval is not None:
#         cp.testval = testval
#     else:
#         pass
#     return cp
# 
# class FlatSpec(PartialSpec):
#     spec = pm.Flat
#     __doc__ = """Gelato DistSpec with {dist} prior\n\n{doc}""".format(
#         dist=spec.__name__,
#         doc=spec.__doc__
#     )
# 
#     def __init__(self):
#         super(FlatSpec, self).__init__(testval=init.Uniform(1))
# 
# Path: gelato/specs/base.py
# class DistSpec(SpecVar):
#     """Spec based on pymc3 distributions
# 
#     All specs support lazy evaluation, see Usage
# 
#     Parameters
#     ----------
#     distcls : pymc3.Distribution
#     args : args for `distcls`
#     kwargs : kwargs for `distcls`
# 
#     Usage
#     -----
#     >>> spec = DistSpec(Normal, mu=0, sd=DistSpec(Lognormal, 0, 1))
#     >>> spec += (NormalSpec() + LaplaceSpec()) / 100 - NormalSpec()
#     >>> with Model():
#     ...     prior_expr = spec((10, 10), name='silly_prior')
# 
#     """
#     def __init__(self, distcls, *args, **kwargs):
#         if not isinstance(distcls, type) and issubclass(distcls, pm.Distribution):
#             raise ValueError('We can deal with pymc3 '
#                              'distributions only, got {!r} instead'
#                              .format(distcls))
#         self.testval = kwargs.pop('testval', None)
#         self.tag = kwargs.get('tag', 'default')
#         self.args = args
#         self.kwargs = kwargs
#         self.distcls = distcls
# 
#     def __call__(self, shape, name=None, memo=None):
#         memo, shape = self._prepare(memo, shape)
#         if name is None:
#             name = self.auto()
#         shape, tag = self._get_shape(shape)
#         if id(self) ^ hash(tag) in memo:
#             return memo[id(self) ^ hash(tag)]
#         model = pm.modelcontext(None)
#         called_args = self._call_args(self.args, name, shape, memo)
#         called_kwargs = self._call_kwargs(self.kwargs, name, shape, memo)
#         called_kwargs.update(shape=shape['default'])
#         val = model.Var(
#             name, self.distcls.dist(
#                 *called_args,
#                 dtype=theano.config.floatX,
#                 **called_kwargs
#             ),
#         )
#         if self.testval is None:
#             val.tag.test_value = get_default_testval()(shape['default']).astype(val.dtype)
#         elif isinstance(self.testval, str) and self.testval == 'random':
#             val.tag.test_value = val.random(size=shape['default']).astype(val.dtype)
#         else:
#             val.tag.test_value = self.testval(shape['default']).astype(val.dtype)
#         memo[id(self) ^ hash(tag)] = val
#         return memo[id(self) ^ hash(tag)]
# 
#     def __repr__(self):
#         if self._shape != -1:
#             sh = '; '+str(self._shape)
#         else:
#             sh = ''
#         template = '<{cls}: {args!r}; {kwargs!r}'+sh+'>'
#         return template.format(cls=self.distcls.__name__,
#                                args=self.args,
#                                kwargs=self.kwargs)


import functools
import inspect
import six
import lasagne.layers.base
import pymc3 as pm
from pymc3.memoize import hashable
from gelato.specs.dist import get_default_spec, FlatSpec
from gelato.specs.base import DistSpec
        from gelato.layers.helper import find_parent
        def wrap_init(__init__):
            @functools.wraps(__init__)
            def wrapped(self, *args, **kwargs):
                name = kwargs.get('name')
                self._fingerprint = hashable(self.parent)
                pm.Model.__init__(self, name)
                __init__(self, *args, **kwargs)
            return wrapped

        # wrap new for new class
        def wrap_new(__new__):
            @functools.wraps(__new__)
            def wrapped(_cls_, *args, **kwargs):
                parent = kwargs.get('model', None)
                if parent is None and not issubclass(_cls_, lasagne.layers.InputLayer):
                    incoming = kwargs.get('incoming',
                                          kwargs.get('incomings',
                                                     args[1]))
                    parent = find_parent(incoming)
                kwargs['model'] = parent
                instance = __new__(_cls_, *args, **kwargs)
                return instance
            return classmethod(wrapped)

        cls.__init__ = wrap_init(cls.__init__)
        cls.__new__ = wrap_new(cls.__new__)

        def add_param(self, spec, shape, name=None, **tags):
            if tags.get('trainable', True):
                if tags.get('regularizable', True):

# Path: gelato/specs/dist.py
# def get_default_spec(testval=None):
#     # to avoid init collision
#     cp = copy.deepcopy(_default_spec)
#     if testval is None and cp.testval is None:
#         cp.testval = get_default_testval()
#     elif testval is not None:
#         cp.testval = testval
#     else:
#         pass
#     return cp
# 
# class FlatSpec(PartialSpec):
#     spec = pm.Flat
#     __doc__ = """Gelato DistSpec with {dist} prior\n\n{doc}""".format(
#         dist=spec.__name__,
#         doc=spec.__doc__
#     )
# 
#     def __init__(self):
#         super(FlatSpec, self).__init__(testval=init.Uniform(1))
# 
# Path: gelato/specs/base.py
# class DistSpec(SpecVar):
#     """Spec based on pymc3 distributions
# 
#     All specs support lazy evaluation, see Usage
# 
#     Parameters
#     ----------
#     distcls : pymc3.Distribution
#     args : args for `distcls`
#     kwargs : kwargs for `distcls`
# 
#     Usage
#     -----
#     >>> spec = DistSpec(Normal, mu=0, sd=DistSpec(Lognormal, 0, 1))
#     >>> spec += (NormalSpec() + LaplaceSpec()) / 100 - NormalSpec()
#     >>> with Model():
#     ...     prior_expr = spec((10, 10), name='silly_prior')
# 
#     """
#     def __init__(self, distcls, *args, **kwargs):
#         if not isinstance(distcls, type) and issubclass(distcls, pm.Distribution):
#             raise ValueError('We can deal with pymc3 '
#                              'distributions only, got {!r} instead'
#                              .format(distcls))
#         self.testval = kwargs.pop('testval', None)
#         self.tag = kwargs.get('tag', 'default')
#         self.args = args
#         self.kwargs = kwargs
#         self.distcls = distcls
# 
#     def __call__(self, shape, name=None, memo=None):
#         memo, shape = self._prepare(memo, shape)
#         if name is None:
#             name = self.auto()
#         shape, tag = self._get_shape(shape)
#         if id(self) ^ hash(tag) in memo:
#             return memo[id(self) ^ hash(tag)]
#         model = pm.modelcontext(None)
#         called_args = self._call_args(self.args, name, shape, memo)
#         called_kwargs = self._call_kwargs(self.kwargs, name, shape, memo)
#         called_kwargs.update(shape=shape['default'])
#         val = model.Var(
#             name, self.distcls.dist(
#                 *called_args,
#                 dtype=theano.config.floatX,
#                 **called_kwargs
#             ),
#         )
#         if self.testval is None:
#             val.tag.test_value = get_default_testval()(shape['default']).astype(val.dtype)
#         elif isinstance(self.testval, str) and self.testval == 'random':
#             val.tag.test_value = val.random(size=shape['default']).astype(val.dtype)
#         else:
#             val.tag.test_value = self.testval(shape['default']).astype(val.dtype)
#         memo[id(self) ^ hash(tag)] = val
#         return memo[id(self) ^ hash(tag)]
# 
#     def __repr__(self):
#         if self._shape != -1:
#             sh = '; '+str(self._shape)
#         else:
#             sh = ''
#         template = '<{cls}: {args!r}; {kwargs!r}'+sh+'>'
#         return template.format(cls=self.distcls.__name__,
#                                args=self.args,
#                                kwargs=self.kwargs)


# Path: gelato/layers/base.py
import functools
import inspect
import six
import lasagne.layers.base
import pymc3 as pm
from pymc3.memoize import hashable
from gelato.specs.dist import get_default_spec, FlatSpec
from gelato.specs.base import DistSpec
        from gelato.layers.helper import find_parent

        def wrap_init(__init__):
            @functools.wraps(__init__)
            def wrapped(self, *args, **kwargs):
                name = kwargs.get('name')
                self._fingerprint = hashable(self.parent)
                pm.Model.__init__(self, name)
                __init__(self, *args, **kwargs)
            return wrapped

        # wrap new for new class
        def wrap_new(__new__):
            @functools.wraps(__new__)
            def wrapped(_cls_, *args, **kwargs):
                parent = kwargs.get('model', None)
                if parent is None and not issubclass(_cls_, lasagne.layers.InputLayer):
                    incoming = kwargs.get('incoming',
                                          kwargs.get('incomings',
                                                     args[1]))
                    parent = find_parent(incoming)
                kwargs['model'] = parent
                instance = __new__(_cls_, *args, **kwargs)
                return instance
            return classmethod(wrapped)

        cls.__init__ = wrap_init(cls.__init__)
        cls.__new__ = wrap_new(cls.__new__)

        def add_param(self, spec, shape, name=None, **tags):
            if tags.get('trainable', True):
                if tags.get('regularizable', True):

                    if not isinstance(spec, DistSpec):