提交 cc612fde authored 作者: amrithasuresh's avatar amrithasuresh

1. Added import numpy as np

2. Updated numpy as np
上级 bc00e8f5
......@@ -2,6 +2,7 @@ from __future__ import absolute_import, print_function, division
import unittest
from six.moves import xrange
import theano
import numpy as np
from theano.tensor import *
from theano.tests import unittest_tools as utt
......@@ -12,30 +13,30 @@ class TestRealImag(unittest.TestCase):
def test0(self):
x = zvector()
rng = numpy.random.RandomState(23)
xval = numpy.asarray(list(numpy.complex(rng.randn(), rng.randn())
rng = np.random.RandomState(23)
xval = np.asarray(list(np.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))
assert np.all(xval.real == theano.function([x], real(x))(xval))
assert np.all(xval.imag == theano.function([x], imag(x))(xval))
def test_on_real_input(self):
x = dvector()
rng = numpy.random.RandomState(23)
rng = np.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))
np.all(0 == theano.function([x], imag(x))(xval))
np.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))
xval = np.asarray(rng.randn(3, 3) * 100, dtype='int32')
np.all(0 == theano.function([x], imag(x))(xval))
np.all(xval == theano.function([x], real(x))(xval))
def test_cast(self):
x = zvector()
self.assertRaises(TypeError, cast, x, 'int32')
def test_complex(self):
rng = numpy.random.RandomState(2333)
rng = np.random.RandomState(2333)
m = fmatrix()
c = complex(m[0], m[1])
assert c.type == cvector
......@@ -44,10 +45,10 @@ class TestRealImag(unittest.TestCase):
assert i.type == fvector
f = theano.function([m], [r, i])
mval = numpy.asarray(rng.randn(2, 5), dtype='float32')
mval = np.asarray(rng.randn(2, 5), dtype='float32')
rval, ival = f(mval)
assert numpy.all(rval == mval[0]), (rval, mval[0])
assert numpy.all(ival == mval[1]), (ival, mval[1])
assert np.all(rval == mval[0]), (rval, mval[0])
assert np.all(ival == mval[1]), (ival, mval[1])
@dec.skipif(True, "Complex grads not enabled, see #178")
def test_complex_grads(self):
......@@ -55,8 +56,8 @@ class TestRealImag(unittest.TestCase):
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))
rng = np.random.RandomState(9333)
mval = np.asarray(rng.randn(2, 5))
utt.verify_grad(f, [mval])
@dec.skipif(True, "Complex grads not enabled, see #178")
......@@ -66,8 +67,8 @@ class TestRealImag(unittest.TestCase):
ac = complex(a[0], a[1])
return abs((ac)**2).sum()
rng = numpy.random.RandomState(9333)
aval = numpy.asarray(rng.randn(2, 5))
rng = np.random.RandomState(9333)
aval = np.asarray(rng.randn(2, 5))
try:
utt.verify_grad(f, [aval])
except utt.verify_grad.E_grad as e:
......@@ -82,8 +83,8 @@ class TestRealImag(unittest.TestCase):
ac = complex(a[0], a[1])
return abs(ac).sum()
rng = numpy.random.RandomState(9333)
aval = numpy.asarray(rng.randn(2, 5))
rng = np.random.RandomState(9333)
aval = np.asarray(rng.randn(2, 5))
try:
utt.verify_grad(f, [aval])
except utt.verify_grad.E_grad as e:
......@@ -98,8 +99,8 @@ class TestRealImag(unittest.TestCase):
ac = complex(a[0], a[1])
return abs((ac*b)**2).sum()
rng = numpy.random.RandomState(9333)
aval = numpy.asarray(rng.randn(2, 5))
rng = np.random.RandomState(9333)
aval = np.asarray(rng.randn(2, 5))
bval = rng.randn(5)
try:
utt.verify_grad(f, [aval, bval])
......@@ -114,8 +115,8 @@ class TestRealImag(unittest.TestCase):
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))
rng = np.random.RandomState(9333)
mval = np.asarray(rng.randn(2, 5))
utt.verify_grad(f, [mval])
@dec.skipif(True, "Complex grads not enabled, see #178")
......@@ -124,6 +125,6 @@ class TestRealImag(unittest.TestCase):
c = complex(m[0], m[1])
return .5 * abs(c)
rng = numpy.random.RandomState(9333)
mval = numpy.asarray(rng.randn(2, 5))
rng = np.random.RandomState(9333)
mval = np.asarray(rng.randn(2, 5))
utt.verify_grad(f, [mval])
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论