提交 466cdaa8 authored 作者: Frédéric Bastien's avatar Frédéric Bastien 提交者: GitHub

Merge pull request #5454 from bscellier/import_numpy_gof

Import numpy gof
......@@ -11,7 +11,7 @@ import os
import sys
import logging
import numpy
import numpy as np
import theano
from theano import config
......@@ -1347,7 +1347,7 @@ class CLinker(link.Linker):
# We must always add the numpy ABI version here as
# DynamicModule always add the include <numpy/arrayobject.h>
sig.append('NPY_ABI_VERSION=0x%X' %
numpy.core.multiarray._get_ndarray_c_version())
np.core.multiarray._get_ndarray_c_version())
if c_compiler:
sig.append('c_compiler_str=' + c_compiler.version_str())
......
......@@ -20,7 +20,7 @@ import platform
import distutils.sysconfig
import warnings
import numpy.distutils # TODO: TensorType should handle this
import numpy as np # TODO: TensorType should handle nunpy.distutils
import theano
from theano.compat import PY3, decode, decode_iter
......@@ -1578,7 +1578,7 @@ def get_gcc_shared_library_arg():
def std_include_dirs():
numpy_inc_dirs = numpy.distutils.misc_util.get_numpy_include_dirs()
numpy_inc_dirs = np.distutils.misc_util.get_numpy_include_dirs()
py_inc = distutils.sysconfig.get_python_inc()
py_plat_spec_inc = distutils.sysconfig.get_python_inc(plat_specific=True)
python_inc_dirs = ([py_inc] if py_inc == py_plat_spec_inc
......
......@@ -4,7 +4,7 @@ import logging
import os
import shutil
import numpy
import numpy as np
import theano
from six import string_types, iteritems
......@@ -42,7 +42,7 @@ def cleanup():
have_npy_abi_version = False
have_c_compiler = False
for obj in flatten(key):
if isinstance(obj, numpy.ndarray):
if isinstance(obj, np.ndarray):
# Reuse have_npy_abi_version to
# force the removing of key
have_npy_abi_version = False
......
......@@ -481,12 +481,12 @@ class Variable(Node):
Examples
--------
>>> import numpy
>>> import numpy as np
>>> import theano.tensor as T
>>> x = T.dscalar('x')
>>> y = T.dscalar('y')
>>> z = x + y
>>> numpy.allclose(z.eval({x : 16.3, y : 12.1}), 28.4)
>>> np.allclose(z.eval({x : 16.3, y : 12.1}), 28.4)
True
We passed :func:`eval` a dictionary mapping symbolic theano
......
......@@ -7,7 +7,7 @@ from copy import copy, deepcopy
from sys import getsizeof
import sys
import traceback
import numpy
import numpy as np
import theano
from theano.compat import izip
......@@ -236,11 +236,11 @@ def raise_with_op(node, thunk=None, exc_info=None, storage_map=None):
# storage_map_item[3]: bytes
if hasattr(storage_map[k][0], 'dtype'):
dtype = storage_map[k][0].dtype
storage_map_item.append(numpy.dtype(dtype).itemsize)
storage_map_item.append(np.dtype(dtype).itemsize)
if shapeinfo is None:
storage_map_item.append(-1)
else:
sz = numpy.dtype(dtype).itemsize * numpy.prod(shapeinfo)
sz = np.dtype(dtype).itemsize * np.prod(shapeinfo)
storage_map_item.append(sz)
total_size += sz
if not k.owner:
......
......@@ -9,7 +9,7 @@ from __future__ import absolute_import, print_function, division
import inspect
import logging
import numpy
import numpy as np
import os
import re
import sys
......@@ -1430,7 +1430,7 @@ class COp(Op):
(macro_name, macro_value))
undef_macros.append(undef_template % macro_name)
d = numpy.dtype(v.dtype)
d = np.dtype(v.dtype)
macro_name = "TYPENUM_" + vname
macro_value = d.num
......
......@@ -15,7 +15,7 @@ import time
import warnings
import traceback
import numpy
import numpy as np
import theano
from theano import config
......@@ -1695,8 +1695,7 @@ class PatternSub(LocalOptimizer):
u = u.merge(expr, v)
elif (isinstance(pattern, (integer_types, float)) and
isinstance(expr, graph.Constant)):
if numpy.all(
theano.tensor.constant(pattern).value == expr.value):
if np.all(theano.tensor.constant(pattern).value == expr.value):
return u
else:
return retry_with_equiv()
......
......@@ -2,7 +2,7 @@ from __future__ import absolute_import, print_function, division
from nose.plugins.skip import SkipTest
import numpy
import numpy as np
import theano
from theano.gof.link import PerformLinker
......@@ -211,16 +211,16 @@ def test_clinker_literal_cache():
A = theano.tensor.matrix()
input1 = theano.tensor.vector()
normal_svd = numpy.array([[5.936276e+01, -4.664007e-07, -2.56265e-06],
[-4.664007e-07, 9.468691e-01, -3.18862e-02],
[-2.562651e-06, -3.188625e-02, 1.05226e+00]],
dtype=theano.config.floatX)
normal_svd = np.array([[5.936276e+01, -4.664007e-07, -2.56265e-06],
[-4.664007e-07, 9.468691e-01, -3.18862e-02],
[-2.562651e-06, -3.188625e-02, 1.05226e+00]],
dtype=theano.config.floatX)
orientationi = numpy.array([59.36276866, 1.06116353, 0.93797339],
dtype=theano.config.floatX)
orientationi = np.array([59.36276866, 1.06116353, 0.93797339],
dtype=theano.config.floatX)
for out1 in [A - input1[0] * numpy.identity(3),
input1[0] * numpy.identity(3)]:
for out1 in [A - input1[0] * np.identity(3),
input1[0] * np.identity(3)]:
benchmark = theano.function(
inputs=[A, input1],
outputs=[out1],
......@@ -421,7 +421,7 @@ def test_shared_input_output():
g0 = g(0)
assert f0 == g0 == 5, (f0, g0)
vstate = theano.shared(numpy.zeros(3, dtype='int32'))
vstate = theano.shared(np.zeros(3, dtype='int32'))
vstate.name = 'vstate'
fv = theano.function([inc], vstate, updates=[(vstate, vstate + inc)],
mode=mode)
......@@ -430,21 +430,21 @@ def test_shared_input_output():
# Initial value
fv0 = fv(0)
gv0 = gv(0)
assert numpy.all(fv0 == 0), fv0
assert numpy.all(gv0 == 0), gv0
assert np.all(fv0 == 0), fv0
assert np.all(gv0 == 0), gv0
# Increment state via f, returns the previous value.
fv2 = fv(2)
assert numpy.all(fv2 == fv0), (fv2, fv0)
assert np.all(fv2 == fv0), (fv2, fv0)
fv0 = fv(0)
gv0 = gv(0)
assert numpy.all(fv0 == 2), fv0
assert numpy.all(gv0 == 2), gv0
assert np.all(fv0 == 2), fv0
assert np.all(gv0 == 2), gv0
# Increment state via g, returns the previous value
gv3 = gv(3)
assert numpy.all(gv3 == gv0), (gv3, gv0)
assert np.all(gv3 == gv0), (gv3, gv0)
fv0 = fv(0)
gv0 = gv(0)
assert numpy.all(fv0 == 5), fv0
assert numpy.all(gv0 == 5), gv0
assert np.all(fv0 == 5), fv0
assert np.all(gv0 == 5), gv0
......@@ -6,7 +6,7 @@ deterministic based on the input type and the op.
"""
from __future__ import absolute_import, print_function, division
import numpy
import numpy as np
import theano
from theano.gof.cmodule import GCC_compiler
......@@ -26,7 +26,7 @@ class MyOp(theano.compile.ops.DeepCopyOp):
itype = node.inputs[0].type.__class__
if itype in self.c_code_and_version:
code, version = self.c_code_and_version[itype]
rand = numpy.random.rand()
rand = np.random.rand()
return ("""printf("%(rand)s\\n");""" + code) % locals()
# Else, no C code
return super(theano.compile.ops.DeepCopyOp, self).c_code(
......@@ -47,7 +47,7 @@ def test_inter_process_cache():
x, y = theano.tensor.dvectors('xy')
f = theano.function([x, y], [MyOp()(x), MyOp()(y)])
f(numpy.arange(60), numpy.arange(60))
f(np.arange(60), np.arange(60))
if theano.config.mode == 'FAST_COMPILE' or theano.config.cxx == "":
assert MyOp.nb_called == 0
else:
......@@ -56,7 +56,7 @@ def test_inter_process_cache():
# What if we compile a new function with new variables?
x, y = theano.tensor.dvectors('xy')
f = theano.function([x, y], [MyOp()(x), MyOp()(y)])
f(numpy.arange(60), numpy.arange(60))
f(np.arange(60), np.arange(60))
if theano.config.mode == 'FAST_COMPILE' or theano.config.cxx == "":
assert MyOp.nb_called == 0
else:
......
......@@ -4,7 +4,7 @@ import sys
import traceback
import warnings
import numpy
import numpy as np
from nose.plugins.skip import SkipTest
import unittest
......@@ -44,9 +44,9 @@ class TestComputeTestValue(unittest.TestCase):
theano.config.compute_test_value = 'raise'
x = T.matrix('x')
x.tag.test_value = numpy.random.rand(3, 4).astype(config.floatX)
x.tag.test_value = np.random.rand(3, 4).astype(config.floatX)
y = T.matrix('y')
y.tag.test_value = numpy.random.rand(4, 5).astype(config.floatX)
y.tag.test_value = np.random.rand(4, 5).astype(config.floatX)
# should work
z = T.dot(x, y)
......@@ -56,7 +56,7 @@ class TestComputeTestValue(unittest.TestCase):
z.tag.test_value)
# this test should fail
y.tag.test_value = numpy.random.rand(6, 5).astype(config.floatX)
y.tag.test_value = np.random.rand(6, 5).astype(config.floatX)
self.assertRaises(ValueError, T.dot, x, y)
finally:
theano.config.compute_test_value = orig_compute_test_value
......@@ -66,7 +66,7 @@ class TestComputeTestValue(unittest.TestCase):
try:
x = T.matrix('x')
y = T.matrix('y')
y.tag.test_value = numpy.random.rand(4, 5).astype(config.floatX)
y.tag.test_value = np.random.rand(4, 5).astype(config.floatX)
# should skip computation of test value
theano.config.compute_test_value = 'off'
......@@ -96,11 +96,11 @@ class TestComputeTestValue(unittest.TestCase):
theano.config.compute_test_value = 'raise'
x = T.matrix('x')
x.tag.test_value = numpy.random.rand(3, 4).astype(config.floatX)
x.tag.test_value = np.random.rand(3, 4).astype(config.floatX)
y = T.matrix('y')
y.tag.test_value = numpy.random.rand(4, 5).astype(config.floatX)
y.tag.test_value = np.random.rand(4, 5).astype(config.floatX)
z = theano.shared(numpy.random.rand(5, 6).astype(config.floatX))
z = theano.shared(np.random.rand(5, 6).astype(config.floatX))
# should work
out = T.dot(T.dot(x, y), z)
......@@ -114,7 +114,7 @@ class TestComputeTestValue(unittest.TestCase):
return T.dot(T.dot(x, y), z)
# this test should fail
z.set_value(numpy.random.rand(7, 6).astype(config.floatX))
z.set_value(np.random.rand(7, 6).astype(config.floatX))
self.assertRaises(ValueError, f, x, y, z)
finally:
theano.config.compute_test_value = orig_compute_test_value
......@@ -125,8 +125,8 @@ class TestComputeTestValue(unittest.TestCase):
theano.config.compute_test_value = 'raise'
x = T.matrix('x')
x.tag.test_value = numpy.random.rand(3, 4).astype(config.floatX)
y = theano.shared(numpy.random.rand(4, 6).astype(config.floatX),
x.tag.test_value = np.random.rand(3, 4).astype(config.floatX)
y = theano.shared(np.random.rand(4, 6).astype(config.floatX),
'y')
# should work
......@@ -136,7 +136,7 @@ class TestComputeTestValue(unittest.TestCase):
assert _allclose(f(x.tag.test_value), z.tag.test_value)
# this test should fail
y.set_value(numpy.random.rand(5, 6).astype(config.floatX))
y.set_value(np.random.rand(5, 6).astype(config.floatX))
self.assertRaises(ValueError, T.dot, x, y)
finally:
theano.config.compute_test_value = orig_compute_test_value
......@@ -146,8 +146,8 @@ class TestComputeTestValue(unittest.TestCase):
try:
theano.config.compute_test_value = 'raise'
x = numpy.random.rand(2, 3).astype(config.floatX)
y = theano.shared(numpy.random.rand(3, 6).astype(config.floatX),
x = np.random.rand(2, 3).astype(config.floatX)
y = theano.shared(np.random.rand(3, 6).astype(config.floatX),
'y')
# should work
......@@ -157,7 +157,7 @@ class TestComputeTestValue(unittest.TestCase):
assert _allclose(f(), z.tag.test_value)
# this test should fail
x = numpy.random.rand(2, 4).astype(config.floatX)
x = np.random.rand(2, 4).astype(config.floatX)
self.assertRaises(ValueError, T.dot, x, y)
finally:
theano.config.compute_test_value = orig_compute_test_value
......@@ -167,7 +167,7 @@ class TestComputeTestValue(unittest.TestCase):
try:
theano.config.compute_test_value = 'raise'
x = theano.shared(numpy.random.rand(0, 6).astype(config.floatX),
x = theano.shared(np.random.rand(0, 6).astype(config.floatX),
'x')
# should work
......@@ -184,8 +184,8 @@ class TestComputeTestValue(unittest.TestCase):
try:
theano.config.compute_test_value = 'raise'
x = T.constant(numpy.random.rand(2, 3), dtype=config.floatX)
y = theano.shared(numpy.random.rand(3, 6).astype(config.floatX),
x = T.constant(np.random.rand(2, 3), dtype=config.floatX)
y = theano.shared(np.random.rand(3, 6).astype(config.floatX),
'y')
# should work
......@@ -195,7 +195,7 @@ class TestComputeTestValue(unittest.TestCase):
assert _allclose(f(), z.tag.test_value)
# this test should fail
x = T.constant(numpy.random.rand(2, 4), dtype=config.floatX)
x = T.constant(np.random.rand(2, 4), dtype=config.floatX)
self.assertRaises(ValueError, T.dot, x, y)
finally:
theano.config.compute_test_value = orig_compute_test_value
......@@ -207,9 +207,9 @@ class TestComputeTestValue(unittest.TestCase):
x = T.fmatrix('x')
# Incorrect dtype (float64) for test_value
x.tag.test_value = numpy.random.rand(3, 4)
x.tag.test_value = np.random.rand(3, 4)
y = T.dmatrix('y')
y.tag.test_value = numpy.random.rand(4, 5)
y.tag.test_value = np.random.rand(4, 5)
self.assertRaises(TypeError, T.dot, x, y)
finally:
......@@ -222,9 +222,9 @@ class TestComputeTestValue(unittest.TestCase):
try:
config.compute_test_value = "raise"
x = T.matrix()
x.tag.test_value = numpy.zeros((2, 3), dtype=config.floatX)
x.tag.test_value = np.zeros((2, 3), dtype=config.floatX)
y = T.matrix()
y.tag.test_value = numpy.zeros((2, 2), dtype=config.floatX)
y.tag.test_value = np.zeros((2, 2), dtype=config.floatX)
self.assertRaises(ValueError, x.__mul__, y)
finally:
theano.config.compute_test_value = orig_compute_test_value
......@@ -240,7 +240,7 @@ class TestComputeTestValue(unittest.TestCase):
k = T.iscalar("k")
A = T.vector("A")
k.tag.test_value = 3
A.tag.test_value = numpy.random.rand(5).astype(config.floatX)
A.tag.test_value = np.random.rand(5).astype(config.floatX)
def fx(prior_result, A):
return prior_result * A
......@@ -267,7 +267,7 @@ class TestComputeTestValue(unittest.TestCase):
k = T.iscalar("k")
A = T.matrix("A")
k.tag.test_value = 3
A.tag.test_value = numpy.random.rand(5, 3).astype(config.floatX)
A.tag.test_value = np.random.rand(5, 3).astype(config.floatX)
def fx(prior_result, A):
return T.dot(prior_result, A)
......@@ -304,7 +304,7 @@ class TestComputeTestValue(unittest.TestCase):
k = T.iscalar("k")
A = T.matrix("A")
k.tag.test_value = 3
A.tag.test_value = numpy.random.rand(5, 3).astype(config.floatX)
A.tag.test_value = np.random.rand(5, 3).astype(config.floatX)
def fx(prior_result, A):
return T.dot(prior_result, A)
......@@ -400,7 +400,7 @@ class TestComputeTestValue(unittest.TestCase):
try:
theano.config.compute_test_value = 'raise'
init_Mu1 = theano.shared(
numpy.zeros((5,), dtype=config.floatX)).dimshuffle('x', 0)
np.zeros((5,), dtype=config.floatX)).dimshuffle('x', 0)
theano.function([], outputs=[init_Mu1])
finally:
......
......@@ -4,7 +4,7 @@ import pickle
import unittest
from nose.plugins.skip import SkipTest
import numpy
import numpy as np
from theano import (
sparse,
......@@ -362,7 +362,7 @@ class TestAutoName:
r1 = tensor.TensorType(dtype='int32', broadcastable=())('myvar')
r2 = tensor.TensorVariable(tensor.TensorType(dtype='int32',
broadcastable=()))
r3 = shared(numpy.random.randn(3, 4))
r3 = shared(np.random.randn(3, 4))
assert r1.auto_name == "auto_" + str(autoname_id)
assert r2.auto_name == "auto_" + str(autoname_id + 1)
assert r3.auto_name == "auto_" + str(autoname_id + 2)
......
from __future__ import absolute_import, print_function, division
import os
import numpy
import numpy as np
import theano
import theano.tensor as T
......@@ -19,20 +19,20 @@ def test_graph_opt_caching():
theano.config.cache_optimizations = True
a = T.fmatrix('a')
b = T.fmatrix('b')
c = theano.shared(numpy.ones((10, 10), dtype=floatX))
d = theano.shared(numpy.ones((10, 10), dtype=floatX))
c = theano.shared(np.ones((10, 10), dtype=floatX))
d = theano.shared(np.ones((10, 10), dtype=floatX))
e = T.sum(T.sum(T.sum(a ** 2 + b) + c) + d)
f1 = theano.function([a, b], e, mode=mode)
m = T.fmatrix('x1')
n = T.fmatrix('x2')
p = theano.shared(numpy.ones((10, 10), dtype=floatX))
q = theano.shared(numpy.ones((10, 10), dtype=floatX))
p = theano.shared(np.ones((10, 10), dtype=floatX))
q = theano.shared(np.ones((10, 10), dtype=floatX))
j = T.sum(T.sum(T.sum(m ** 2 + n) + p) + q)
f2 = theano.function([m, n], j, mode=mode)
in1 = numpy.ones((10, 10), dtype=floatX)
in2 = numpy.ones((10, 10), dtype=floatX)
in1 = np.ones((10, 10), dtype=floatX)
in2 = np.ones((10, 10), dtype=floatX)
assert f1(in1, in2) == f2(in1, in2)
finally:
theano.config.cache_optimizations = default
......
from __future__ import absolute_import, print_function, division
from copy import deepcopy
import numpy
import numpy as np
import theano
from theano.gof.op import PureOp
......@@ -154,13 +154,13 @@ def more_complex_test():
optimizer='fast_run'))
if theano.config.vm.lazy is False:
try:
f(1, 0, numpy.array(10, dtype=x1.dtype), 0)
f(1, 0, np.array(10, dtype=x1.dtype), 0)
assert False
except NotImplementedOp.E:
pass
else:
print(f(1, 0, numpy.array(10, dtype=x1.dtype), 0))
assert f(1, 0, numpy.array(10, dtype=x1.dtype), 0) == 20.5
print(f(1, 0, np.array(10, dtype=x1.dtype), 0))
assert f(1, 0, np.array(10, dtype=x1.dtype), 0) == 20.5
print('... passed')
if __name__ == '__main__':
......
......@@ -2,7 +2,7 @@ from __future__ import absolute_import, print_function, division
from copy import deepcopy
import unittest
import numpy
import numpy as np
import theano
from theano.gof import graph
......@@ -203,18 +203,18 @@ def test_container_deepcopy():
# It seam that numpy.asarray(0.).astype(floatX) can return a numpy
# scalar with some NumPy Version. So we call numpy.asarray with
# the dtype parameter.
v = numpy.asarray(0., dtype=theano.config.floatX)
assert isinstance(v, numpy.ndarray), type(v)
v = np.asarray(0., dtype=theano.config.floatX)
assert isinstance(v, np.ndarray), type(v)
for readonly in [True, False]:
c = Container(t, [v], readonly=readonly)
assert isinstance(c.storage[0], numpy.ndarray), (c.storage[0],
type(c.storage[0]))
assert isinstance(c.storage[0], np.ndarray), (c.storage[0],
type(c.storage[0]))
assert c.storage[0].dtype == v.dtype, (c.storage[0].dtype, v.dtype)
assert c.storage[0].dtype == c.type.dtype, (c.storage[0].dtype,
c.type.dtype)
d = deepcopy(c)
assert isinstance(d.storage[0], numpy.ndarray), (d.storage[0],
type(d.storage[0]))
assert isinstance(d.storage[0], np.ndarray), (d.storage[0],
type(d.storage[0]))
assert d.storage[0].dtype == v.dtype, (d.storage[0].dtype, v.dtype)
assert d.storage[0].dtype == c.type.dtype, (d.storage[0].dtype,
c.type.dtype)
......@@ -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
import theano
import theano.gof.op as op
......@@ -181,7 +181,7 @@ class TestMakeThunk(unittest.TestCase):
o.owner.op.c_code,
o.owner, 'o', ['x'], 'z', {'fail': ''})
storage_map = {i: [numpy.int32(3)],
storage_map = {i: [np.int32(3)],
o: [None]}
compute_map = {i: [True],
o: [False]}
......@@ -218,7 +218,7 @@ class TestMakeThunk(unittest.TestCase):
o.owner.op.perform,
o.owner, 0, [None])
storage_map = {i: [numpy.int32(3)],
storage_map = {i: [np.int32(3)],
o: [None]}
compute_map = {i: [True],
o: [False]}
......@@ -251,9 +251,9 @@ class TestMakeThunk(unittest.TestCase):
x_input = T.dmatrix('x_input')
f = theano.function([x_input], DoubleOp()(x_input))
inp = numpy.random.rand(5, 4)
inp = np.random.rand(5, 4)
out = f(inp)
assert numpy.allclose(inp * 2, out)
assert np.allclose(inp * 2, out)
def test_test_value_python_objects():
......@@ -262,33 +262,33 @@ def test_test_value_python_objects():
def test_test_value_ndarray():
x = numpy.zeros((5, 5))
x = np.zeros((5, 5))
v = op.get_test_value(x)
assert (v == x).all()
def test_test_value_constant():
x = T.as_tensor_variable(numpy.zeros((5, 5)))
x = T.as_tensor_variable(np.zeros((5, 5)))
v = op.get_test_value(x)
assert numpy.all(v == numpy.zeros((5, 5)))
assert np.all(v == np.zeros((5, 5)))
def test_test_value_shared():
x = shared(numpy.zeros((5, 5)))
x = shared(np.zeros((5, 5)))
v = op.get_test_value(x)
assert numpy.all(v == numpy.zeros((5, 5)))
assert np.all(v == np.zeros((5, 5)))
def test_test_value_op():
try:
prev_value = config.compute_test_value
config.compute_test_value = 'raise'
x = T.log(numpy.ones((5, 5)))
x = T.log(np.ones((5, 5)))
v = op.get_test_value(x)
assert numpy.allclose(v, numpy.zeros((5, 5)))
assert np.allclose(v, np.zeros((5, 5)))
finally:
config.compute_test_value = prev_value
......@@ -337,8 +337,8 @@ def test_get_debug_values_success():
config.compute_test_value = mode
x = T.vector()
x.tag.test_value = numpy.zeros((4,), dtype=config.floatX)
y = numpy.zeros((5, 5))
x.tag.test_value = np.zeros((4,), dtype=config.floatX)
y = np.zeros((5, 5))
iters = 0
......
from __future__ import absolute_import, print_function, division
import numpy
import numpy as np
import theano
from theano import Op, Apply
......@@ -72,7 +72,7 @@ def test_cdata():
# This should be a passthrough function for vectors
f = theano.function([i], i2, mode=mode)
v = numpy.random.randn(9).astype('float32')
v = np.random.randn(9).astype('float32')
v2 = f(v)
assert (v2 == v).all()
......@@ -5,7 +5,7 @@ import time
import unittest
from nose.plugins.skip import SkipTest
import numpy
import numpy as np
from six import itervalues
from theano import function
......@@ -92,7 +92,7 @@ def test_speed():
def time_numpy():
steps_a = 5
steps_b = 100
x = numpy.asarray([2.0, 3.0], dtype=theano.config.floatX)
x = np.asarray([2.0, 3.0], dtype=theano.config.floatX)
numpy_version(x, steps_a)
t0 = time.time()
......@@ -195,7 +195,6 @@ def test_speed_lazy():
def test_partial_function():
import numpy as np
from theano.tests import unittest_tools as utt
def check_partial_function(linker_name):
......@@ -234,7 +233,7 @@ def test_partial_function_with_updates():
def check_updates(linker_name):
x = tensor.lscalar('input')
y = theano.shared(numpy.asarray(1, 'int64'), name='global')
y = theano.shared(np.asarray(1, 'int64'), name='global')
f = theano.function([x], [x, x + 34], updates=[(y, x + 1)], mode=Mode(
optimizer=None, linker=linker_name))
g = theano.function([x], [x - 6], updates=[(y, y + 3)], mode=Mode(
......@@ -283,7 +282,7 @@ if run_memory_usage_tests:
def test_leak2():
import theano.sandbox.cuda as cuda
for i in xrange(1000000):
n = numpy.asarray([2.3, 4.5], dtype='f')
n = np.asarray([2.3, 4.5], dtype='f')
c = sys.getrefcount(n)
a = cuda.CudaNdarray(n)
a.sum()
......@@ -338,7 +337,7 @@ if run_memory_usage_tests:
f_a = function([x], a,
mode=Mode(optimizer=None,
linker=linker()))
inp = numpy.random.rand(1000000)
inp = np.random.rand(1000000)
for i in xrange(100):
f_a(inp)
if 0: # this doesn't seem to work, prints 0 for everything
......@@ -375,7 +374,7 @@ if run_memory_usage_tests:
f_a = function([x], a,
mode=Mode(optimizer=None,
linker=linker()))
inp = numpy.random.rand(1000000)
inp = np.random.rand(1000000)
for i in xrange(500):
f_a(inp)
print(1)
......
......@@ -3,7 +3,7 @@ import linecache
import sys
import traceback
import numpy
import numpy as np
from six import iteritems, integer_types, string_types, with_metaclass
from six.moves import StringIO
......@@ -561,8 +561,8 @@ else:
try:
return hashlib.md5(msg).hexdigest()
except TypeError:
assert isinstance(msg, numpy.ndarray)
return hashlib.md5(numpy.getbuffer(msg)).hexdigest()
assert isinstance(msg, np.ndarray)
return hashlib.md5(np.getbuffer(msg)).hexdigest()
def hash_from_file(file_path):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论