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

Updated numpy as np

上级 420eb37b
......@@ -17,7 +17,7 @@ import warnings
from copy import copy
from textwrap import dedent
import numpy
import numpy as np
import six
from six.moves import xrange
......@@ -72,7 +72,7 @@ def upcast(dtype, *dtypes):
keep_float16[0] = False
if dt == 'float32':
keep_float16[0] = False
return numpy.zeros((), dtype=dt)
return np.zeros((), dtype=dt)
z = make_array(dtype)
for dt in dtypes:
z = z + make_array(dt=dt)
......@@ -168,12 +168,12 @@ class NumpyAutocaster(object):
# Make sure we only deal with scalars.
assert (isinstance(x, six.integer_types) 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':
return numpy.asarray(x)
return np.asarray(x)
elif config.cast_policy == 'numpy+floatX':
rval = numpy.asarray(x)
rval = np.asarray(x)
if ((not hasattr(x, 'dtype') and
rval.dtype in ('float64', 'float32') and
rval.dtype != config.floatX)):
......@@ -191,7 +191,7 @@ class NumpyAutocaster(object):
# 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
# one already (e.g. if x == numpy.float64(1.1)).
return numpy.asarray(x)
return np.asarray(x)
except AttributeError:
# Means `x` has no 'dtype' attribute.
pass
......@@ -209,7 +209,7 @@ class NumpyAutocaster(object):
for dtype in try_dtypes:
x_ = theano._asarray(x, dtype=dtype)
if numpy.all(x == x_):
if np.all(x == x_):
break
# returns either an exact x_==x, or the last cast x_
return x_
......@@ -272,16 +272,16 @@ def convert(x, dtype=None):
x_ = theano._asarray(x, dtype='uint64')
elif isinstance(x, builtin_float):
x_ = autocast_float(x)
elif isinstance(x, numpy.ndarray):
elif isinstance(x, np.ndarray):
x_ = x
else:
# Here x is probably a list or a tuple. If it contains a
# long, we will behave like the current NumPy version: it
# 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'):
x_ = numpy.asarray(x, dtype=config.floatX)
assert type(x_) in [numpy.ndarray, numpy.memmap]
x_ = np.asarray(x, dtype=config.floatX)
assert type(x_) in [np.ndarray, np.memmap]
return x_
......@@ -396,21 +396,21 @@ class Scalar(Type):
print(dtype, np.zeros(1, dtype=dtype).dtype.num)
"""
return { # dtype: (py_type, c_type, cls_name)
'float16': (numpy.float16, 'npy_float16', 'Float16'),
'float32': (numpy.float32, 'npy_float32', 'Float32'),
'float64': (numpy.float64, 'npy_float64', 'Float64'),
'complex128': (numpy.complex128, 'theano_complex128',
'float16': (np.float16, 'npy_float16', 'Float16'),
'float32': (np.float32, 'npy_float32', 'Float32'),
'float64': (np.float64, 'npy_float64', 'Float64'),
'complex128': (np.complex128, 'theano_complex128',
'Complex128'),
'complex64': (numpy.complex64, 'theano_complex64', 'Complex64'),
'bool': (numpy.bool_, 'npy_bool', 'Bool'),
'uint8': (numpy.uint8, 'npy_uint8', 'UInt8'),
'int8': (numpy.int8, 'npy_int8', 'Int8'),
'uint16': (numpy.uint16, 'npy_uint16', 'UInt16'),
'int16': (numpy.int16, 'npy_int16', 'Int16'),
'uint32': (numpy.uint32, 'npy_uint32', 'UInt32'),
'int32': (numpy.int32, 'npy_int32', 'Int32'),
'uint64': (numpy.uint64, 'npy_uint64', 'UInt64'),
'int64': (numpy.int64, 'npy_int64', 'Int64')
'complex64': (np.complex64, 'theano_complex64', 'Complex64'),
'bool': (np.bool_, 'npy_bool', 'Bool'),
'uint8': (np.uint8, 'npy_uint8', 'UInt8'),
'int8': (np.int8, 'npy_int8', 'Int8'),
'uint16': (np.uint16, 'npy_uint16', 'UInt16'),
'int16': (np.int16, 'npy_int16', 'Int16'),
'uint32': (np.uint32, 'npy_uint32', 'UInt32'),
'int32': (np.int32, 'npy_int32', 'Int32'),
'uint64': (np.uint64, 'npy_uint64', 'UInt64'),
'int64': (np.int64, 'npy_int64', 'Int64')
}[self.dtype]
except KeyError:
raise TypeError("Unsupported dtype for %s: %s" % (
......@@ -505,8 +505,8 @@ class Scalar(Type):
# 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
# the value 0 (cast to 'int' in C) to a theano_complex64.
if (numpy.dtype('intc').num not in
[numpy.dtype(d[4:]).num for d in real_types]):
if (np.dtype('intc').num not in
[np.dtype(d[4:]).num for d in real_types]):
# In that case we add the 'int' type to the real types.
real_types.append('int')
......@@ -645,7 +645,7 @@ class Scalar(Type):
return ["import_array();"]
def c_code_cache_version(self):
return (13, numpy.__version__)
return (13, np.__version__)
def get_shape_info(self, obj):
return obj.itemsize
......@@ -1247,7 +1247,7 @@ class LT(LogicalComparison):
def impl(self, x, y):
# 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):
(x, y) = inputs
......@@ -1266,7 +1266,7 @@ class GT(LogicalComparison):
def impl(self, x, y):
# 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):
(x, y) = inputs
......@@ -1285,7 +1285,7 @@ class LE(LogicalComparison):
def impl(self, x, y):
# 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):
(x, y) = inputs
......@@ -1304,7 +1304,7 @@ class GE(LogicalComparison):
def impl(self, x, y):
# 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):
(x, y) = inputs
......@@ -1353,7 +1353,7 @@ class IsNan(FixedLogicalComparison):
nfunc_spec = ('isnan', 1, 1)
def impl(self, x):
return numpy.isnan(x)
return np.isnan(x)
def c_code(self, node, name, inputs, outputs, sub):
(x,) = inputs
......@@ -1378,7 +1378,7 @@ class IsInf(FixedLogicalComparison):
nfunc_spec = ('isinf', 1, 1)
def impl(self, x):
return numpy.isinf(x)
return np.isinf(x)
def c_code(self, node, name, inputs, outputs, sub):
(x,) = inputs
......@@ -1596,7 +1596,7 @@ class Maximum(BinaryScalarOp):
def impl(self, *inputs):
# 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):
(x, y) = inputs
......@@ -1633,7 +1633,7 @@ class Minimum(BinaryScalarOp):
def impl(self, *inputs):
# 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):
(x, y) = inputs
......@@ -1709,7 +1709,7 @@ class Mul(ScalarOp):
nfunc_spec = ('multiply', 2, 1)
def impl(self, *inputs):
return numpy.product(inputs)
return np.product(inputs)
def c_code(self, node, name, inputs, outputs, sub):
(z,) = outputs
......@@ -1859,10 +1859,10 @@ class TrueDiv(BinaryScalarOp):
return super(TrueDiv, self).output_types(types)
def impl(self, x, y):
x = numpy.asarray(x)
y = numpy.asarray(y)
x = np.asarray(x)
y = np.asarray(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:
return x / y
......@@ -1999,7 +1999,7 @@ class Mod(BinaryScalarOp):
"complex numbers, since numpy deprecated it.")
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
return x % y
......@@ -2360,7 +2360,7 @@ class Abs(UnaryScalarOp):
return Apply(self, inputs, outputs)
def impl(self, x):
return numpy.abs(x)
return np.abs(x)
def L_op(self, inputs, outputs, gout):
(x,) = inputs
......@@ -2400,7 +2400,7 @@ class Sgn(UnaryScalarOp):
def impl(self, x):
# casting to output type is handled by filter
return numpy.sign(x)
return np.sign(x)
def grad(self, inputs, gout):
(x,) = inputs
......@@ -2437,7 +2437,7 @@ class Ceil(UnaryScalarOp):
nfunc_spec = ('ceil', 1, 1)
def impl(self, x):
return numpy.ceil(x)
return np.ceil(x)
def grad(self, inputs, gout):
(x,) = inputs
......@@ -2460,7 +2460,7 @@ class Floor(UnaryScalarOp):
nfunc_spec = ('floor', 1, 1)
def impl(self, x):
return numpy.floor(x)
return np.floor(x)
def grad(self, inputs, gout):
(x,) = inputs
......@@ -2483,7 +2483,7 @@ class Trunc(UnaryScalarOp):
nfunc_spec = ('trunc', 1, 1)
def impl(self, x):
return numpy.trunc(x)
return np.trunc(x)
def grad(self, inputs, gout):
(x,) = inputs
......@@ -2508,7 +2508,7 @@ class RoundHalfToEven(UnaryScalarOp):
nfunc_spec = ('around', 1, 1)
def impl(self, x):
return numpy.round(x)
return np.round(x)
def grad(self, inputs, gout):
(x,) = inputs
......@@ -2561,21 +2561,21 @@ round_half_to_even = RoundHalfToEven(same_out_float_only)
def round_half_away_from_zero_(a):
if a > 0:
return numpy.floor(a + 0.5)
return np.floor(a + 0.5)
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_,
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_,
doc='round_half_away_from_zero_vec32',
otypes=['float32'])
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_vec64(a)
......@@ -2653,7 +2653,7 @@ class Inv(UnaryScalarOp):
"""
def impl(self, x):
return numpy.float32(1.0) / x
return np.float32(1.0) / x
def L_op(self, inputs, outputs, gout):
(x,) = inputs
......@@ -2691,8 +2691,8 @@ class Log(UnaryScalarOp):
# half-precision (float16), where we want float32.
x_dtype = str(getattr(x, 'dtype', ''))
if x_dtype in ('int8', 'uint8'):
return numpy.log(x, sig='f')
return numpy.log(x)
return np.log(x, sig='f')
return np.log(x)
def L_op(self, inputs, outputs, gout):
(x,) = inputs
......@@ -2733,8 +2733,8 @@ class Log2(UnaryScalarOp):
# half-precision (float16), where we want float32.
x_dtype = str(getattr(x, 'dtype', ''))
if x_dtype in ('int8', 'uint8'):
return numpy.log2(x, sig='f')
return numpy.log2(x)
return np.log2(x, sig='f')
return np.log2(x)
def L_op(self, inputs, outputs, gout):
(x,) = inputs
......@@ -2747,7 +2747,7 @@ class Log2(UnaryScalarOp):
else:
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):
(x,) = inputs
......@@ -2772,8 +2772,8 @@ class Log10(UnaryScalarOp):
# half-precision (float16), where we want float32.
x_dtype = str(getattr(x, 'dtype', ''))
if x_dtype in ('int8', 'uint8'):
return numpy.log10(x, sig='f')
return numpy.log10(x)
return np.log10(x, sig='f')
return np.log10(x)
def L_op(self, inputs, outputs, gout):
(x,) = inputs
......@@ -2786,7 +2786,7 @@ class Log10(UnaryScalarOp):
else:
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):
(x,) = inputs
......@@ -2809,8 +2809,8 @@ class Log1p(UnaryScalarOp):
# half-precision (float16), where we want float32.
x_dtype = str(getattr(x, 'dtype', ''))
if x_dtype in ('int8', 'uint8'):
return numpy.log1p(x, sig='f')
return numpy.log1p(x)
return np.log1p(x, sig='f')
return np.log1p(x)
def L_op(self, inputs, outputs, gout):
(x,) = inputs
......@@ -2844,8 +2844,8 @@ class Exp(UnaryScalarOp):
# half-precision (float16), where we want float32.
x_dtype = str(getattr(x, 'dtype', ''))
if x_dtype in ('int8', 'uint8'):
return numpy.exp(x, sig='f')
return numpy.exp(x)
return np.exp(x, sig='f')
return np.exp(x)
def L_op(self, inputs, outputs, gout):
(x,) = inputs
......@@ -2877,8 +2877,8 @@ class Exp2(UnaryScalarOp):
# half-precision (float16), where we want float32.
x_dtype = str(getattr(x, 'dtype', ''))
if x_dtype in ('int8', 'uint8'):
return numpy.exp2(x, sig='f')
return numpy.exp2(x)
return np.exp2(x, sig='f')
return np.exp2(x)
def L_op(self, inputs, outputs, gout):
(x,) = inputs
......@@ -2891,7 +2891,7 @@ class Exp2(UnaryScalarOp):
else:
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):
(x,) = inputs
......@@ -2910,8 +2910,8 @@ class Expm1(UnaryScalarOp):
# half-precision (float16), where we want float32.
x_dtype = str(getattr(x, 'dtype', ''))
if x_dtype in ('int8', 'uint8'):
return numpy.expm1(x, sig='f')
return numpy.expm1(x)
return np.expm1(x, sig='f')
return np.expm1(x)
def L_op(self, inputs, outputs, gout):
(x,) = inputs
......@@ -2972,8 +2972,8 @@ class Sqrt(UnaryScalarOp):
# half-precision (float16), where we want float32.
x_dtype = str(getattr(x, 'dtype', ''))
if x_dtype in ('int8', 'uint8'):
return numpy.sqrt(x, sig='f')
return numpy.sqrt(x)
return np.sqrt(x, sig='f')
return np.sqrt(x)
def L_op(self, inputs, outputs, gout):
(x,) = inputs
......@@ -3005,8 +3005,8 @@ class Deg2Rad(UnaryScalarOp):
# half-precision (float16), where we want float32.
x_dtype = str(getattr(x, 'dtype', ''))
if x_dtype in ('int8', 'uint8'):
return numpy.deg2rad(x, sig='f')
return numpy.deg2rad(x)
return np.deg2rad(x, sig='f')
return np.deg2rad(x)
def L_op(self, inputs, outputs, gout):
(x,) = inputs
......@@ -3019,7 +3019,7 @@ class Deg2Rad(UnaryScalarOp):
else:
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):
(x,) = inputs
......@@ -3038,8 +3038,8 @@ class Rad2Deg(UnaryScalarOp):
# half-precision (float16), where we want float32.
x_dtype = str(getattr(x, 'dtype', ''))
if x_dtype in ('int8', 'uint8'):
return numpy.rad2deg(x, sig='f')
return numpy.rad2deg(x)
return np.rad2deg(x, sig='f')
return np.rad2deg(x)
def L_op(self, inputs, outputs, gout):
(x,) = inputs
......@@ -3052,7 +3052,7 @@ class Rad2Deg(UnaryScalarOp):
else:
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):
(x,) = inputs
......@@ -3073,8 +3073,8 @@ class Cos(UnaryScalarOp):
# half-precision (float16), where we want float32.
x_dtype = str(getattr(x, 'dtype', ''))
if x_dtype in ('int8', 'uint8'):
return numpy.cos(x, sig='f')
return numpy.cos(x)
return np.cos(x, sig='f')
return np.cos(x)
def L_op(self, inputs, outputs, gout):
(x,) = inputs
......@@ -3106,8 +3106,8 @@ class ArcCos(UnaryScalarOp):
# half-precision (float16), where we want float32.
x_dtype = str(getattr(x, 'dtype', ''))
if x_dtype in ('int8', 'uint8'):
return numpy.arccos(x, sig='f')
return numpy.arccos(x)
return np.arccos(x, sig='f')
return np.arccos(x)
def L_op(self, inputs, outputs, gout):
(x,) = inputs
......@@ -3120,7 +3120,7 @@ class ArcCos(UnaryScalarOp):
else:
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):
(x,) = inputs
......@@ -3141,8 +3141,8 @@ class Sin(UnaryScalarOp):
# half-precision (float16), where we want float32.
x_dtype = str(getattr(x, 'dtype', ''))
if x_dtype in ('int8', 'uint8'):
return numpy.sin(x, sig='f')
return numpy.sin(x)
return np.sin(x, sig='f')
return np.sin(x)
def L_op(self, inputs, outputs, gout):
(x,) = inputs
......@@ -3174,8 +3174,8 @@ class ArcSin(UnaryScalarOp):
# half-precision (float16), where we want float32.
x_dtype = str(getattr(x, 'dtype', ''))
if x_dtype in ('int8', 'uint8'):
return numpy.arcsin(x, sig='f')
return numpy.arcsin(x)
return np.arcsin(x, sig='f')
return np.arcsin(x)
def L_op(self, inputs, outputs, gout):
(x,) = inputs
......@@ -3188,7 +3188,7 @@ class ArcSin(UnaryScalarOp):
else:
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):
(x,) = inputs
......@@ -3207,8 +3207,8 @@ class Tan(UnaryScalarOp):
# half-precision (float16), where we want float32.
x_dtype = str(getattr(x, 'dtype', ''))
if x_dtype in ('int8', 'uint8'):
return numpy.tan(x, sig='f')
return numpy.tan(x)
return np.tan(x, sig='f')
return np.tan(x)
def L_op(self, inputs, outputs, gout):
(x,) = inputs
......@@ -3240,8 +3240,8 @@ class ArcTan(UnaryScalarOp):
# half-precision (float16), where we want float32.
x_dtype = str(getattr(x, 'dtype', ''))
if x_dtype in ('int8', 'uint8'):
return numpy.arctan(x, sig='f')
return numpy.arctan(x)
return np.arctan(x, sig='f')
return np.arctan(x)
def L_op(self, inputs, outputs, gout):
(x,) = inputs
......@@ -3254,7 +3254,7 @@ class ArcTan(UnaryScalarOp):
else:
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):
(x,) = inputs
......@@ -3275,8 +3275,8 @@ class ArcTan2(BinaryScalarOp):
if x_dtype in ('int8', 'uint8'):
y_dtype = str(getattr(x, 'dtype', ''))
if y_dtype in ('int8', 'uint8'):
return numpy.arctan2(y, x, sig='f')
return numpy.arctan2(y, x)
return np.arctan2(y, x, sig='f')
return np.arctan2(y, x)
def L_op(self, inputs, outputs, gout):
(y, x) = inputs
......@@ -3322,8 +3322,8 @@ class Cosh(UnaryScalarOp):
# half-precision (float16), where we want float32.
x_dtype = str(getattr(x, 'dtype', ''))
if x_dtype in ('int8', 'uint8'):
return numpy.cosh(x, sig='f')
return numpy.cosh(x)
return np.cosh(x, sig='f')
return np.cosh(x)
def L_op(self, inputs, outputs, gout):
(x,) = inputs
......@@ -3355,8 +3355,8 @@ class ArcCosh(UnaryScalarOp):
# half-precision (float16), where we want float32.
x_dtype = str(getattr(x, 'dtype', ''))
if x_dtype in ('int8', 'uint8'):
return numpy.arccosh(x, sig='f')
return numpy.arccosh(x)
return np.arccosh(x, sig='f')
return np.arccosh(x)
def L_op(self, inputs, outputs, gout):
(x,) = inputs
......@@ -3369,7 +3369,7 @@ class ArcCosh(UnaryScalarOp):
else:
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):
(x,) = inputs
......@@ -3392,8 +3392,8 @@ class Sinh(UnaryScalarOp):
# half-precision (float16), where we want float32.
x_dtype = str(getattr(x, 'dtype', ''))
if x_dtype in ('int8', 'uint8'):
return numpy.sinh(x, sig='f')
return numpy.sinh(x)
return np.sinh(x, sig='f')
return np.sinh(x)
def L_op(self, inputs, outputs, gout):
(x,) = inputs
......@@ -3425,8 +3425,8 @@ class ArcSinh(UnaryScalarOp):
# half-precision (float16), where we want float32.
x_dtype = str(getattr(x, 'dtype', ''))
if x_dtype in ('int8', 'uint8'):
return numpy.arcsinh(x, sig='f')
return numpy.arcsinh(x)
return np.arcsinh(x, sig='f')
return np.arcsinh(x)
def L_op(self, inputs, outputs, gout):
(x,) = inputs
......@@ -3439,7 +3439,7 @@ class ArcSinh(UnaryScalarOp):
else:
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):
(x,) = inputs
......@@ -3463,8 +3463,8 @@ class Tanh(UnaryScalarOp):
# half-precision (float16), where we want float32.
x_dtype = str(getattr(x, 'dtype', ''))
if x_dtype in ('int8', 'uint8'):
return numpy.tanh(x, sig='f')
return numpy.tanh(x)
return np.tanh(x, sig='f')
return np.tanh(x)
def L_op(self, inputs, outputs, gout):
(x,) = inputs
......@@ -3496,8 +3496,8 @@ class ArcTanh(UnaryScalarOp):
# half-precision (float16), where we want float32.
x_dtype = str(getattr(x, 'dtype', ''))
if x_dtype in ('int8', 'uint8'):
return numpy.arctanh(x, sig='f')
return numpy.arctanh(x)
return np.arctanh(x, sig='f')
return np.arctanh(x)
def L_op(self, inputs, outputs, gout):
(x,) = inputs
......@@ -3510,7 +3510,7 @@ class ArcTanh(UnaryScalarOp):
else:
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):
(x,) = inputs
......@@ -3530,7 +3530,7 @@ class Real(UnaryScalarOp):
# nfunc_spec = ('real', 1, 1)
def impl(self, x):
return numpy.real(x)
return np.real(x)
def grad(self, inputs, gout):
(x,) = inputs
......@@ -3544,7 +3544,7 @@ class Imag(UnaryScalarOp):
nfunc_spec = ('imag', 1, 1)
def impl(self, x):
return numpy.imag(x)
return np.imag(x)
def grad(self, inputs, gout):
(x,) = inputs
......@@ -3563,7 +3563,7 @@ class Angle(UnaryScalarOp):
nfunc_spec = ('angle', 1, 1)
def impl(self, x):
return numpy.angle(x)
return np.angle(x)
def grad(self, inputs, gout):
# y = x.imag
......@@ -3610,7 +3610,7 @@ class Complex(BinaryScalarOp):
return [complex64]
def impl(self, x, y):
return numpy.complex(x, y)
return np.complex(x, y)
def grad(self, inputs, gout):
(x, y) = inputs
......@@ -3624,7 +3624,7 @@ class Conj(UnaryScalarOp):
nfunc_spec = ('conj', 1, 1)
def impl(self, x):
return numpy.conj(x)
return np.conj(x)
def c_code(self, node, name, inputs, outputs, sub):
(x,) = inputs
......@@ -3646,12 +3646,12 @@ class ComplexFromPolar(BinaryScalarOp):
def impl(self, r, theta):
if r < 0:
raise ValueError('polar radius must be non-negative', r)
x = r * numpy.cos(theta)
y = r * numpy.sin(theta)
x = r * np.cos(theta)
y = r * np.sin(theta)
if x.dtype == 'float32':
return numpy.complex64(numpy.complex(x, y))
return np.complex64(np.complex(x, y))
else:
return numpy.complex128(numpy.complex(x, y))
return np.complex128(np.complex(x, y))
def grad(self, inputs, gout):
(r, theta) = inputs
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论