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

modified numpy imports to one common form

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