提交 eab932a1 authored 作者: james@X40's avatar james@X40

disabling RModule tests

上级 d7aebfad
...@@ -43,7 +43,7 @@ from compile import \ ...@@ -43,7 +43,7 @@ from compile import \
Mode, \ Mode, \
predefined_modes, predefined_linkers, predefined_optimizers, \ predefined_modes, predefined_linkers, predefined_optimizers, \
FunctionMaker, function, OpFromGraph, \ FunctionMaker, function, OpFromGraph, \
Component, External, Member, KitComponent, Method, \ Component, External, Member, Method, \
Composite, ComponentList, ComponentDict, Module, \ Composite, ComponentList, ComponentDict, Module, \
ProfileMode ProfileMode
......
...@@ -4,183 +4,70 @@ import sys ...@@ -4,183 +4,70 @@ import sys
import unittest import unittest
import numpy as N import numpy as N
from theano.tensor.rmodule import * from theano.tensor.deprecated.rmodule import *
from theano import tensor from theano import tensor
from theano import compile, gof from theano import compile, gof
class T_RandomStreams(unittest.TestCase): if 0:
def test_basics(self): class T_test_module(unittest.TestCase):
m = Module() def test_state_propagation(self):
m.random = RandomStreams(234) if 1:
m.fn = Method([], m.random.uniform((2,2))) print >> sys.stderr, "RModule deprecated"
m.gn = Method([], m.random.normal((2,2))) else:
made = m.make() x = tensor.vector()
made.random.initialize() rk = RandomKit('rk', 1000)
f = compile.function([x, (rk, [gof.Container(r = gof.generic, storage = [123], name='bla')])], rk.binomial(tensor.shape(x)))
fn_val0 = made.fn() print "RK", rk.value
fn_val1 = made.fn() f['rk'] = 9873456
print "RK", rk.value
gn_val0 = made.gn()
rvals = [f([1,2,3,4,6, 7, 8]) for i in xrange(5)]
rng_seed = numpy.random.RandomState(234).randint(2**30) print rvals
rng = numpy.random.RandomState(int(rng_seed)) #int() is for 32bit for i in xrange(5-1):
for j in xrange(i+1, 5):
#print fn_val0 assert not N.all(rvals[i] == rvals[j])
numpy_val0 = rng.uniform(size=(2,2))
numpy_val1 = rng.uniform(size=(2,2)) def test_B(self):
#print numpy_val0 """Test that random numbers change from call to call!
assert numpy.all(fn_val0 == numpy_val0) Also, make sure that the seeding strategy doesn't change without failing a test.
assert numpy.all(fn_val1 == numpy_val1)
Random numbers can't be too random or experiments aren't repeatable. Email theano-dev
def test_seed_in_initialize(self): before updating the `rvals` in this test.
m = Module() """
m.random = RandomStreams(234) class B(RModule):
m.fn = Method([], m.random.uniform((2,2))) def __init__(self):
made = m.make() super(B, self).__init__()
made.random.initialize(seed=888)
self.x = compile.Member(tensor.dvector())
fn_val0 = made.fn() self.r = self.random.uniform(tensor.shape(self.x))
fn_val1 = made.fn()
self.f = compile.Method([self.x], self.r)
rng_seed = numpy.random.RandomState(888).randint(2**30) class E(RModule):
rng = numpy.random.RandomState(int(rng_seed)) #int() is for 32bit def __init__(self):
super(E, self).__init__()
#print fn_val0 self.b = B()
numpy_val0 = rng.uniform(size=(2,2)) self.f = compile.Method([self.b.x], self.b.r)
numpy_val1 = rng.uniform(size=(2,2))
#print numpy_val0 b = E()
m = b.make()
assert numpy.all(fn_val0 == numpy_val0)
assert numpy.all(fn_val1 == numpy_val1) m.seed(1000)
#print m.f(N.ones(5))
def test_seed_fn(self): #print m.f(N.ones(5))
m = Module() #print m.f(N.ones(5))
m.random = RandomStreams(234) rvals = ["0.74802375876 0.872308123517 0.294830748897 0.803123780003 0.6321109955",
m.fn = Method([], m.random.uniform((2,2))) "0.00168744844365 0.278638315678 0.725436793755 0.7788480779 0.629885140994",
made = m.make() "0.545561221664 0.0992011009108 0.847112593242 0.188015424144 0.158046201298",
made.random.initialize(seed=789) "0.054382248842 0.563459168529 0.192757276954 0.360455221883 0.174805216702",
"0.961942907777 0.49657319422 0.0316111492826 0.0915054717012 0.195877184515"]
made.random.seed(888)
for i in xrange(5):
fn_val0 = made.fn() s = " ".join([str(n) for n in m.f(N.ones(5))])
fn_val1 = made.fn() print s
assert s == rvals[i]
rng_seed = numpy.random.RandomState(888).randint(2**30)
rng = numpy.random.RandomState(int(rng_seed)) #int() is for 32bit
#print fn_val0
numpy_val0 = rng.uniform(size=(2,2))
numpy_val1 = rng.uniform(size=(2,2))
#print numpy_val0
assert numpy.all(fn_val0 == numpy_val0)
assert numpy.all(fn_val1 == numpy_val1)
def test_getitem(self):
m = Module()
m.random = RandomStreams(234)
out = m.random.uniform((2,2))
m.fn = Method([], out)
made = m.make()
made.random.initialize(seed=789)
made.random.seed(888)
rng = numpy.random.RandomState()
rng.set_state(made.random[out.rng].get_state())
fn_val0 = made.fn()
fn_val1 = made.fn()
numpy_val0 = rng.uniform(size=(2,2))
numpy_val1 = rng.uniform(size=(2,2))
assert numpy.all(fn_val0 == numpy_val0)
assert numpy.all(fn_val1 == numpy_val1)
def test_setitem(self):
m = Module()
m.random = RandomStreams(234)
out = m.random.uniform((2,2))
m.fn = Method([], out)
made = m.make()
made.random.initialize(seed=789)
made.random.seed(888)
rng = numpy.random.RandomState(823874)
made.random[out.rng] = numpy.random.RandomState(823874)
fn_val0 = made.fn()
fn_val1 = made.fn()
numpy_val0 = rng.uniform(size=(2,2))
numpy_val1 = rng.uniform(size=(2,2))
assert numpy.all(fn_val0 == numpy_val0)
assert numpy.all(fn_val1 == numpy_val1)
class T_test_module(unittest.TestCase):
def test_state_propagation(self):
if 1:
print >> sys.stderr, "RModule deprecated"
else:
x = tensor.vector()
rk = RandomKit('rk', 1000)
f = compile.function([x, (rk, [gof.Container(r = gof.generic, storage = [123], name='bla')])], rk.binomial(tensor.shape(x)))
print "RK", rk.value
f['rk'] = 9873456
print "RK", rk.value
rvals = [f([1,2,3,4,6, 7, 8]) for i in xrange(5)]
print rvals
for i in xrange(5-1):
for j in xrange(i+1, 5):
assert not N.all(rvals[i] == rvals[j])
def test_B(self):
"""Test that random numbers change from call to call!
Also, make sure that the seeding strategy doesn't change without failing a test.
Random numbers can't be too random or experiments aren't repeatable. Email theano-dev
before updating the `rvals` in this test.
"""
class B(RModule):
def __init__(self):
super(B, self).__init__()
self.x = compile.Member(tensor.dvector())
self.r = self.random.uniform(tensor.shape(self.x))
self.f = compile.Method([self.x], self.r)
class E(RModule):
def __init__(self):
super(E, self).__init__()
self.b = B()
self.f = compile.Method([self.b.x], self.b.r)
b = E()
m = b.make()
m.seed(1000)
#print m.f(N.ones(5))
#print m.f(N.ones(5))
#print m.f(N.ones(5))
rvals = ["0.74802375876 0.872308123517 0.294830748897 0.803123780003 0.6321109955",
"0.00168744844365 0.278638315678 0.725436793755 0.7788480779 0.629885140994",
"0.545561221664 0.0992011009108 0.847112593242 0.188015424144 0.158046201298",
"0.054382248842 0.563459168529 0.192757276954 0.360455221883 0.174805216702",
"0.961942907777 0.49657319422 0.0316111492826 0.0915054717012 0.195877184515"]
for i in xrange(5):
s = " ".join([str(n) for n in m.f(N.ones(5))])
print s
assert s == rvals[i]
if __name__ == '__main__': if __name__ == '__main__':
from theano.tests import main from theano.tests import main
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论