def test_none_Constant(): """ Tests equals We had an error in the past with unpickling """ o1 = Constant(NoneTypeT(), None, name='NoneConst') o2 = Constant(NoneTypeT(), None, name='NoneConst') assert o1.equals(o2) assert NoneConst.equals(o1) assert o1.equals(NoneConst) assert NoneConst.equals(o2) assert o2.equals(NoneConst) # This trigger equals that returned the wrong answer in the past. import six.moves.cPickle as pickle import theano from theano import tensor x = tensor.vector('x') y = tensor.argmax(x) kwargs = {} # We can't pickle DebugMode if theano.config.mode in ["DebugMode", "DEBUG_MODE"]: kwargs = {'mode': 'FAST_RUN'} f = theano.function([x], [y], **kwargs) pickle.loads(pickle.dumps(f))
def make_node(self, rv, val): """Make an `Observed` random variable. Parameters ---------- rv: RandomVariable The distribution from which `val` is assumed to be a sample value. val: Variable The observed value. """ val = as_tensor_variable(val) if rv is not None: if not hasattr(rv, "type") or rv.type.convert_variable(val) is None: raise TypeError( ( "`rv` and `val` do not have compatible types:" f" rv={rv}, val={val}" ) ) else: rv = NoneConst.clone() inputs = [rv, val] return Apply(self, inputs, [val.type()])
def test_none_Constant(): """ Tests equals We had an error in the past with unpickling """ o1 = Constant(NoneTypeT(), None, name='NoneConst') o2 = Constant(NoneTypeT(), None, name='NoneConst') assert o1.equals(o2) assert NoneConst.equals(o1) assert o1.equals(NoneConst) assert NoneConst.equals(o2) assert o2.equals(NoneConst) # This trigger equals that returned the wrong answer in the past. import cPickle import theano from theano import tensor x = tensor.vector('x') y = tensor.argmax(x) f = theano.function([x], [y]) cPickle.loads(cPickle.dumps(f))