提交 2730024a authored 作者: amrithasuresh's avatar amrithasuresh

Updated numpy as np

上级 5e5d1bb2
......@@ -2,7 +2,7 @@ from __future__ import absolute_import, print_function, division
import sys
from copy import copy
import numpy
import numpy as np
from six import iteritems, integer_types
from six.moves import xrange
......@@ -21,7 +21,7 @@ from theano.misc.frozendict import frozendict
config = theano.config
_numpy_ver = [int(n) for n in numpy.__version__.split('.')[:2]]
_numpy_ver = [int(n) for n in np.__version__.split('.')[:2]]
# tensor depends on elemwise to provide definitions for several ops
......@@ -148,7 +148,7 @@ class DimShuffle(Op):
# isinstance(x, integer_types) returning False for
# numpy integers. See
# <http://projects.scipy.org/numpy/ticket/2235>.
if not isinstance(j, (integer_types, numpy.integer)):
if not isinstance(j, (integer_types, np.integer)):
raise TypeError(
"DimShuffle indices must be python ints. "
"Got: '%s' of type '%s'.",
......@@ -228,7 +228,7 @@ class DimShuffle(Op):
storage, = out
# drop
res = input
if type(res) != numpy.ndarray and type(res) != numpy.memmap:
if type(res) != np.ndarray and type(res) != np.memmap:
raise TypeError(res)
# transpose
......@@ -242,9 +242,9 @@ class DimShuffle(Op):
# copy (if not inplace)
if not self.inplace:
res = numpy.copy(res)
res = np.copy(res)
storage[0] = numpy.asarray(res) # asarray puts scalars back into array
storage[0] = np.asarray(res) # asarray puts scalars back into array
def infer_shape(self, node, shapes):
ishp, = shapes
......@@ -487,7 +487,7 @@ second dimension
nfunc_spec = getattr(scalar_op, 'nfunc_spec', None)
self.nfunc_spec = nfunc_spec
if nfunc_spec:
self.nfunc = getattr(numpy, nfunc_spec[0])
self.nfunc = getattr(np, nfunc_spec[0])
super(Elemwise, self).__init__(openmp=openmp)
......@@ -504,9 +504,9 @@ second dimension
self.nfunc = None
self.inplace_pattern = frozendict(self.inplace_pattern)
if getattr(self, 'nfunc_spec', None):
self.nfunc = getattr(numpy, self.nfunc_spec[0])
self.nfunc = getattr(np, self.nfunc_spec[0])
elif 0 < self.scalar_op.nin < 32:
self.ufunc = numpy.frompyfunc(self.scalar_op.impl,
self.ufunc = np.frompyfunc(self.scalar_op.impl,
self.scalar_op.nin,
self.scalar_op.nout)
......@@ -723,7 +723,7 @@ second dimension
# the gradient contains a constant, translate it as
# an equivalent TensorType of size 1 and proper number of
# dimensions
res = theano.tensor.constant(numpy.asarray(r.data),
res = theano.tensor.constant(np.asarray(r.data),
dtype=r.type.dtype)
return DimShuffle((), ['x'] * nd)(res)
......@@ -750,7 +750,7 @@ second dimension
self.ufunc is None and
impl == 'py'):
ufunc = numpy.frompyfunc(self.scalar_op.impl,
ufunc = np.frompyfunc(self.scalar_op.impl,
len(node.inputs),
self.scalar_op.nout)
if self.scalar_op.nin > 0:
......@@ -772,9 +772,9 @@ second dimension
# when the input is complex. So add it only when inputs is int.
out_dtype = node.outputs[0].dtype
if (out_dtype in theano.tensor.float_dtypes and
isinstance(self.nfunc, numpy.ufunc) and
isinstance(self.nfunc, np.ufunc) and
node.inputs[0].dtype in theano.tensor.discrete_dtypes):
char = numpy.sctype2char(out_dtype)
char = np.sctype2char(out_dtype)
sig = char * node.nin + '->' + char * node.nout
node.tag.sig = sig
node.tag.fake_node = Apply(
......@@ -870,7 +870,7 @@ second dimension
if getattr(variable, "dtype", "") == 'object':
# Since numpy 1.6, function created with numpy.frompyfunc
# always return an ndarray with dtype object
variable = numpy.asarray(variable, dtype=nout.dtype)
variable = np.asarray(variable, dtype=nout.dtype)
if i in self.inplace_pattern:
odat = inputs[self.inplace_pattern[i]]
......@@ -879,15 +879,15 @@ second dimension
# Sometimes NumPy return a Python type.
# Some Theano op return a different dtype like floor, ceil,
# trunc, eq, ...
elif (not isinstance(variable, numpy.ndarray) or
elif (not isinstance(variable, np.ndarray) or
variable.dtype != nout.dtype):
variable = numpy.asarray(variable, nout.dtype)
variable = np.asarray(variable, nout.dtype)
# The next line is needed for numpy 1.9. Otherwise
# there are tests that fail in DebugMode.
# Normally we would call theano.misc._asarray, but it
# is faster to inline the code. We know that the dtype
# are the same string, just different typenum.
if numpy.dtype(nout.dtype).num != variable.dtype.num:
if np.dtype(nout.dtype).num != variable.dtype.num:
variable = variable.view(dtype=nout.dtype)
storage[0] = variable
# numpy.real return a view!
......@@ -1302,9 +1302,9 @@ class CAReduce(Op):
# There is a bug in numpy that results in isinstance(x,
# integer_types) returning False for numpy integers. See
# <http://projects.scipy.org/numpy/ticket/2235>.
elif isinstance(axis, (integer_types, numpy.integer)):
elif isinstance(axis, (integer_types, np.integer)):
self.axis = (axis,)
elif isinstance(axis, numpy.ndarray) and axis.ndim == 0:
elif isinstance(axis, np.ndarray) and axis.ndim == 0:
self.axis = (int(axis),)
else:
self.axis = list(set(int(a) for a in axis))
......@@ -1316,26 +1316,26 @@ class CAReduce(Op):
def set_ufunc(self, scalar_op):
# This is probably a speed up of the implementation
if isinstance(scalar_op, theano.scalar.basic.Add):
self.ufunc = numpy.add
self.ufunc = np.add
elif isinstance(scalar_op, theano.scalar.basic.Mul):
self.ufunc = numpy.multiply
self.ufunc = np.multiply
elif isinstance(scalar_op, theano.scalar.basic.Maximum):
self.ufunc = numpy.maximum
self.ufunc = np.maximum
elif isinstance(scalar_op, theano.scalar.basic.Minimum):
self.ufunc = numpy.minimum
self.ufunc = np.minimum
elif (isinstance(scalar_op, theano.scalar.basic.AND) and
_numpy_ver >= [1, 12]):
# numpy.bitwise_and.identity was incorrect for versions before
# 1.12 (it was 1 instead of -1), so we skip it in that case.
# We will fall back to the "else:" case, which defines a
# ufunc without identity.
self.ufunc = numpy.bitwise_and
self.ufunc = np.bitwise_and
elif isinstance(scalar_op, theano.scalar.basic.OR):
self.ufunc = numpy.bitwise_or
self.ufunc = np.bitwise_or
elif isinstance(scalar_op, theano.scalar.basic.XOR):
self.ufunc = numpy.bitwise_xor
self.ufunc = np.bitwise_xor
else:
self.ufunc = numpy.frompyfunc(scalar_op.impl, 2, 1)
self.ufunc = np.frompyfunc(scalar_op.impl, 2, 1)
def _output_dtype(self, input_dtype):
return input_dtype
......@@ -1415,7 +1415,7 @@ class CAReduce(Op):
# Compute the shape of the output
v_shape = list(variable.shape)
del v_shape[dimension]
variable = numpy.empty(tuple(v_shape),
variable = np.empty(tuple(v_shape),
dtype=acc_dtype)
variable.fill(self.scalar_op.identity)
else:
......@@ -1427,8 +1427,8 @@ class CAReduce(Op):
variable = self.ufunc.reduce(variable, dimension,
dtype=acc_dtype)
variable = numpy.asarray(variable)
if numpy.may_share_memory(variable, input):
variable = np.asarray(variable)
if np.may_share_memory(variable, input):
# perhaps numpy is clever for reductions of size 1?
# We don't want this.
variable = variable.copy()
......@@ -1436,7 +1436,7 @@ class CAReduce(Op):
dtype=node.outputs[0].type.dtype)
else:
# Force a copy
output[0] = numpy.array(variable, copy=True,
output[0] = np.array(variable, copy=True,
dtype=node.outputs[0].type.dtype)
def infer_shape(self, node, shapes):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论