提交 5c25733d authored 作者: abergeron's avatar abergeron

Merge pull request #1832 from nouiz/fix_tests

[BUG] Fix bad view map in real(float32)
......@@ -74,11 +74,11 @@ VERSION = '%d.%d.%d%s' % (MAJOR, MINOR, MICRO, SUFFIX)
def find_packages(where='.', exclude=()):
out = []
stack=[(convert_path(where), '')]
stack = [(convert_path(where), '')]
while stack:
where, prefix = stack.pop(0)
for name in os.listdir(where):
fn = os.path.join(where,name)
fn = os.path.join(where, name)
if ('.' not in name and os.path.isdir(fn) and
os.path.isfile(os.path.join(fn, '__init__.py'))
):
......@@ -146,6 +146,7 @@ def write_text(filename, text):
a.close()
""")
def write_version_py(filename=os.path.join('theano', 'generated_version.py')):
cnt = """
# THIS FILE IS GENERATED FROM THEANO SETUP.PY
......@@ -175,6 +176,7 @@ if not release:
'isrelease': str(ISRELEASED)}
write_text(filename, text)
def do_setup():
write_version_py()
setup(name=NAME,
......@@ -199,7 +201,7 @@ def do_setup():
'theano', 'math', 'numerical', 'symbolic', 'blas',
'numpy', 'gpu', 'autodiff', 'differentiation'
]),
cmdclass = {'build_py': build_py,
cmdclass={'build_py': build_py,
'build_scripts': build_scripts}
)
if __name__ == "__main__":
......
......@@ -166,7 +166,8 @@ def test_consistency_cpu_parallel():
rstate = theano.shared(rstate)
new_rstate, sample = rng_mrg.mrg_uniform.new(rstate, ndim=None,
dtype=config.floatX, size=(n_substreams,))
dtype=config.floatX,
size=(n_substreams,))
# Not really necessary, just mimicking
# rng_mrg.MRG_RandomStreams' behavior
sample.rstate = rstate
......@@ -219,7 +220,8 @@ def test_consistency_GPU_serial():
rstate = float32_shared_constructor(tmp_float_buf)
new_rstate, sample = rng_mrg.GPU_mrg_uniform.new(rstate, ndim=None,
dtype='float32', size=(1,))
dtype='float32',
size=(1,))
rstate.default_update = new_rstate
# Not really necessary, just mimicking
......@@ -278,7 +280,8 @@ def test_consistency_GPU_parallel():
rstate = float32_shared_constructor(tmp_float_buf)
new_rstate, sample = rng_mrg.GPU_mrg_uniform.new(rstate, ndim=None,
dtype='float32', size=(n_substreams,))
dtype='float32',
size=(n_substreams,))
rstate.default_update = new_rstate
# Not really necessary, just mimicking
......@@ -381,7 +384,8 @@ def test_consistency_GPUA_parallel():
rstate = gpuarray_shared_constructor(rstate)
new_rstate, sample = rng_mrg.GPUA_mrg_uniform.new(rstate, ndim=None,
dtype='float32', size=(n_substreams,))
dtype='float32',
size=(n_substreams,))
rstate.default_update = new_rstate
# Not really necessary, just mimicking
......@@ -887,12 +891,14 @@ def test_multMatVect():
g0 = rng_mrg.DotModulo()(A1, s1, m1, A2, s2, m2)
f0 = theano.function([A1, s1, m1, A2, s2, m2], g0)
A1 = numpy.random.randint(0, numpy.iinfo(numpy.int32).max, (3, 3)).astype('int64')
s1 = numpy.random.randint(0, numpy.iinfo(numpy.int32).max, 3).astype('int32')
m1 = numpy.asarray(numpy.random.randint(numpy.iinfo(numpy.int32).max), dtype="int32")
A2 = numpy.random.randint(0, numpy.iinfo(numpy.int32).max, (3, 3)).astype('int64')
s2 = numpy.random.randint(0, numpy.iinfo(numpy.int32).max, 3).astype('int32')
m2 = numpy.asarray(numpy.random.randint(numpy.iinfo(numpy.int32).max), dtype="int32")
i32max = numpy.iinfo(numpy.int32).max
A1 = numpy.random.randint(0, i32max, (3, 3)).astype('int64')
s1 = numpy.random.randint(0, i32max, 3).astype('int32')
m1 = numpy.asarray(numpy.random.randint(i32max), dtype="int32")
A2 = numpy.random.randint(0, i32max, (3, 3)).astype('int64')
s2 = numpy.random.randint(0, i32max, 3).astype('int32')
m2 = numpy.asarray(numpy.random.randint(i32max), dtype="int32")
f0.input_storage[0].storage[0] = A1
f0.input_storage[1].storage[0] = s1
......@@ -903,7 +909,8 @@ def test_multMatVect():
r_a1 = rng_mrg.matVecModM(A1, s1, m1)
r_a2 = rng_mrg.matVecModM(A2, s2, m2)
r_b = f0.fn()[0]
f0.fn()
r_b = f0.output_storage[0].value
assert numpy.allclose(r_a1, r_b[:3])
assert numpy.allclose(r_a2, r_b[3:])
......
......@@ -2028,8 +2028,9 @@ def chi2sf(x, k):
"""chi squared survival function"""
@_scal_elemwise_with_nfunc('real', 1, -1)
#numpy.real(float32) return a view on the inputs.
#@_scal_elemwise_with_nfunc('real', 1, -1)
@_scal_elemwise
def real(z):
"""Return real component of complex-valued tensor `z`"""
_tensor_py_operators.real = property(real)
......
......@@ -5,30 +5,31 @@ from theano.tests import unittest_tools as utt
from numpy.testing import dec
class TestRealImag(unittest.TestCase):
def test0(self):
x= zvector()
x = zvector()
rng = numpy.random.RandomState(23)
xval = numpy.asarray(list(numpy.complex(rng.randn(), rng.randn()) for i in xrange(10)))
assert numpy.all( xval.real == theano.function([x], real(x))(xval))
assert numpy.all( xval.imag == theano.function([x], imag(x))(xval))
xval = numpy.asarray(list(numpy.complex(rng.randn(), rng.randn())
for i in xrange(10)))
assert numpy.all(xval.real == theano.function([x], real(x))(xval))
assert numpy.all(xval.imag == theano.function([x], imag(x))(xval))
def test_on_real_input(self):
x= dvector()
x = dvector()
rng = numpy.random.RandomState(23)
xval = rng.randn(10)
numpy.all( 0 == theano.function([x], imag(x))(xval))
numpy.all( xval == theano.function([x], real(x))(xval))
numpy.all(0 == theano.function([x], imag(x))(xval))
numpy.all(xval == theano.function([x], real(x))(xval))
x= imatrix()
xval = numpy.asarray(rng.randn(3,3)*100, dtype='int32')
numpy.all( 0 == theano.function([x], imag(x))(xval))
numpy.all( xval == theano.function([x], real(x))(xval))
x = imatrix()
xval = numpy.asarray(rng.randn(3, 3) * 100, dtype='int32')
numpy.all(0 == theano.function([x], imag(x))(xval))
numpy.all(xval == theano.function([x], real(x))(xval))
def test_cast(self):
x= zvector()
x = zvector()
self.assertRaises(TypeError, cast, x, 'int32')
def test_complex(self):
......@@ -36,27 +37,27 @@ class TestRealImag(unittest.TestCase):
m = fmatrix()
c = complex(m[0], m[1])
assert c.type == cvector
r,i = [real(c), imag(c)]
r, i = [real(c), imag(c)]
assert r.type == fvector
assert i.type == fvector
f = theano.function([m], [r,i] )
f = theano.function([m], [r, i])
mval = numpy.asarray(rng.randn(2,5), dtype='float32')
mval = numpy.asarray(rng.randn(2, 5), dtype='float32')
rval, ival = f(mval)
assert numpy.all(rval == mval[0]), (rval,mval[0])
assert numpy.all(rval == mval[0]), (rval, mval[0])
assert numpy.all(ival == mval[1]), (ival, mval[1])
@dec.knownfailureif(True,"Complex grads not enabled, see #178")
@dec.knownfailureif(True, "Complex grads not enabled, see #178")
def test_complex_grads(self):
def f(m):
c = complex(m[0], m[1])
return .5 * real(c) + .9 * imag(c)
rng = numpy.random.RandomState(9333)
mval = numpy.asarray(rng.randn(2,5))
mval = numpy.asarray(rng.randn(2, 5))
utt.verify_grad(f, [mval])
@dec.knownfailureif(True,"Complex grads not enabled, see #178")
@dec.knownfailureif(True, "Complex grads not enabled, see #178")
def test_mul_mixed0(self):
def f(a):
......@@ -64,7 +65,7 @@ class TestRealImag(unittest.TestCase):
return abs((ac)**2).sum()
rng = numpy.random.RandomState(9333)
aval = numpy.asarray(rng.randn(2,5))
aval = numpy.asarray(rng.randn(2, 5))
try:
utt.verify_grad(f, [aval])
except utt.verify_grad.E_grad, e:
......@@ -72,7 +73,7 @@ class TestRealImag(unittest.TestCase):
print e.analytic_grad
raise
@dec.knownfailureif(True,"Complex grads not enabled, see #178")
@dec.knownfailureif(True, "Complex grads not enabled, see #178")
def test_mul_mixed1(self):
def f(a):
......@@ -80,22 +81,23 @@ class TestRealImag(unittest.TestCase):
return abs(ac).sum()
rng = numpy.random.RandomState(9333)
aval = numpy.asarray(rng.randn(2,5))
aval = numpy.asarray(rng.randn(2, 5))
try:
utt.verify_grad(f, [aval])
except utt.verify_grad.E_grad, e:
print e.num_grad.gf
print e.analytic_grad
raise
@dec.knownfailureif(True,"Complex grads not enabled, see #178")
@dec.knownfailureif(True, "Complex grads not enabled, see #178")
def test_mul_mixed(self):
def f(a,b):
def f(a, b):
ac = complex(a[0], a[1])
return abs((ac*b)**2).sum()
rng = numpy.random.RandomState(9333)
aval = numpy.asarray(rng.randn(2,5))
aval = numpy.asarray(rng.randn(2, 5))
bval = rng.randn(5)
try:
utt.verify_grad(f, [aval, bval])
......@@ -104,22 +106,22 @@ class TestRealImag(unittest.TestCase):
print e.analytic_grad
raise
@dec.knownfailureif(True,"Complex grads not enabled, see #178")
@dec.knownfailureif(True, "Complex grads not enabled, see #178")
def test_polar_grads(self):
def f(m):
c = complex_from_polar(abs(m[0]), m[1])
return .5 * real(c) + .9 * imag(c)
rng = numpy.random.RandomState(9333)
mval = numpy.asarray(rng.randn(2,5))
mval = numpy.asarray(rng.randn(2, 5))
utt.verify_grad(f, [mval])
@dec.knownfailureif(True,"Complex grads not enabled, see #178")
@dec.knownfailureif(True, "Complex grads not enabled, see #178")
def test_abs_grad(self):
def f(m):
c = complex(m[0], m[1])
return .5 * abs(c)
rng = numpy.random.RandomState(9333)
mval = numpy.asarray(rng.randn(2,5))
mval = numpy.asarray(rng.randn(2, 5))
utt.verify_grad(f, [mval])
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论