提交 b17f6ef6 authored 作者: amrithasuresh's avatar amrithasuresh

Updated numpy as np

上级 420eb37b
...@@ -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
...@@ -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
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论