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

Merge pull request #5853 from Amrithasuresh/master

Updated numpy as np #4218
...@@ -134,7 +134,7 @@ if (config.device.startswith('cuda') or ...@@ -134,7 +134,7 @@ if (config.device.startswith('cuda') or
import theano.gpuarray import theano.gpuarray
# Use config.numpy to call numpy.seterr # Use config.numpy to call numpy.seterr
import numpy import numpy as np
if config.numpy.seterr_all == 'None': if config.numpy.seterr_all == 'None':
_all = None _all = None
...@@ -156,7 +156,7 @@ if config.numpy.seterr_invalid == 'None': ...@@ -156,7 +156,7 @@ if config.numpy.seterr_invalid == 'None':
_invalid = None _invalid = None
else: else:
_invalid = config.numpy.seterr_invalid _invalid = config.numpy.seterr_invalid
numpy.seterr( np.seterr(
all=_all, all=_all,
divide=_divide, divide=_divide,
over=_over, over=_over,
......
...@@ -3,7 +3,7 @@ import errno ...@@ -3,7 +3,7 @@ import errno
import os import os
import sys import sys
import logging import logging
import numpy import numpy as np
import platform import platform
import textwrap import textwrap
import re import re
...@@ -1052,7 +1052,7 @@ AddConfigVar('profiling.ignore_first_call', ...@@ -1052,7 +1052,7 @@ AddConfigVar('profiling.ignore_first_call',
AddConfigVar('optdb.position_cutoff', AddConfigVar('optdb.position_cutoff',
'Where to stop eariler during optimization. It represent the' 'Where to stop eariler during optimization. It represent the'
' position of the optimizer where to stop.', ' position of the optimizer where to stop.',
FloatParam(numpy.inf), FloatParam(np.inf),
in_c_key=False) in_c_key=False)
AddConfigVar('optdb.max_use_ratio', AddConfigVar('optdb.max_use_ratio',
...@@ -1106,11 +1106,11 @@ def default_blas_ldflags(): ...@@ -1106,11 +1106,11 @@ def default_blas_ldflags():
global numpy global numpy
warn_record = [] warn_record = []
try: try:
if (hasattr(numpy.distutils, '__config__') and if (hasattr(np.distutils, '__config__') and
numpy.distutils.__config__): np.distutils.__config__):
# If the old private interface is available use it as it # If the old private interface is available use it as it
# don't print information to the user. # don't print information to the user.
blas_info = numpy.distutils.__config__.blas_opt_info blas_info = np.distutils.__config__.blas_opt_info
else: else:
# We do this import only here, as in some setup, if we # We do this import only here, as in some setup, if we
# just import theano and exit, with the import at global # just import theano and exit, with the import at global
...@@ -1494,7 +1494,7 @@ compiledir_format_dict = { ...@@ -1494,7 +1494,7 @@ compiledir_format_dict = {
"python_bitwidth": local_bitwidth(), "python_bitwidth": local_bitwidth(),
"python_int_bitwidth": python_int_bitwidth(), "python_int_bitwidth": python_int_bitwidth(),
"theano_version": theano.__version__, "theano_version": theano.__version__,
"numpy_version": numpy.__version__, "numpy_version": np.__version__,
"gxx_version": gcc_version_str.replace(" ", "_"), "gxx_version": gcc_version_str.replace(" ", "_"),
"hostname": socket.gethostname()} "hostname": socket.gethostname()}
......
from __future__ import absolute_import, print_function, division from __future__ import absolute_import, print_function, division
import theano import theano
import numpy import numpy as np
from unittest import TestCase from unittest import TestCase
from theano.gof import Op, COp, Apply from theano.gof import Op, COp, Apply
from theano import Generic from theano import Generic
...@@ -121,21 +121,21 @@ class TestParamsType(TestCase): ...@@ -121,21 +121,21 @@ class TestParamsType(TestCase):
npy_scalar=TensorType('float64', tuple())) npy_scalar=TensorType('float64', tuple()))
wp2 = ParamsType(a=Generic(), array=TensorType('int64', (False,)), floatting=Scalar('float64'), wp2 = ParamsType(a=Generic(), array=TensorType('int64', (False,)), floatting=Scalar('float64'),
npy_scalar=TensorType('float64', tuple())) npy_scalar=TensorType('float64', tuple()))
w1 = Params(wp1, a=1, array=numpy.asarray([1, 2, 4, 5, 7]), floatting=-4.5, npy_scalar=numpy.asarray(12)) w1 = Params(wp1, a=1, array=np.asarray([1, 2, 4, 5, 7]), floatting=-4.5, npy_scalar=np.asarray(12))
w2 = Params(wp2, a=1, array=numpy.asarray([1, 2, 4, 5, 7]), floatting=-4.5, npy_scalar=numpy.asarray(12)) w2 = Params(wp2, a=1, array=np.asarray([1, 2, 4, 5, 7]), floatting=-4.5, npy_scalar=np.asarray(12))
assert w1 == w2 assert w1 == w2
assert not (w1 != w2) assert not (w1 != w2)
assert hash(w1) == hash(w2) assert hash(w1) == hash(w2)
# Changing attributes names only (a -> other_name). # Changing attributes names only (a -> other_name).
wp2_other = ParamsType(other_name=Generic(), array=TensorType('int64', (False,)), floatting=Scalar('float64'), wp2_other = ParamsType(other_name=Generic(), array=TensorType('int64', (False,)), floatting=Scalar('float64'),
npy_scalar=TensorType('float64', tuple())) npy_scalar=TensorType('float64', tuple()))
w2 = Params(wp2_other, other_name=1, array=numpy.asarray([1, 2, 4, 5, 7]), floatting=-4.5, npy_scalar=numpy.asarray(12)) w2 = Params(wp2_other, other_name=1, array=np.asarray([1, 2, 4, 5, 7]), floatting=-4.5, npy_scalar=np.asarray(12))
assert w1 != w2 assert w1 != w2
# Changing attributes values only (now a=2). # Changing attributes values only (now a=2).
w2 = Params(wp2, a=2, array=numpy.asarray([1, 2, 4, 5, 7]), floatting=-4.5, npy_scalar=numpy.asarray(12)) w2 = Params(wp2, a=2, array=np.asarray([1, 2, 4, 5, 7]), floatting=-4.5, npy_scalar=np.asarray(12))
assert w1 != w2 assert w1 != w2
# Changing NumPy array values (5 -> -5). # Changing NumPy array values (5 -> -5).
w2 = Params(wp2, a=1, array=numpy.asarray([1, 2, 4, -5, 7]), floatting=-4.5, npy_scalar=numpy.asarray(12)) w2 = Params(wp2, a=1, array=np.asarray([1, 2, 4, -5, 7]), floatting=-4.5, npy_scalar=np.asarray(12))
assert w1 != w2 assert w1 != w2
def test_hash_and_eq_params_type(self): def test_hash_and_eq_params_type(self):
...@@ -168,7 +168,7 @@ class TestParamsType(TestCase): ...@@ -168,7 +168,7 @@ class TestParamsType(TestCase):
def test_params_type_filtering(self): def test_params_type_filtering(self):
shape_tensor5 = (1, 2, 2, 3, 2) shape_tensor5 = (1, 2, 2, 3, 2)
size_tensor5 = shape_tensor5[0] * shape_tensor5[1] * shape_tensor5[2] * shape_tensor5[3] * shape_tensor5[4] size_tensor5 = shape_tensor5[0] * shape_tensor5[1] * shape_tensor5[2] * shape_tensor5[3] * shape_tensor5[4]
random_tensor = numpy.random.normal(size=size_tensor5).reshape(shape_tensor5) random_tensor = np.random.normal(size=size_tensor5).reshape(shape_tensor5)
w = ParamsType(a1=TensorType('int32', (False, False)), w = ParamsType(a1=TensorType('int32', (False, False)),
a2=TensorType('float64', (False, False, False, False, False)), a2=TensorType('float64', (False, False, False, False, False)),
...@@ -176,7 +176,7 @@ class TestParamsType(TestCase): ...@@ -176,7 +176,7 @@ class TestParamsType(TestCase):
# With a value that does not match the params type. # With a value that does not match the params type.
o = Params(w, o = Params(w,
a1=numpy.asarray([[1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11, 12]]).astype('int64'), a1=np.asarray([[1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11, 12]]).astype('int64'),
a2=random_tensor.astype('float32'), a2=random_tensor.astype('float32'),
a3=2000) a3=2000)
# should fail (o.a1 is not int32, o.a2 is not float64) # should fail (o.a1 is not int32, o.a2 is not float64)
...@@ -188,7 +188,7 @@ class TestParamsType(TestCase): ...@@ -188,7 +188,7 @@ class TestParamsType(TestCase):
# With a value that matches the params type. # With a value that matches the params type.
o1 = Params(w, o1 = Params(w,
a1=numpy.asarray([[1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11, 12]]).astype('int32'), a1=np.asarray([[1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11, 12]]).astype('int32'),
a2=random_tensor.astype('float64'), a2=random_tensor.astype('float64'),
a3=2000) a3=2000)
# All should pass. # All should pass.
...@@ -198,7 +198,7 @@ class TestParamsType(TestCase): ...@@ -198,7 +198,7 @@ class TestParamsType(TestCase):
# Check values_eq and values_eq_approx. # Check values_eq and values_eq_approx.
o2 = Params(w, o2 = Params(w,
a1=numpy.asarray([[1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11, 12]]).astype('int32'), a1=np.asarray([[1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11, 12]]).astype('int32'),
a2=random_tensor.astype('float64'), a2=random_tensor.astype('float64'),
a3=2000) a3=2000)
assert w.values_eq(o1, o2) assert w.values_eq(o1, o2)
...@@ -208,7 +208,7 @@ class TestParamsType(TestCase): ...@@ -208,7 +208,7 @@ class TestParamsType(TestCase):
# NB: I don't know exactly which kind of differences is rejected by values_eq but accepted by values_eq_approx. # NB: I don't know exactly which kind of differences is rejected by values_eq but accepted by values_eq_approx.
# So, I just play a little with float values. # So, I just play a little with float values.
o3 = Params(w, o3 = Params(w,
a1=numpy.asarray([[1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11, 12]]).astype('int32'), a1=np.asarray([[1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11, 12]]).astype('int32'),
a2=(random_tensor.astype('float32') * 10 / 2.2 * 2.19999999999 / 10).astype('float64'), a2=(random_tensor.astype('float32') * 10 / 2.2 * 2.19999999999 / 10).astype('float64'),
a3=2000.0 - 0.00000000000000001) a3=2000.0 - 0.00000000000000001)
assert w.values_eq_approx(o1, o3) assert w.values_eq_approx(o1, o3)
...@@ -250,7 +250,7 @@ class TestParamsType(TestCase): ...@@ -250,7 +250,7 @@ class TestParamsType(TestCase):
f1 = theano.function([x], y1) f1 = theano.function([x], y1)
f2 = theano.function([x], y2) f2 = theano.function([x], y2)
shape = (100, 100) shape = (100, 100)
vx = numpy.random.normal(size=shape[0] * shape[1]).astype('float64').reshape(*shape) vx = np.random.normal(size=shape[0] * shape[1]).astype('float64').reshape(*shape)
vy1 = f1(vx) vy1 = f1(vx)
vy2 = f2(vx) vy2 = f2(vx)
ref = a * (vx**2) + b * vx + c ref = a * (vx**2) + b * vx + c
......
...@@ -7,7 +7,7 @@ http://www.iro.umontreal.ca/~simardr/ssj/indexe.html ...@@ -7,7 +7,7 @@ http://www.iro.umontreal.ca/~simardr/ssj/indexe.html
""" """
from __future__ import absolute_import, print_function, division from __future__ import absolute_import, print_function, division
import numpy import numpy as np
from theano import Apply, tensor from theano import Apply, tensor
from theano.gof import local_optimizer from theano.gof import local_optimizer
...@@ -170,7 +170,7 @@ class GPUA_mrg_uniform(GpuKernelBase, mrg_uniform_base): ...@@ -170,7 +170,7 @@ class GPUA_mrg_uniform(GpuKernelBase, mrg_uniform_base):
o_rstate, o_sample = out o_rstate, o_sample = out
inplace = int(self.inplace) inplace = int(self.inplace)
ndim = self.output_type.ndim ndim = self.output_type.ndim
o_type_num = numpy.asarray(0, dtype=self.output_type.dtype).dtype.num o_type_num = np.asarray(0, dtype=self.output_type.dtype).dtype.num
fail = sub['fail'] fail = sub['fail']
ctx = sub['params'] ctx = sub['params']
kname = self.gpu_kernels(node, nodename)[0].objvar kname = self.gpu_kernels(node, nodename)[0].objvar
......
...@@ -17,7 +17,7 @@ import warnings ...@@ -17,7 +17,7 @@ import warnings
from copy import copy from copy import copy
from textwrap import dedent from textwrap import dedent
import numpy import numpy as np
import six import six
from six.moves import xrange from six.moves import xrange
...@@ -72,7 +72,7 @@ def upcast(dtype, *dtypes): ...@@ -72,7 +72,7 @@ def upcast(dtype, *dtypes):
keep_float16[0] = False keep_float16[0] = False
if dt == 'float32': if dt == 'float32':
keep_float16[0] = False keep_float16[0] = False
return numpy.zeros((), dtype=dt) return np.zeros((), dtype=dt)
z = make_array(dtype) z = make_array(dtype)
for dt in dtypes: for dt in dtypes:
z = z + make_array(dt=dt) z = z + make_array(dt=dt)
...@@ -168,12 +168,12 @@ class NumpyAutocaster(object): ...@@ -168,12 +168,12 @@ class NumpyAutocaster(object):
# Make sure we only deal with scalars. # Make sure we only deal with scalars.
assert (isinstance(x, six.integer_types) or assert (isinstance(x, six.integer_types) or
isinstance(x, builtin_float) or isinstance(x, builtin_float) or
(isinstance(x, numpy.ndarray) and x.ndim == 0)) (isinstance(x, np.ndarray) and x.ndim == 0))
if config.cast_policy == 'numpy': if config.cast_policy == 'numpy':
return numpy.asarray(x) return np.asarray(x)
elif config.cast_policy == 'numpy+floatX': elif config.cast_policy == 'numpy+floatX':
rval = numpy.asarray(x) rval = np.asarray(x)
if ((not hasattr(x, 'dtype') and if ((not hasattr(x, 'dtype') and
rval.dtype in ('float64', 'float32') and rval.dtype in ('float64', 'float32') and
rval.dtype != config.floatX)): rval.dtype != config.floatX)):
...@@ -191,7 +191,7 @@ class NumpyAutocaster(object): ...@@ -191,7 +191,7 @@ class NumpyAutocaster(object):
# No need to cast `x` into a new dtype. Note that we still # No need to cast `x` into a new dtype. Note that we still
# need to convert it into an array, because it may not be # need to convert it into an array, because it may not be
# one already (e.g. if x == numpy.float64(1.1)). # one already (e.g. if x == numpy.float64(1.1)).
return numpy.asarray(x) return np.asarray(x)
except AttributeError: except AttributeError:
# Means `x` has no 'dtype' attribute. # Means `x` has no 'dtype' attribute.
pass pass
...@@ -209,7 +209,7 @@ class NumpyAutocaster(object): ...@@ -209,7 +209,7 @@ class NumpyAutocaster(object):
for dtype in try_dtypes: for dtype in try_dtypes:
x_ = theano._asarray(x, dtype=dtype) x_ = theano._asarray(x, dtype=dtype)
if numpy.all(x == x_): if np.all(x == x_):
break break
# returns either an exact x_==x, or the last cast x_ # returns either an exact x_==x, or the last cast x_
return x_ return x_
...@@ -272,16 +272,16 @@ def convert(x, dtype=None): ...@@ -272,16 +272,16 @@ def convert(x, dtype=None):
x_ = theano._asarray(x, dtype='uint64') x_ = theano._asarray(x, dtype='uint64')
elif isinstance(x, builtin_float): elif isinstance(x, builtin_float):
x_ = autocast_float(x) x_ = autocast_float(x)
elif isinstance(x, numpy.ndarray): elif isinstance(x, np.ndarray):
x_ = x x_ = x
else: else:
# Here x is probably a list or a tuple. If it contains a # Here x is probably a list or a tuple. If it contains a
# long, we will behave like the current NumPy version: it # long, we will behave like the current NumPy version: it
# will work if the long fits in int64 or uint64. # will work if the long fits in int64 or uint64.
x_ = numpy.asarray(x) x_ = np.asarray(x)
if x_.size == 0 and not hasattr(x, 'dtype'): if x_.size == 0 and not hasattr(x, 'dtype'):
x_ = numpy.asarray(x, dtype=config.floatX) x_ = np.asarray(x, dtype=config.floatX)
assert type(x_) in [numpy.ndarray, numpy.memmap] assert type(x_) in [np.ndarray, np.memmap]
return x_ return x_
...@@ -396,21 +396,21 @@ class Scalar(Type): ...@@ -396,21 +396,21 @@ class Scalar(Type):
print(dtype, np.zeros(1, dtype=dtype).dtype.num) print(dtype, np.zeros(1, dtype=dtype).dtype.num)
""" """
return { # dtype: (py_type, c_type, cls_name) return { # dtype: (py_type, c_type, cls_name)
'float16': (numpy.float16, 'npy_float16', 'Float16'), 'float16': (np.float16, 'npy_float16', 'Float16'),
'float32': (numpy.float32, 'npy_float32', 'Float32'), 'float32': (np.float32, 'npy_float32', 'Float32'),
'float64': (numpy.float64, 'npy_float64', 'Float64'), 'float64': (np.float64, 'npy_float64', 'Float64'),
'complex128': (numpy.complex128, 'theano_complex128', 'complex128': (np.complex128, 'theano_complex128',
'Complex128'), 'Complex128'),
'complex64': (numpy.complex64, 'theano_complex64', 'Complex64'), 'complex64': (np.complex64, 'theano_complex64', 'Complex64'),
'bool': (numpy.bool_, 'npy_bool', 'Bool'), 'bool': (np.bool_, 'npy_bool', 'Bool'),
'uint8': (numpy.uint8, 'npy_uint8', 'UInt8'), 'uint8': (np.uint8, 'npy_uint8', 'UInt8'),
'int8': (numpy.int8, 'npy_int8', 'Int8'), 'int8': (np.int8, 'npy_int8', 'Int8'),
'uint16': (numpy.uint16, 'npy_uint16', 'UInt16'), 'uint16': (np.uint16, 'npy_uint16', 'UInt16'),
'int16': (numpy.int16, 'npy_int16', 'Int16'), 'int16': (np.int16, 'npy_int16', 'Int16'),
'uint32': (numpy.uint32, 'npy_uint32', 'UInt32'), 'uint32': (np.uint32, 'npy_uint32', 'UInt32'),
'int32': (numpy.int32, 'npy_int32', 'Int32'), 'int32': (np.int32, 'npy_int32', 'Int32'),
'uint64': (numpy.uint64, 'npy_uint64', 'UInt64'), 'uint64': (np.uint64, 'npy_uint64', 'UInt64'),
'int64': (numpy.int64, 'npy_int64', 'Int64') 'int64': (np.int64, 'npy_int64', 'Int64')
}[self.dtype] }[self.dtype]
except KeyError: except KeyError:
raise TypeError("Unsupported dtype for %s: %s" % ( raise TypeError("Unsupported dtype for %s: %s" % (
...@@ -505,8 +505,8 @@ class Scalar(Type): ...@@ -505,8 +505,8 @@ class Scalar(Type):
# If the 'int' C type is not exactly the same as an existing # If the 'int' C type is not exactly the same as an existing
# 'npy_intX', some C code may not compile, e.g. when assigning # 'npy_intX', some C code may not compile, e.g. when assigning
# the value 0 (cast to 'int' in C) to a theano_complex64. # the value 0 (cast to 'int' in C) to a theano_complex64.
if (numpy.dtype('intc').num not in if (np.dtype('intc').num not in
[numpy.dtype(d[4:]).num for d in real_types]): [np.dtype(d[4:]).num for d in real_types]):
# In that case we add the 'int' type to the real types. # In that case we add the 'int' type to the real types.
real_types.append('int') real_types.append('int')
...@@ -645,7 +645,7 @@ class Scalar(Type): ...@@ -645,7 +645,7 @@ class Scalar(Type):
return ["import_array();"] return ["import_array();"]
def c_code_cache_version(self): def c_code_cache_version(self):
return (13, numpy.__version__) return (13, np.__version__)
def get_shape_info(self, obj): def get_shape_info(self, obj):
return obj.itemsize return obj.itemsize
...@@ -1247,7 +1247,7 @@ class LT(LogicalComparison): ...@@ -1247,7 +1247,7 @@ class LT(LogicalComparison):
def impl(self, x, y): def impl(self, x, y):
# built-in < don't support complex # built-in < don't support complex
return numpy.less(x, y) return np.less(x, y)
def c_code(self, node, name, inputs, outputs, sub): def c_code(self, node, name, inputs, outputs, sub):
(x, y) = inputs (x, y) = inputs
...@@ -1266,7 +1266,7 @@ class GT(LogicalComparison): ...@@ -1266,7 +1266,7 @@ class GT(LogicalComparison):
def impl(self, x, y): def impl(self, x, y):
# built-in > don't support complex # built-in > don't support complex
return numpy.greater(x, y) return np.greater(x, y)
def c_code(self, node, name, inputs, outputs, sub): def c_code(self, node, name, inputs, outputs, sub):
(x, y) = inputs (x, y) = inputs
...@@ -1285,7 +1285,7 @@ class LE(LogicalComparison): ...@@ -1285,7 +1285,7 @@ class LE(LogicalComparison):
def impl(self, x, y): def impl(self, x, y):
# built-in <= don't support complex # built-in <= don't support complex
return numpy.less_equal(x, y) return np.less_equal(x, y)
def c_code(self, node, name, inputs, outputs, sub): def c_code(self, node, name, inputs, outputs, sub):
(x, y) = inputs (x, y) = inputs
...@@ -1304,7 +1304,7 @@ class GE(LogicalComparison): ...@@ -1304,7 +1304,7 @@ class GE(LogicalComparison):
def impl(self, x, y): def impl(self, x, y):
# built-in >= don't support complex # built-in >= don't support complex
return numpy.greater_equal(x, y) return np.greater_equal(x, y)
def c_code(self, node, name, inputs, outputs, sub): def c_code(self, node, name, inputs, outputs, sub):
(x, y) = inputs (x, y) = inputs
...@@ -1353,7 +1353,7 @@ class IsNan(FixedLogicalComparison): ...@@ -1353,7 +1353,7 @@ class IsNan(FixedLogicalComparison):
nfunc_spec = ('isnan', 1, 1) nfunc_spec = ('isnan', 1, 1)
def impl(self, x): def impl(self, x):
return numpy.isnan(x) return np.isnan(x)
def c_code(self, node, name, inputs, outputs, sub): def c_code(self, node, name, inputs, outputs, sub):
(x,) = inputs (x,) = inputs
...@@ -1378,7 +1378,7 @@ class IsInf(FixedLogicalComparison): ...@@ -1378,7 +1378,7 @@ class IsInf(FixedLogicalComparison):
nfunc_spec = ('isinf', 1, 1) nfunc_spec = ('isinf', 1, 1)
def impl(self, x): def impl(self, x):
return numpy.isinf(x) return np.isinf(x)
def c_code(self, node, name, inputs, outputs, sub): def c_code(self, node, name, inputs, outputs, sub):
(x,) = inputs (x,) = inputs
...@@ -1596,7 +1596,7 @@ class Maximum(BinaryScalarOp): ...@@ -1596,7 +1596,7 @@ class Maximum(BinaryScalarOp):
def impl(self, *inputs): def impl(self, *inputs):
# The built-in max function don't support complex type # The built-in max function don't support complex type
return numpy.maximum(*inputs) return np.maximum(*inputs)
def c_code(self, node, name, inputs, outputs, sub): def c_code(self, node, name, inputs, outputs, sub):
(x, y) = inputs (x, y) = inputs
...@@ -1633,7 +1633,7 @@ class Minimum(BinaryScalarOp): ...@@ -1633,7 +1633,7 @@ class Minimum(BinaryScalarOp):
def impl(self, *inputs): def impl(self, *inputs):
# The built-in min function don't support complex type # The built-in min function don't support complex type
return numpy.minimum(*inputs) return np.minimum(*inputs)
def c_code(self, node, name, inputs, outputs, sub): def c_code(self, node, name, inputs, outputs, sub):
(x, y) = inputs (x, y) = inputs
...@@ -1709,7 +1709,7 @@ class Mul(ScalarOp): ...@@ -1709,7 +1709,7 @@ class Mul(ScalarOp):
nfunc_spec = ('multiply', 2, 1) nfunc_spec = ('multiply', 2, 1)
def impl(self, *inputs): def impl(self, *inputs):
return numpy.product(inputs) return np.product(inputs)
def c_code(self, node, name, inputs, outputs, sub): def c_code(self, node, name, inputs, outputs, sub):
(z,) = outputs (z,) = outputs
...@@ -1859,10 +1859,10 @@ class TrueDiv(BinaryScalarOp): ...@@ -1859,10 +1859,10 @@ class TrueDiv(BinaryScalarOp):
return super(TrueDiv, self).output_types(types) return super(TrueDiv, self).output_types(types)
def impl(self, x, y): def impl(self, x, y):
x = numpy.asarray(x) x = np.asarray(x)
y = numpy.asarray(y) y = np.asarray(y)
if all(a.dtype in discrete_types for a in (x, y)): if all(a.dtype in discrete_types for a in (x, y)):
return numpy.sctypeDict[config.floatX](float(x) / y) return np.sctypeDict[config.floatX](float(x) / y)
else: else:
return x / y return x / y
...@@ -1999,7 +1999,7 @@ class Mod(BinaryScalarOp): ...@@ -1999,7 +1999,7 @@ class Mod(BinaryScalarOp):
"complex numbers, since numpy deprecated it.") "complex numbers, since numpy deprecated it.")
def impl(self, x, y): def impl(self, x, y):
if isinstance(x, numpy.complex) or isinstance(y, numpy.complex): if isinstance(x, np.complex) or isinstance(y, np.complex):
raise self.complex_error raise self.complex_error
return x % y return x % y
...@@ -2249,7 +2249,7 @@ class Cast(UnaryScalarOp): ...@@ -2249,7 +2249,7 @@ class Cast(UnaryScalarOp):
raise TypeError(o_type) raise TypeError(o_type)
super(Cast, self).__init__(specific_out(o_type), name=name) super(Cast, self).__init__(specific_out(o_type), name=name)
self.o_type = o_type self.o_type = o_type
self.ctor = getattr(numpy, o_type.dtype) self.ctor = getattr(np, o_type.dtype)
def __str__(self): def __str__(self):
return '%s{%s}' % (self.__class__.__name__, self.o_type.dtype) return '%s{%s}' % (self.__class__.__name__, self.o_type.dtype)
...@@ -2360,7 +2360,7 @@ class Abs(UnaryScalarOp): ...@@ -2360,7 +2360,7 @@ class Abs(UnaryScalarOp):
return Apply(self, inputs, outputs) return Apply(self, inputs, outputs)
def impl(self, x): def impl(self, x):
return numpy.abs(x) return np.abs(x)
def L_op(self, inputs, outputs, gout): def L_op(self, inputs, outputs, gout):
(x,) = inputs (x,) = inputs
...@@ -2400,7 +2400,7 @@ class Sgn(UnaryScalarOp): ...@@ -2400,7 +2400,7 @@ class Sgn(UnaryScalarOp):
def impl(self, x): def impl(self, x):
# casting to output type is handled by filter # casting to output type is handled by filter
return numpy.sign(x) return np.sign(x)
def grad(self, inputs, gout): def grad(self, inputs, gout):
(x,) = inputs (x,) = inputs
...@@ -2437,7 +2437,7 @@ class Ceil(UnaryScalarOp): ...@@ -2437,7 +2437,7 @@ class Ceil(UnaryScalarOp):
nfunc_spec = ('ceil', 1, 1) nfunc_spec = ('ceil', 1, 1)
def impl(self, x): def impl(self, x):
return numpy.ceil(x) return np.ceil(x)
def grad(self, inputs, gout): def grad(self, inputs, gout):
(x,) = inputs (x,) = inputs
...@@ -2460,7 +2460,7 @@ class Floor(UnaryScalarOp): ...@@ -2460,7 +2460,7 @@ class Floor(UnaryScalarOp):
nfunc_spec = ('floor', 1, 1) nfunc_spec = ('floor', 1, 1)
def impl(self, x): def impl(self, x):
return numpy.floor(x) return np.floor(x)
def grad(self, inputs, gout): def grad(self, inputs, gout):
(x,) = inputs (x,) = inputs
...@@ -2483,7 +2483,7 @@ class Trunc(UnaryScalarOp): ...@@ -2483,7 +2483,7 @@ class Trunc(UnaryScalarOp):
nfunc_spec = ('trunc', 1, 1) nfunc_spec = ('trunc', 1, 1)
def impl(self, x): def impl(self, x):
return numpy.trunc(x) return np.trunc(x)
def grad(self, inputs, gout): def grad(self, inputs, gout):
(x,) = inputs (x,) = inputs
...@@ -2508,7 +2508,7 @@ class RoundHalfToEven(UnaryScalarOp): ...@@ -2508,7 +2508,7 @@ class RoundHalfToEven(UnaryScalarOp):
nfunc_spec = ('around', 1, 1) nfunc_spec = ('around', 1, 1)
def impl(self, x): def impl(self, x):
return numpy.round(x) return np.round(x)
def grad(self, inputs, gout): def grad(self, inputs, gout):
(x,) = inputs (x,) = inputs
...@@ -2561,21 +2561,21 @@ round_half_to_even = RoundHalfToEven(same_out_float_only) ...@@ -2561,21 +2561,21 @@ round_half_to_even = RoundHalfToEven(same_out_float_only)
def round_half_away_from_zero_(a): def round_half_away_from_zero_(a):
if a > 0: if a > 0:
return numpy.floor(a + 0.5) return np.floor(a + 0.5)
else: else:
return numpy.ceil(a - 0.5) return np.ceil(a - 0.5)
round_half_away_from_zero_vec64 = numpy.vectorize( round_half_away_from_zero_vec64 = np.vectorize(
round_half_away_from_zero_, round_half_away_from_zero_,
doc='round_half_away_from_zero_vec64') doc='round_half_away_from_zero_vec64')
round_half_away_from_zero_vec32 = numpy.vectorize( round_half_away_from_zero_vec32 = np.vectorize(
round_half_away_from_zero_, round_half_away_from_zero_,
doc='round_half_away_from_zero_vec32', doc='round_half_away_from_zero_vec32',
otypes=['float32']) otypes=['float32'])
def round_half_away_from_zero_vec(a): def round_half_away_from_zero_vec(a):
if getattr(a, 'dtype', None) == numpy.float32: if getattr(a, 'dtype', None) == np.float32:
return round_half_away_from_zero_vec32(a) return round_half_away_from_zero_vec32(a)
return round_half_away_from_zero_vec64(a) return round_half_away_from_zero_vec64(a)
...@@ -2653,7 +2653,7 @@ class Inv(UnaryScalarOp): ...@@ -2653,7 +2653,7 @@ class Inv(UnaryScalarOp):
""" """
def impl(self, x): def impl(self, x):
return numpy.float32(1.0) / x return np.float32(1.0) / x
def L_op(self, inputs, outputs, gout): def L_op(self, inputs, outputs, gout):
(x,) = inputs (x,) = inputs
...@@ -2691,8 +2691,8 @@ class Log(UnaryScalarOp): ...@@ -2691,8 +2691,8 @@ class Log(UnaryScalarOp):
# half-precision (float16), where we want float32. # half-precision (float16), where we want float32.
x_dtype = str(getattr(x, 'dtype', '')) x_dtype = str(getattr(x, 'dtype', ''))
if x_dtype in ('int8', 'uint8'): if x_dtype in ('int8', 'uint8'):
return numpy.log(x, sig='f') return np.log(x, sig='f')
return numpy.log(x) return np.log(x)
def L_op(self, inputs, outputs, gout): def L_op(self, inputs, outputs, gout):
(x,) = inputs (x,) = inputs
...@@ -2733,8 +2733,8 @@ class Log2(UnaryScalarOp): ...@@ -2733,8 +2733,8 @@ class Log2(UnaryScalarOp):
# half-precision (float16), where we want float32. # half-precision (float16), where we want float32.
x_dtype = str(getattr(x, 'dtype', '')) x_dtype = str(getattr(x, 'dtype', ''))
if x_dtype in ('int8', 'uint8'): if x_dtype in ('int8', 'uint8'):
return numpy.log2(x, sig='f') return np.log2(x, sig='f')
return numpy.log2(x) return np.log2(x)
def L_op(self, inputs, outputs, gout): def L_op(self, inputs, outputs, gout):
(x,) = inputs (x,) = inputs
...@@ -2747,7 +2747,7 @@ class Log2(UnaryScalarOp): ...@@ -2747,7 +2747,7 @@ class Log2(UnaryScalarOp):
else: else:
return [x.zeros_like()] return [x.zeros_like()]
return gz / (x * numpy.asarray(math.log(2.0)).astype(x.dtype)), return gz / (x * np.asarray(math.log(2.0)).astype(x.dtype)),
def c_code(self, node, name, inputs, outputs, sub): def c_code(self, node, name, inputs, outputs, sub):
(x,) = inputs (x,) = inputs
...@@ -2772,8 +2772,8 @@ class Log10(UnaryScalarOp): ...@@ -2772,8 +2772,8 @@ class Log10(UnaryScalarOp):
# half-precision (float16), where we want float32. # half-precision (float16), where we want float32.
x_dtype = str(getattr(x, 'dtype', '')) x_dtype = str(getattr(x, 'dtype', ''))
if x_dtype in ('int8', 'uint8'): if x_dtype in ('int8', 'uint8'):
return numpy.log10(x, sig='f') return np.log10(x, sig='f')
return numpy.log10(x) return np.log10(x)
def L_op(self, inputs, outputs, gout): def L_op(self, inputs, outputs, gout):
(x,) = inputs (x,) = inputs
...@@ -2786,7 +2786,7 @@ class Log10(UnaryScalarOp): ...@@ -2786,7 +2786,7 @@ class Log10(UnaryScalarOp):
else: else:
return [x.zeros_like()] return [x.zeros_like()]
return gz / (x * numpy.log(10.0)), return gz / (x * np.log(10.0)),
def c_code(self, node, name, inputs, outputs, sub): def c_code(self, node, name, inputs, outputs, sub):
(x,) = inputs (x,) = inputs
...@@ -2809,8 +2809,8 @@ class Log1p(UnaryScalarOp): ...@@ -2809,8 +2809,8 @@ class Log1p(UnaryScalarOp):
# half-precision (float16), where we want float32. # half-precision (float16), where we want float32.
x_dtype = str(getattr(x, 'dtype', '')) x_dtype = str(getattr(x, 'dtype', ''))
if x_dtype in ('int8', 'uint8'): if x_dtype in ('int8', 'uint8'):
return numpy.log1p(x, sig='f') return np.log1p(x, sig='f')
return numpy.log1p(x) return np.log1p(x)
def L_op(self, inputs, outputs, gout): def L_op(self, inputs, outputs, gout):
(x,) = inputs (x,) = inputs
...@@ -2844,8 +2844,8 @@ class Exp(UnaryScalarOp): ...@@ -2844,8 +2844,8 @@ class Exp(UnaryScalarOp):
# half-precision (float16), where we want float32. # half-precision (float16), where we want float32.
x_dtype = str(getattr(x, 'dtype', '')) x_dtype = str(getattr(x, 'dtype', ''))
if x_dtype in ('int8', 'uint8'): if x_dtype in ('int8', 'uint8'):
return numpy.exp(x, sig='f') return np.exp(x, sig='f')
return numpy.exp(x) return np.exp(x)
def L_op(self, inputs, outputs, gout): def L_op(self, inputs, outputs, gout):
(x,) = inputs (x,) = inputs
...@@ -2877,8 +2877,8 @@ class Exp2(UnaryScalarOp): ...@@ -2877,8 +2877,8 @@ class Exp2(UnaryScalarOp):
# half-precision (float16), where we want float32. # half-precision (float16), where we want float32.
x_dtype = str(getattr(x, 'dtype', '')) x_dtype = str(getattr(x, 'dtype', ''))
if x_dtype in ('int8', 'uint8'): if x_dtype in ('int8', 'uint8'):
return numpy.exp2(x, sig='f') return np.exp2(x, sig='f')
return numpy.exp2(x) return np.exp2(x)
def L_op(self, inputs, outputs, gout): def L_op(self, inputs, outputs, gout):
(x,) = inputs (x,) = inputs
...@@ -2891,7 +2891,7 @@ class Exp2(UnaryScalarOp): ...@@ -2891,7 +2891,7 @@ class Exp2(UnaryScalarOp):
else: else:
return [x.zeros_like()] return [x.zeros_like()]
return gz * exp2(x) * log(numpy.cast[x.type](2)), return gz * exp2(x) * log(np.cast[x.type](2)),
def c_code(self, node, name, inputs, outputs, sub): def c_code(self, node, name, inputs, outputs, sub):
(x,) = inputs (x,) = inputs
...@@ -2910,8 +2910,8 @@ class Expm1(UnaryScalarOp): ...@@ -2910,8 +2910,8 @@ class Expm1(UnaryScalarOp):
# half-precision (float16), where we want float32. # half-precision (float16), where we want float32.
x_dtype = str(getattr(x, 'dtype', '')) x_dtype = str(getattr(x, 'dtype', ''))
if x_dtype in ('int8', 'uint8'): if x_dtype in ('int8', 'uint8'):
return numpy.expm1(x, sig='f') return np.expm1(x, sig='f')
return numpy.expm1(x) return np.expm1(x)
def L_op(self, inputs, outputs, gout): def L_op(self, inputs, outputs, gout):
(x,) = inputs (x,) = inputs
...@@ -2972,8 +2972,8 @@ class Sqrt(UnaryScalarOp): ...@@ -2972,8 +2972,8 @@ class Sqrt(UnaryScalarOp):
# half-precision (float16), where we want float32. # half-precision (float16), where we want float32.
x_dtype = str(getattr(x, 'dtype', '')) x_dtype = str(getattr(x, 'dtype', ''))
if x_dtype in ('int8', 'uint8'): if x_dtype in ('int8', 'uint8'):
return numpy.sqrt(x, sig='f') return np.sqrt(x, sig='f')
return numpy.sqrt(x) return np.sqrt(x)
def L_op(self, inputs, outputs, gout): def L_op(self, inputs, outputs, gout):
(x,) = inputs (x,) = inputs
...@@ -3005,8 +3005,8 @@ class Deg2Rad(UnaryScalarOp): ...@@ -3005,8 +3005,8 @@ class Deg2Rad(UnaryScalarOp):
# half-precision (float16), where we want float32. # half-precision (float16), where we want float32.
x_dtype = str(getattr(x, 'dtype', '')) x_dtype = str(getattr(x, 'dtype', ''))
if x_dtype in ('int8', 'uint8'): if x_dtype in ('int8', 'uint8'):
return numpy.deg2rad(x, sig='f') return np.deg2rad(x, sig='f')
return numpy.deg2rad(x) return np.deg2rad(x)
def L_op(self, inputs, outputs, gout): def L_op(self, inputs, outputs, gout):
(x,) = inputs (x,) = inputs
...@@ -3019,7 +3019,7 @@ class Deg2Rad(UnaryScalarOp): ...@@ -3019,7 +3019,7 @@ class Deg2Rad(UnaryScalarOp):
else: else:
return [x.zeros_like()] return [x.zeros_like()]
return gz * numpy.asarray(numpy.pi / 180, gz.type), return gz * np.asarray(np.pi / 180, gz.type),
def c_code(self, node, name, inputs, outputs, sub): def c_code(self, node, name, inputs, outputs, sub):
(x,) = inputs (x,) = inputs
...@@ -3038,8 +3038,8 @@ class Rad2Deg(UnaryScalarOp): ...@@ -3038,8 +3038,8 @@ class Rad2Deg(UnaryScalarOp):
# half-precision (float16), where we want float32. # half-precision (float16), where we want float32.
x_dtype = str(getattr(x, 'dtype', '')) x_dtype = str(getattr(x, 'dtype', ''))
if x_dtype in ('int8', 'uint8'): if x_dtype in ('int8', 'uint8'):
return numpy.rad2deg(x, sig='f') return np.rad2deg(x, sig='f')
return numpy.rad2deg(x) return np.rad2deg(x)
def L_op(self, inputs, outputs, gout): def L_op(self, inputs, outputs, gout):
(x,) = inputs (x,) = inputs
...@@ -3052,7 +3052,7 @@ class Rad2Deg(UnaryScalarOp): ...@@ -3052,7 +3052,7 @@ class Rad2Deg(UnaryScalarOp):
else: else:
return [x.zeros_like()] return [x.zeros_like()]
return gz * numpy.asarray(180. / numpy.pi, gz.type), return gz * np.asarray(180. / np.pi, gz.type),
def c_code(self, node, name, inputs, outputs, sub): def c_code(self, node, name, inputs, outputs, sub):
(x,) = inputs (x,) = inputs
...@@ -3073,8 +3073,8 @@ class Cos(UnaryScalarOp): ...@@ -3073,8 +3073,8 @@ class Cos(UnaryScalarOp):
# half-precision (float16), where we want float32. # half-precision (float16), where we want float32.
x_dtype = str(getattr(x, 'dtype', '')) x_dtype = str(getattr(x, 'dtype', ''))
if x_dtype in ('int8', 'uint8'): if x_dtype in ('int8', 'uint8'):
return numpy.cos(x, sig='f') return np.cos(x, sig='f')
return numpy.cos(x) return np.cos(x)
def L_op(self, inputs, outputs, gout): def L_op(self, inputs, outputs, gout):
(x,) = inputs (x,) = inputs
...@@ -3106,8 +3106,8 @@ class ArcCos(UnaryScalarOp): ...@@ -3106,8 +3106,8 @@ class ArcCos(UnaryScalarOp):
# half-precision (float16), where we want float32. # half-precision (float16), where we want float32.
x_dtype = str(getattr(x, 'dtype', '')) x_dtype = str(getattr(x, 'dtype', ''))
if x_dtype in ('int8', 'uint8'): if x_dtype in ('int8', 'uint8'):
return numpy.arccos(x, sig='f') return np.arccos(x, sig='f')
return numpy.arccos(x) return np.arccos(x)
def L_op(self, inputs, outputs, gout): def L_op(self, inputs, outputs, gout):
(x,) = inputs (x,) = inputs
...@@ -3120,7 +3120,7 @@ class ArcCos(UnaryScalarOp): ...@@ -3120,7 +3120,7 @@ class ArcCos(UnaryScalarOp):
else: else:
return [x.zeros_like()] return [x.zeros_like()]
return - gz / sqrt(numpy.cast[x.type](1) - sqr(x)), return - gz / sqrt(np.cast[x.type](1) - sqr(x)),
def c_code(self, node, name, inputs, outputs, sub): def c_code(self, node, name, inputs, outputs, sub):
(x,) = inputs (x,) = inputs
...@@ -3141,8 +3141,8 @@ class Sin(UnaryScalarOp): ...@@ -3141,8 +3141,8 @@ class Sin(UnaryScalarOp):
# half-precision (float16), where we want float32. # half-precision (float16), where we want float32.
x_dtype = str(getattr(x, 'dtype', '')) x_dtype = str(getattr(x, 'dtype', ''))
if x_dtype in ('int8', 'uint8'): if x_dtype in ('int8', 'uint8'):
return numpy.sin(x, sig='f') return np.sin(x, sig='f')
return numpy.sin(x) return np.sin(x)
def L_op(self, inputs, outputs, gout): def L_op(self, inputs, outputs, gout):
(x,) = inputs (x,) = inputs
...@@ -3174,8 +3174,8 @@ class ArcSin(UnaryScalarOp): ...@@ -3174,8 +3174,8 @@ class ArcSin(UnaryScalarOp):
# half-precision (float16), where we want float32. # half-precision (float16), where we want float32.
x_dtype = str(getattr(x, 'dtype', '')) x_dtype = str(getattr(x, 'dtype', ''))
if x_dtype in ('int8', 'uint8'): if x_dtype in ('int8', 'uint8'):
return numpy.arcsin(x, sig='f') return np.arcsin(x, sig='f')
return numpy.arcsin(x) return np.arcsin(x)
def L_op(self, inputs, outputs, gout): def L_op(self, inputs, outputs, gout):
(x,) = inputs (x,) = inputs
...@@ -3188,7 +3188,7 @@ class ArcSin(UnaryScalarOp): ...@@ -3188,7 +3188,7 @@ class ArcSin(UnaryScalarOp):
else: else:
return [x.zeros_like()] return [x.zeros_like()]
return gz / sqrt(numpy.cast[x.type](1) - sqr(x)), return gz / sqrt(np.cast[x.type](1) - sqr(x)),
def c_code(self, node, name, inputs, outputs, sub): def c_code(self, node, name, inputs, outputs, sub):
(x,) = inputs (x,) = inputs
...@@ -3207,8 +3207,8 @@ class Tan(UnaryScalarOp): ...@@ -3207,8 +3207,8 @@ class Tan(UnaryScalarOp):
# half-precision (float16), where we want float32. # half-precision (float16), where we want float32.
x_dtype = str(getattr(x, 'dtype', '')) x_dtype = str(getattr(x, 'dtype', ''))
if x_dtype in ('int8', 'uint8'): if x_dtype in ('int8', 'uint8'):
return numpy.tan(x, sig='f') return np.tan(x, sig='f')
return numpy.tan(x) return np.tan(x)
def L_op(self, inputs, outputs, gout): def L_op(self, inputs, outputs, gout):
(x,) = inputs (x,) = inputs
...@@ -3240,8 +3240,8 @@ class ArcTan(UnaryScalarOp): ...@@ -3240,8 +3240,8 @@ class ArcTan(UnaryScalarOp):
# half-precision (float16), where we want float32. # half-precision (float16), where we want float32.
x_dtype = str(getattr(x, 'dtype', '')) x_dtype = str(getattr(x, 'dtype', ''))
if x_dtype in ('int8', 'uint8'): if x_dtype in ('int8', 'uint8'):
return numpy.arctan(x, sig='f') return np.arctan(x, sig='f')
return numpy.arctan(x) return np.arctan(x)
def L_op(self, inputs, outputs, gout): def L_op(self, inputs, outputs, gout):
(x,) = inputs (x,) = inputs
...@@ -3254,7 +3254,7 @@ class ArcTan(UnaryScalarOp): ...@@ -3254,7 +3254,7 @@ class ArcTan(UnaryScalarOp):
else: else:
return [x.zeros_like()] return [x.zeros_like()]
return gz / (numpy.cast[x.type](1) + sqr(x)), return gz / (np.cast[x.type](1) + sqr(x)),
def c_code(self, node, name, inputs, outputs, sub): def c_code(self, node, name, inputs, outputs, sub):
(x,) = inputs (x,) = inputs
...@@ -3275,8 +3275,8 @@ class ArcTan2(BinaryScalarOp): ...@@ -3275,8 +3275,8 @@ class ArcTan2(BinaryScalarOp):
if x_dtype in ('int8', 'uint8'): if x_dtype in ('int8', 'uint8'):
y_dtype = str(getattr(x, 'dtype', '')) y_dtype = str(getattr(x, 'dtype', ''))
if y_dtype in ('int8', 'uint8'): if y_dtype in ('int8', 'uint8'):
return numpy.arctan2(y, x, sig='f') return np.arctan2(y, x, sig='f')
return numpy.arctan2(y, x) return np.arctan2(y, x)
def L_op(self, inputs, outputs, gout): def L_op(self, inputs, outputs, gout):
(y, x) = inputs (y, x) = inputs
...@@ -3322,8 +3322,8 @@ class Cosh(UnaryScalarOp): ...@@ -3322,8 +3322,8 @@ class Cosh(UnaryScalarOp):
# half-precision (float16), where we want float32. # half-precision (float16), where we want float32.
x_dtype = str(getattr(x, 'dtype', '')) x_dtype = str(getattr(x, 'dtype', ''))
if x_dtype in ('int8', 'uint8'): if x_dtype in ('int8', 'uint8'):
return numpy.cosh(x, sig='f') return np.cosh(x, sig='f')
return numpy.cosh(x) return np.cosh(x)
def L_op(self, inputs, outputs, gout): def L_op(self, inputs, outputs, gout):
(x,) = inputs (x,) = inputs
...@@ -3355,8 +3355,8 @@ class ArcCosh(UnaryScalarOp): ...@@ -3355,8 +3355,8 @@ class ArcCosh(UnaryScalarOp):
# half-precision (float16), where we want float32. # half-precision (float16), where we want float32.
x_dtype = str(getattr(x, 'dtype', '')) x_dtype = str(getattr(x, 'dtype', ''))
if x_dtype in ('int8', 'uint8'): if x_dtype in ('int8', 'uint8'):
return numpy.arccosh(x, sig='f') return np.arccosh(x, sig='f')
return numpy.arccosh(x) return np.arccosh(x)
def L_op(self, inputs, outputs, gout): def L_op(self, inputs, outputs, gout):
(x,) = inputs (x,) = inputs
...@@ -3369,7 +3369,7 @@ class ArcCosh(UnaryScalarOp): ...@@ -3369,7 +3369,7 @@ class ArcCosh(UnaryScalarOp):
else: else:
return [x.zeros_like()] return [x.zeros_like()]
return gz / sqrt(sqr(x) - numpy.cast[x.type](1)), return gz / sqrt(sqr(x) - np.cast[x.type](1)),
def c_code(self, node, name, inputs, outputs, sub): def c_code(self, node, name, inputs, outputs, sub):
(x,) = inputs (x,) = inputs
...@@ -3392,8 +3392,8 @@ class Sinh(UnaryScalarOp): ...@@ -3392,8 +3392,8 @@ class Sinh(UnaryScalarOp):
# half-precision (float16), where we want float32. # half-precision (float16), where we want float32.
x_dtype = str(getattr(x, 'dtype', '')) x_dtype = str(getattr(x, 'dtype', ''))
if x_dtype in ('int8', 'uint8'): if x_dtype in ('int8', 'uint8'):
return numpy.sinh(x, sig='f') return np.sinh(x, sig='f')
return numpy.sinh(x) return np.sinh(x)
def L_op(self, inputs, outputs, gout): def L_op(self, inputs, outputs, gout):
(x,) = inputs (x,) = inputs
...@@ -3425,8 +3425,8 @@ class ArcSinh(UnaryScalarOp): ...@@ -3425,8 +3425,8 @@ class ArcSinh(UnaryScalarOp):
# half-precision (float16), where we want float32. # half-precision (float16), where we want float32.
x_dtype = str(getattr(x, 'dtype', '')) x_dtype = str(getattr(x, 'dtype', ''))
if x_dtype in ('int8', 'uint8'): if x_dtype in ('int8', 'uint8'):
return numpy.arcsinh(x, sig='f') return np.arcsinh(x, sig='f')
return numpy.arcsinh(x) return np.arcsinh(x)
def L_op(self, inputs, outputs, gout): def L_op(self, inputs, outputs, gout):
(x,) = inputs (x,) = inputs
...@@ -3439,7 +3439,7 @@ class ArcSinh(UnaryScalarOp): ...@@ -3439,7 +3439,7 @@ class ArcSinh(UnaryScalarOp):
else: else:
return [x.zeros_like()] return [x.zeros_like()]
return gz / sqrt(sqr(x) + numpy.cast[x.type](1)), return gz / sqrt(sqr(x) + np.cast[x.type](1)),
def c_code(self, node, name, inputs, outputs, sub): def c_code(self, node, name, inputs, outputs, sub):
(x,) = inputs (x,) = inputs
...@@ -3463,8 +3463,8 @@ class Tanh(UnaryScalarOp): ...@@ -3463,8 +3463,8 @@ class Tanh(UnaryScalarOp):
# half-precision (float16), where we want float32. # half-precision (float16), where we want float32.
x_dtype = str(getattr(x, 'dtype', '')) x_dtype = str(getattr(x, 'dtype', ''))
if x_dtype in ('int8', 'uint8'): if x_dtype in ('int8', 'uint8'):
return numpy.tanh(x, sig='f') return np.tanh(x, sig='f')
return numpy.tanh(x) return np.tanh(x)
def L_op(self, inputs, outputs, gout): def L_op(self, inputs, outputs, gout):
(x,) = inputs (x,) = inputs
...@@ -3496,8 +3496,8 @@ class ArcTanh(UnaryScalarOp): ...@@ -3496,8 +3496,8 @@ class ArcTanh(UnaryScalarOp):
# half-precision (float16), where we want float32. # half-precision (float16), where we want float32.
x_dtype = str(getattr(x, 'dtype', '')) x_dtype = str(getattr(x, 'dtype', ''))
if x_dtype in ('int8', 'uint8'): if x_dtype in ('int8', 'uint8'):
return numpy.arctanh(x, sig='f') return np.arctanh(x, sig='f')
return numpy.arctanh(x) return np.arctanh(x)
def L_op(self, inputs, outputs, gout): def L_op(self, inputs, outputs, gout):
(x,) = inputs (x,) = inputs
...@@ -3510,7 +3510,7 @@ class ArcTanh(UnaryScalarOp): ...@@ -3510,7 +3510,7 @@ class ArcTanh(UnaryScalarOp):
else: else:
return [x.zeros_like()] return [x.zeros_like()]
return gz / (numpy.cast[x.type](1) - sqr(x)), return gz / (np.cast[x.type](1) - sqr(x)),
def c_code(self, node, name, inputs, outputs, sub): def c_code(self, node, name, inputs, outputs, sub):
(x,) = inputs (x,) = inputs
...@@ -3530,7 +3530,7 @@ class Real(UnaryScalarOp): ...@@ -3530,7 +3530,7 @@ class Real(UnaryScalarOp):
# nfunc_spec = ('real', 1, 1) # nfunc_spec = ('real', 1, 1)
def impl(self, x): def impl(self, x):
return numpy.real(x) return np.real(x)
def grad(self, inputs, gout): def grad(self, inputs, gout):
(x,) = inputs (x,) = inputs
...@@ -3544,7 +3544,7 @@ class Imag(UnaryScalarOp): ...@@ -3544,7 +3544,7 @@ class Imag(UnaryScalarOp):
nfunc_spec = ('imag', 1, 1) nfunc_spec = ('imag', 1, 1)
def impl(self, x): def impl(self, x):
return numpy.imag(x) return np.imag(x)
def grad(self, inputs, gout): def grad(self, inputs, gout):
(x,) = inputs (x,) = inputs
...@@ -3563,7 +3563,7 @@ class Angle(UnaryScalarOp): ...@@ -3563,7 +3563,7 @@ class Angle(UnaryScalarOp):
nfunc_spec = ('angle', 1, 1) nfunc_spec = ('angle', 1, 1)
def impl(self, x): def impl(self, x):
return numpy.angle(x) return np.angle(x)
def grad(self, inputs, gout): def grad(self, inputs, gout):
# y = x.imag # y = x.imag
...@@ -3610,7 +3610,7 @@ class Complex(BinaryScalarOp): ...@@ -3610,7 +3610,7 @@ class Complex(BinaryScalarOp):
return [complex64] return [complex64]
def impl(self, x, y): def impl(self, x, y):
return numpy.complex(x, y) return np.complex(x, y)
def grad(self, inputs, gout): def grad(self, inputs, gout):
(x, y) = inputs (x, y) = inputs
...@@ -3624,7 +3624,7 @@ class Conj(UnaryScalarOp): ...@@ -3624,7 +3624,7 @@ class Conj(UnaryScalarOp):
nfunc_spec = ('conj', 1, 1) nfunc_spec = ('conj', 1, 1)
def impl(self, x): def impl(self, x):
return numpy.conj(x) return np.conj(x)
def c_code(self, node, name, inputs, outputs, sub): def c_code(self, node, name, inputs, outputs, sub):
(x,) = inputs (x,) = inputs
...@@ -3646,12 +3646,12 @@ class ComplexFromPolar(BinaryScalarOp): ...@@ -3646,12 +3646,12 @@ class ComplexFromPolar(BinaryScalarOp):
def impl(self, r, theta): def impl(self, r, theta):
if r < 0: if r < 0:
raise ValueError('polar radius must be non-negative', r) raise ValueError('polar radius must be non-negative', r)
x = r * numpy.cos(theta) x = r * np.cos(theta)
y = r * numpy.sin(theta) y = r * np.sin(theta)
if x.dtype == 'float32': if x.dtype == 'float32':
return numpy.complex64(numpy.complex(x, y)) return np.complex64(np.complex(x, y))
else: else:
return numpy.complex128(numpy.complex(x, y)) return np.complex128(np.complex(x, y))
def grad(self, inputs, gout): def grad(self, inputs, gout):
(r, theta) = inputs (r, theta) = inputs
......
...@@ -2,7 +2,7 @@ from __future__ import absolute_import, print_function, division ...@@ -2,7 +2,7 @@ from __future__ import absolute_import, print_function, division
# Definitions of theano.scalar ops that have their python implementation taken # Definitions of theano.scalar ops that have their python implementation taken
# from SciPy. As SciPy is not always available, we treat them separately. # from SciPy. As SciPy is not always available, we treat them separately.
import numpy import numpy as np
import theano import theano
from theano.gradient import grad_not_implemented from theano.gradient import grad_not_implemented
...@@ -43,7 +43,7 @@ class Erf(UnaryScalarOp): ...@@ -43,7 +43,7 @@ class Erf(UnaryScalarOp):
else: else:
return [x.zeros_like()] return [x.zeros_like()]
cst = numpy.asarray(2. / numpy.sqrt(numpy.pi), cst = np.asarray(2. / np.sqrt(np.pi),
dtype=upcast(x.type.dtype, gz.type.dtype)) dtype=upcast(x.type.dtype, gz.type.dtype))
return gz * cst * exp(-x * x), return gz * cst * exp(-x * x),
...@@ -74,7 +74,7 @@ class Erfc(UnaryScalarOp): ...@@ -74,7 +74,7 @@ class Erfc(UnaryScalarOp):
else: else:
return [x.zeros_like()] return [x.zeros_like()]
cst = numpy.asarray(2. / numpy.sqrt(numpy.pi), cst = np.asarray(2. / np.sqrt(np.pi),
dtype=upcast(x.type.dtype, gz.type.dtype)) dtype=upcast(x.type.dtype, gz.type.dtype))
return - gz * cst * exp(-x * x), return - gz * cst * exp(-x * x),
...@@ -120,7 +120,7 @@ class Erfcx(UnaryScalarOp): ...@@ -120,7 +120,7 @@ class Erfcx(UnaryScalarOp):
else: else:
return [x.zeros_like()] return [x.zeros_like()]
cst = numpy.asarray(2. / numpy.sqrt(numpy.pi), cst = np.asarray(2. / np.sqrt(np.pi),
dtype=upcast(x.type.dtype, gz.type.dtype)) dtype=upcast(x.type.dtype, gz.type.dtype))
return gz * (-cst + (2. * x) * erfcx(x)), return gz * (-cst + (2. * x) * erfcx(x)),
...@@ -155,7 +155,7 @@ class Erfinv(UnaryScalarOp): ...@@ -155,7 +155,7 @@ class Erfinv(UnaryScalarOp):
else: else:
return [x.zeros_like()] return [x.zeros_like()]
cst = numpy.asarray(numpy.sqrt(numpy.pi) / 2., cst = np.asarray(np.sqrt(np.pi) / 2.,
dtype=upcast(x.type.dtype, gz.type.dtype)) dtype=upcast(x.type.dtype, gz.type.dtype))
return gz * cst * exp(erfinv(x) ** 2), return gz * cst * exp(erfinv(x) ** 2),
...@@ -188,7 +188,7 @@ class Erfcinv(UnaryScalarOp): ...@@ -188,7 +188,7 @@ class Erfcinv(UnaryScalarOp):
else: else:
return [x.zeros_like()] return [x.zeros_like()]
cst = numpy.asarray(numpy.sqrt(numpy.pi) / 2., cst = np.asarray(np.sqrt(np.pi) / 2.,
dtype=upcast(x.type.dtype, gz.type.dtype)) dtype=upcast(x.type.dtype, gz.type.dtype))
return - gz * cst * exp(erfcinv(x) ** 2), return - gz * cst * exp(erfcinv(x) ** 2),
......
...@@ -16,7 +16,7 @@ way (as scan does) to create a shared variable of this kind. ...@@ -16,7 +16,7 @@ way (as scan does) to create a shared variable of this kind.
""" """
from __future__ import absolute_import, print_function, division from __future__ import absolute_import, print_function, division
import numpy import numpy as np
from six import integer_types from six import integer_types
from theano.compile import SharedVariable from theano.compile import SharedVariable
...@@ -48,15 +48,15 @@ def shared(value, name=None, strict=False, allow_downcast=None): ...@@ -48,15 +48,15 @@ def shared(value, name=None, strict=False, allow_downcast=None):
We implement this using 0-d tensors for now. We implement this using 0-d tensors for now.
""" """
if not isinstance(value, (numpy.number, float, integer_types, complex)): if not isinstance(value, (np.number, float, integer_types, complex)):
raise TypeError() raise TypeError()
try: try:
dtype = value.dtype dtype = value.dtype
except AttributeError: except AttributeError:
dtype = numpy.asarray(value).dtype dtype = np.asarray(value).dtype
dtype = str(dtype) dtype = str(dtype)
value = getattr(numpy, dtype)(value) value = getattr(np, dtype)(value)
scalar_type = Scalar(dtype=dtype) scalar_type = Scalar(dtype=dtype)
rval = ScalarSharedVariable( rval = ScalarSharedVariable(
type=scalar_type, type=scalar_type,
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论