提交 708568c2 authored 作者: amrithasuresh's avatar amrithasuresh

Updated numpy as np

上级 449fc71e
...@@ -2,7 +2,7 @@ from __future__ import absolute_import, print_function, division ...@@ -2,7 +2,7 @@ from __future__ import absolute_import, print_function, division
import unittest import unittest
from nose.plugins.skip import SkipTest from nose.plugins.skip import SkipTest
import numpy import numpy as np
import theano import theano
import theano.typed_list import theano.typed_list
...@@ -24,8 +24,8 @@ except ImportError: ...@@ -24,8 +24,8 @@ except ImportError:
# took from tensors/tests/test_basic.py # took from tensors/tests/test_basic.py
def rand_ranged_matrix(minimum, maximum, shape): def rand_ranged_matrix(minimum, maximum, shape):
return numpy.asarray(numpy.random.rand(*shape) * (maximum - minimum) + return np.asarray(np.random.rand(*shape) * (maximum - minimum) +
minimum, dtype=theano.config.floatX) minimum, dtype=theano.config.floatX)
# took from sparse/tests/test_basic.py # took from sparse/tests/test_basic.py
...@@ -34,8 +34,8 @@ def random_lil(shape, dtype, nnz): ...@@ -34,8 +34,8 @@ def random_lil(shape, dtype, nnz):
huge = 2 ** 30 huge = 2 ** 30
for k in range(nnz): for k in range(nnz):
# set non-zeros in random locations (row x, col y) # set non-zeros in random locations (row x, col y)
idx = numpy.random.randint(1, huge + 1, size=2) % shape idx = np.random.randint(1, huge + 1, size=2) % shape
value = numpy.random.rand() value = np.random.rand()
# if dtype *int*, value will always be zeros! # if dtype *int*, value will always be zeros!
if dtype in theano.tensor.integer_dtypes: if dtype in theano.tensor.integer_dtypes:
value = int(value * 100) value = int(value * 100)
...@@ -68,7 +68,7 @@ class test_get_item(unittest.TestCase): ...@@ -68,7 +68,7 @@ class test_get_item(unittest.TestCase):
x = rand_ranged_matrix(-1000, 1000, [100, 101]) x = rand_ranged_matrix(-1000, 1000, [100, 101])
self.assertTrue(numpy.array_equal(f([x], slice(0, 1, 1)), [x])) self.assertTrue(np.array_equal(f([x], slice(0, 1, 1)), [x]))
def test_sanity_check_single(self): def test_sanity_check_single(self):
...@@ -84,9 +84,9 @@ class test_get_item(unittest.TestCase): ...@@ -84,9 +84,9 @@ class test_get_item(unittest.TestCase):
x = rand_ranged_matrix(-1000, 1000, [100, 101]) x = rand_ranged_matrix(-1000, 1000, [100, 101])
self.assertTrue(numpy.array_equal(f([x], self.assertTrue(np.array_equal(f([x],
numpy.asarray(0, dtype='int64')), np.asarray(0, dtype='int64')),
x)) x))
def test_interface(self): def test_interface(self):
mySymbolicMatricesList = TypedListType(T.TensorType( mySymbolicMatricesList = TypedListType(T.TensorType(
...@@ -100,16 +100,16 @@ class test_get_item(unittest.TestCase): ...@@ -100,16 +100,16 @@ class test_get_item(unittest.TestCase):
x = rand_ranged_matrix(-1000, 1000, [100, 101]) x = rand_ranged_matrix(-1000, 1000, [100, 101])
self.assertTrue(numpy.array_equal(f([x], self.assertTrue(np.array_equal(f([x],
numpy.asarray(0, dtype='int64')), np.asarray(0, dtype='int64')),
x)) x))
z = mySymbolicMatricesList[0] z = mySymbolicMatricesList[0]
f = theano.function([mySymbolicMatricesList], f = theano.function([mySymbolicMatricesList],
z) z)
self.assertTrue(numpy.array_equal(f([x]), x)) self.assertTrue(np.array_equal(f([x]), x))
def test_wrong_input(self): def test_wrong_input(self):
mySymbolicMatricesList = TypedListType(T.TensorType( mySymbolicMatricesList = TypedListType(T.TensorType(
...@@ -130,14 +130,14 @@ class test_get_item(unittest.TestCase): ...@@ -130,14 +130,14 @@ class test_get_item(unittest.TestCase):
x = rand_ranged_matrix(-1000, 1000, [100, 101]) x = rand_ranged_matrix(-1000, 1000, [100, 101])
self.assertTrue(numpy.array_equal(f([x]), x)) self.assertTrue(np.array_equal(f([x]), x))
z = GetItem()(mySymbolicMatricesList, slice(0, 1, 1)) z = GetItem()(mySymbolicMatricesList, slice(0, 1, 1))
f = theano.function([mySymbolicMatricesList], f = theano.function([mySymbolicMatricesList],
z) z)
self.assertTrue(numpy.array_equal(f([x]), [x])) self.assertTrue(np.array_equal(f([x]), [x]))
class test_append(unittest.TestCase): class test_append(unittest.TestCase):
...@@ -156,7 +156,7 @@ class test_append(unittest.TestCase): ...@@ -156,7 +156,7 @@ class test_append(unittest.TestCase):
y = rand_ranged_matrix(-1000, 1000, [100, 101]) y = rand_ranged_matrix(-1000, 1000, [100, 101])
self.assertTrue(numpy.array_equal(f([x], y), [x, y])) self.assertTrue(np.array_equal(f([x], y), [x, y]))
def test_sanity_check(self): def test_sanity_check(self):
mySymbolicMatricesList = TypedListType(T.TensorType( mySymbolicMatricesList = TypedListType(T.TensorType(
...@@ -171,7 +171,7 @@ class test_append(unittest.TestCase): ...@@ -171,7 +171,7 @@ class test_append(unittest.TestCase):
y = rand_ranged_matrix(-1000, 1000, [100, 101]) y = rand_ranged_matrix(-1000, 1000, [100, 101])
self.assertTrue(numpy.array_equal(f([x], y), [x, y])) self.assertTrue(np.array_equal(f([x], y), [x, y]))
def test_interfaces(self): def test_interfaces(self):
mySymbolicMatricesList = TypedListType(T.TensorType( mySymbolicMatricesList = TypedListType(T.TensorType(
...@@ -186,7 +186,7 @@ class test_append(unittest.TestCase): ...@@ -186,7 +186,7 @@ class test_append(unittest.TestCase):
y = rand_ranged_matrix(-1000, 1000, [100, 101]) y = rand_ranged_matrix(-1000, 1000, [100, 101])
self.assertTrue(numpy.array_equal(f([x], y), [x, y])) self.assertTrue(np.array_equal(f([x], y), [x, y]))
class test_extend(unittest.TestCase): class test_extend(unittest.TestCase):
...@@ -206,7 +206,7 @@ class test_extend(unittest.TestCase): ...@@ -206,7 +206,7 @@ class test_extend(unittest.TestCase):
y = rand_ranged_matrix(-1000, 1000, [100, 101]) y = rand_ranged_matrix(-1000, 1000, [100, 101])
self.assertTrue(numpy.array_equal(f([x], [y]), [x, y])) self.assertTrue(np.array_equal(f([x], [y]), [x, y]))
def test_sanity_check(self): def test_sanity_check(self):
mySymbolicMatricesList1 = TypedListType(T.TensorType( mySymbolicMatricesList1 = TypedListType(T.TensorType(
...@@ -223,7 +223,7 @@ class test_extend(unittest.TestCase): ...@@ -223,7 +223,7 @@ class test_extend(unittest.TestCase):
y = rand_ranged_matrix(-1000, 1000, [100, 101]) y = rand_ranged_matrix(-1000, 1000, [100, 101])
self.assertTrue(numpy.array_equal(f([x], [y]), [x, y])) self.assertTrue(np.array_equal(f([x], [y]), [x, y]))
def test_interface(self): def test_interface(self):
mySymbolicMatricesList1 = TypedListType(T.TensorType( mySymbolicMatricesList1 = TypedListType(T.TensorType(
...@@ -240,7 +240,7 @@ class test_extend(unittest.TestCase): ...@@ -240,7 +240,7 @@ class test_extend(unittest.TestCase):
y = rand_ranged_matrix(-1000, 1000, [100, 101]) y = rand_ranged_matrix(-1000, 1000, [100, 101])
self.assertTrue(numpy.array_equal(f([x], [y]), [x, y])) self.assertTrue(np.array_equal(f([x], [y]), [x, y]))
class test_insert(unittest.TestCase): class test_insert(unittest.TestCase):
...@@ -260,10 +260,10 @@ class test_insert(unittest.TestCase): ...@@ -260,10 +260,10 @@ class test_insert(unittest.TestCase):
y = rand_ranged_matrix(-1000, 1000, [100, 101]) y = rand_ranged_matrix(-1000, 1000, [100, 101])
self.assertTrue(numpy.array_equal(f([x], self.assertTrue(np.array_equal(f([x],
numpy.asarray(1, dtype='int64'), np.asarray(1, dtype='int64'),
y), y),
[x, y])) [x, y]))
def test_sanity_check(self): def test_sanity_check(self):
mySymbolicMatricesList = TypedListType(T.TensorType( mySymbolicMatricesList = TypedListType(T.TensorType(
...@@ -279,7 +279,7 @@ class test_insert(unittest.TestCase): ...@@ -279,7 +279,7 @@ class test_insert(unittest.TestCase):
y = rand_ranged_matrix(-1000, 1000, [100, 101]) y = rand_ranged_matrix(-1000, 1000, [100, 101])
self.assertTrue(numpy.array_equal(f([x], numpy.asarray(1, self.assertTrue(np.array_equal(f([x], np.asarray(1,
dtype='int64'), y), [x, y])) dtype='int64'), y), [x, y]))
def test_interface(self): def test_interface(self):
...@@ -296,10 +296,10 @@ class test_insert(unittest.TestCase): ...@@ -296,10 +296,10 @@ class test_insert(unittest.TestCase):
y = rand_ranged_matrix(-1000, 1000, [100, 101]) y = rand_ranged_matrix(-1000, 1000, [100, 101])
self.assertTrue(numpy.array_equal(f([x], self.assertTrue(np.array_equal(f([x],
numpy.asarray(1, dtype='int64'), np.asarray(1, dtype='int64'),
y), y),
[x, y])) [x, y]))
class test_remove(unittest.TestCase): class test_remove(unittest.TestCase):
...@@ -318,7 +318,7 @@ class test_remove(unittest.TestCase): ...@@ -318,7 +318,7 @@ class test_remove(unittest.TestCase):
y = rand_ranged_matrix(-1000, 1000, [100, 101]) y = rand_ranged_matrix(-1000, 1000, [100, 101])
self.assertTrue(numpy.array_equal(f([x, y], y), [x])) self.assertTrue(np.array_equal(f([x, y], y), [x]))
def test_sanity_check(self): def test_sanity_check(self):
mySymbolicMatricesList = TypedListType(T.TensorType( mySymbolicMatricesList = TypedListType(T.TensorType(
...@@ -333,7 +333,7 @@ class test_remove(unittest.TestCase): ...@@ -333,7 +333,7 @@ class test_remove(unittest.TestCase):
y = rand_ranged_matrix(-1000, 1000, [100, 101]) y = rand_ranged_matrix(-1000, 1000, [100, 101])
self.assertTrue(numpy.array_equal(f([x, y], y), [x])) self.assertTrue(np.array_equal(f([x, y], y), [x]))
def test_interface(self): def test_interface(self):
mySymbolicMatricesList = TypedListType(T.TensorType( mySymbolicMatricesList = TypedListType(T.TensorType(
...@@ -348,7 +348,7 @@ class test_remove(unittest.TestCase): ...@@ -348,7 +348,7 @@ class test_remove(unittest.TestCase):
y = rand_ranged_matrix(-1000, 1000, [100, 101]) y = rand_ranged_matrix(-1000, 1000, [100, 101])
self.assertTrue(numpy.array_equal(f([x, y], y), [x])) self.assertTrue(np.array_equal(f([x, y], y), [x]))
class test_reverse(unittest.TestCase): class test_reverse(unittest.TestCase):
...@@ -366,7 +366,7 @@ class test_reverse(unittest.TestCase): ...@@ -366,7 +366,7 @@ class test_reverse(unittest.TestCase):
y = rand_ranged_matrix(-1000, 1000, [100, 101]) y = rand_ranged_matrix(-1000, 1000, [100, 101])
self.assertTrue(numpy.array_equal(f([x, y]), [y, x])) self.assertTrue(np.array_equal(f([x, y]), [y, x]))
def test_sanity_check(self): def test_sanity_check(self):
mySymbolicMatricesList = TypedListType(T.TensorType( mySymbolicMatricesList = TypedListType(T.TensorType(
...@@ -380,7 +380,7 @@ class test_reverse(unittest.TestCase): ...@@ -380,7 +380,7 @@ class test_reverse(unittest.TestCase):
y = rand_ranged_matrix(-1000, 1000, [100, 101]) y = rand_ranged_matrix(-1000, 1000, [100, 101])
self.assertTrue(numpy.array_equal(f([x, y]), [y, x])) self.assertTrue(np.array_equal(f([x, y]), [y, x]))
def test_interface(self): def test_interface(self):
mySymbolicMatricesList = TypedListType(T.TensorType( mySymbolicMatricesList = TypedListType(T.TensorType(
...@@ -394,7 +394,7 @@ class test_reverse(unittest.TestCase): ...@@ -394,7 +394,7 @@ class test_reverse(unittest.TestCase):
y = rand_ranged_matrix(-1000, 1000, [100, 101]) y = rand_ranged_matrix(-1000, 1000, [100, 101])
self.assertTrue(numpy.array_equal(f([x, y]), [y, x])) self.assertTrue(np.array_equal(f([x, y]), [y, x]))
class test_index(unittest.TestCase): class test_index(unittest.TestCase):
...@@ -570,10 +570,10 @@ class TestMakeList(unittest.TestCase): ...@@ -570,10 +570,10 @@ class TestMakeList(unittest.TestCase):
x = T.tensor3() x = T.tensor3()
y = T.tensor3() y = T.tensor3()
A = numpy.cast[theano.config.floatX](numpy.random.rand(5, 3)) A = np.cast[theano.config.floatX](np.random.rand(5, 3))
B = numpy.cast[theano.config.floatX](numpy.random.rand(7, 2)) B = np.cast[theano.config.floatX](np.random.rand(7, 2))
X = numpy.cast[theano.config.floatX](numpy.random.rand(5, 6, 1)) X = np.cast[theano.config.floatX](np.random.rand(5, 6, 1))
Y = numpy.cast[theano.config.floatX](numpy.random.rand(1, 9, 3)) Y = np.cast[theano.config.floatX](np.random.rand(1, 9, 3))
make_list((3., 4.)) make_list((3., 4.))
c = make_list((a, b)) c = make_list((a, b))
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论