提交 ac4b7a5d authored 作者: kvmanohar22's avatar kvmanohar22

modified numpy imports to one common form

上级 86d21acd
from __future__ import absolute_import, print_function, division from __future__ import absolute_import, print_function, division
from nose.plugins.skip import SkipTest from nose.plugins.skip import SkipTest
import numpy import numpy as np
try: try:
import scipy.sparse as sp import scipy.sparse as sp
import scipy.sparse import scipy.sparse
...@@ -157,14 +157,14 @@ def test_local_dense_from_sparse_sparse_from_dense(): ...@@ -157,14 +157,14 @@ def test_local_dense_from_sparse_sparse_from_dense():
def test_sd_csc(): def test_sd_csc():
A = sp.rand(4, 5, density=0.60, format='csc', dtype=numpy.float32) A = sp.rand(4, 5, density=0.60, format='csc', dtype=np.float32)
b = numpy.random.rand(5,2).astype(numpy.float32) b = np.random.rand(5,2).astype(np.float32)
target = A*b target = A*b
a_val = theano.tensor.as_tensor_variable(A.data) a_val = theano.tensor.as_tensor_variable(A.data)
a_ind = theano.tensor.as_tensor_variable(A.indices) a_ind = theano.tensor.as_tensor_variable(A.indices)
a_ptr = theano.tensor.as_tensor_variable(A.indptr) a_ptr = theano.tensor.as_tensor_variable(A.indptr)
nrows = theano.tensor.as_tensor_variable(numpy.int32(A.shape[0])) nrows = theano.tensor.as_tensor_variable(np.int32(A.shape[0]))
b = theano.tensor.as_tensor_variable(b) b = theano.tensor.as_tensor_variable(b)
res = theano.sparse.opt.sd_csc(a_val, a_ind, a_ptr, nrows, b).eval() res = theano.sparse.opt.sd_csc(a_val, a_ind, a_ptr, nrows, b).eval()
......
...@@ -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
try: try:
import scipy.sparse as sp import scipy.sparse as sp
except ImportError: except ImportError:
...@@ -30,7 +30,7 @@ class PoissonTester(utt.InferShapeTester): ...@@ -30,7 +30,7 @@ class PoissonTester(utt.InferShapeTester):
for format in sparse.sparse_formats: for format in sparse.sparse_formats:
variable = getattr(theano.sparse, format + '_matrix') variable = getattr(theano.sparse, format + '_matrix')
rand = numpy.array(numpy.random.randint(1, 4, size=(3, 4)) - 1, rand = np.array(np.random.randint(1, 4, size=(3, 4)) - 1,
dtype=theano.config.floatX) dtype=theano.config.floatX)
x[format] = variable() x[format] = variable()
...@@ -50,7 +50,7 @@ class PoissonTester(utt.InferShapeTester): ...@@ -50,7 +50,7 @@ class PoissonTester(utt.InferShapeTester):
assert tested.format == format assert tested.format == format
assert tested.dtype == self.a[format].dtype assert tested.dtype == self.a[format].dtype
assert numpy.allclose(numpy.floor(tested.data), tested.data) assert np.allclose(np.floor(tested.data), tested.data)
assert tested.shape == self.a[format].shape assert tested.shape == self.a[format].shape
def test_infer_shape(self): def test_infer_shape(self):
...@@ -67,7 +67,7 @@ class BinomialTester(utt.InferShapeTester): ...@@ -67,7 +67,7 @@ class BinomialTester(utt.InferShapeTester):
shape = tensor.lvector() shape = tensor.lvector()
_n = 5 _n = 5
_p = .25 _p = .25
_shape = numpy.asarray([3, 5], dtype='int64') _shape = np.asarray([3, 5], dtype='int64')
inputs = [n, p, shape] inputs = [n, p, shape]
_inputs = [_n, _p, _shape] _inputs = [_n, _p, _shape]
...@@ -88,7 +88,7 @@ class BinomialTester(utt.InferShapeTester): ...@@ -88,7 +88,7 @@ class BinomialTester(utt.InferShapeTester):
assert tested.shape == tuple(self._shape) assert tested.shape == tuple(self._shape)
assert tested.format == sp_format assert tested.format == sp_format
assert tested.dtype == o_type assert tested.dtype == o_type
assert numpy.allclose(numpy.floor(tested.todense()), assert np.allclose(np.floor(tested.todense()),
tested.todense()) tested.todense())
def test_infer_shape(self): def test_infer_shape(self):
...@@ -103,7 +103,7 @@ class BinomialTester(utt.InferShapeTester): ...@@ -103,7 +103,7 @@ class BinomialTester(utt.InferShapeTester):
class MultinomialTester(utt.InferShapeTester): class MultinomialTester(utt.InferShapeTester):
p = sparse.csr_matrix() p = sparse.csr_matrix()
_p = sp.csr_matrix(numpy.asarray([[0.0, 0.5, 0.0, 0.5], _p = sp.csr_matrix(np.asarray([[0.0, 0.5, 0.0, 0.5],
[0.1, 0.2, 0.3, 0.4], [0.1, 0.2, 0.3, 0.4],
[0.0, 1.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0],
[0.3, 0.3, 0.0, 0.4]], [0.3, 0.3, 0.0, 0.4]],
...@@ -120,16 +120,16 @@ class MultinomialTester(utt.InferShapeTester): ...@@ -120,16 +120,16 @@ class MultinomialTester(utt.InferShapeTester):
_n = 5 _n = 5
tested = f(self._p, _n) tested = f(self._p, _n)
assert tested.shape == self._p.shape assert tested.shape == self._p.shape
assert numpy.allclose(numpy.floor(tested.todense()), tested.todense()) assert np.allclose(np.floor(tested.todense()), tested.todense())
assert tested[2, 1] == _n assert tested[2, 1] == _n
n = tensor.lvector() n = tensor.lvector()
f = theano.function([self.p, n], multinomial(n, self.p)) f = theano.function([self.p, n], multinomial(n, self.p))
_n = numpy.asarray([1, 2, 3, 4], dtype='int64') _n = np.asarray([1, 2, 3, 4], dtype='int64')
tested = f(self._p, _n) tested = f(self._p, _n)
assert tested.shape == self._p.shape assert tested.shape == self._p.shape
assert numpy.allclose(numpy.floor(tested.todense()), tested.todense()) assert np.allclose(np.floor(tested.todense()), tested.todense())
assert tested[2, 1] == _n[2] assert tested[2, 1] == _n[2]
def test_infer_shape(self): def test_infer_shape(self):
......
from __future__ import absolute_import, print_function, division from __future__ import absolute_import, print_function, division
from nose.plugins.skip import SkipTest from nose.plugins.skip import SkipTest
import numpy import numpy as np
import theano.sparse import theano.sparse
if not theano.sparse.enable_sparse: if not theano.sparse.enable_sparse:
raise SkipTest('Optional package sparse disabled') raise SkipTest('Optional package sparse disabled')
...@@ -11,21 +11,21 @@ from theano.sparse.tests.test_basic import as_sparse_format ...@@ -11,21 +11,21 @@ from theano.sparse.tests.test_basic import as_sparse_format
def test_hash_from_sparse(): def test_hash_from_sparse():
hashs = [] hashs = []
rng = numpy.random.rand(5, 5) rng = np.random.rand(5, 5)
for format in ['csc', 'csr']: for format in ['csc', 'csr']:
rng = as_sparse_format(rng, format) rng = as_sparse_format(rng, format)
for data in [[[-2]], [[-1]], [[0]], [[1]], [[2]], for data in [[[-2]], [[-1]], [[0]], [[1]], [[2]],
numpy.zeros((1, 5)), numpy.zeros((1, 6)), np.zeros((1, 5)), np.zeros((1, 6)),
# Data buffer empty but different shapes # Data buffer empty but different shapes
# numpy.zeros((1, 0)), numpy.zeros((2, 0)), # np.zeros((1, 0)), np.zeros((2, 0)),
# Same data buffer and shapes but different strides # Same data buffer and shapes but different strides
numpy.arange(25).reshape(5, 5), np.arange(25).reshape(5, 5),
numpy.arange(25).reshape(5, 5).T, np.arange(25).reshape(5, 5).T,
# Same data buffer, shapes and strides # Same data buffer, shapes and strides
# but different dtypes # but different dtypes
numpy.zeros((5, 5), dtype="uint32"), np.zeros((5, 5), dtype="uint32"),
numpy.zeros((5, 5), dtype="int32"), np.zeros((5, 5), dtype="int32"),
# Test slice # Test slice
rng, rng[1:], rng[:4], rng[1:3], rng, rng[1:], rng[:4], rng[1:3],
# Don't test step as they are not supported by sparse # Don't test step as they are not supported by sparse
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论