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

Updated numpy as np

上级 85fb68bc
......@@ -4,7 +4,7 @@ import copy
import traceback as tb
import warnings
import numpy
import numpy as np
from six import integer_types
from six.moves import xrange
......@@ -462,7 +462,7 @@ class _tensor_py_operators(object):
def check_bool(args_el):
try:
if (isinstance(args_el, (numpy.bool_, bool)) or
if (isinstance(args_el, (np.bool_, bool)) or
args_el.dtype == 'bool'):
raise TypeError('TensorType does not support boolean '
'mask for indexing such as tensor[x==0]. '
......@@ -495,7 +495,7 @@ class _tensor_py_operators(object):
elif len(ellipses) == 1:
new_axes = sum(1
for index in args
if index is numpy.newaxis) # numpy.newaxis is None
if index is np.newaxis) # numpy.newaxis is None
ellipsis_at = ellipses[0]
args = list(args)
args[ellipsis_at: ellipsis_at + 1] = (
......@@ -503,7 +503,7 @@ class _tensor_py_operators(object):
# Force input to be int64 datatype if input is an empty list or tuple
# Else leave it as is if it is a real number
args = tuple([numpy.array(inp, dtype=numpy.int64)
args = tuple([np.array(inp, dtype=np.int64)
if(inp == [] or inp == ()) else inp for inp in args])
# Convert python literals to theano constants
args = theano.tensor.subtensor.make_constant(args)
......@@ -515,7 +515,7 @@ class _tensor_py_operators(object):
axis = None
for i, arg in enumerate(args):
try:
if arg is not numpy.newaxis:
if arg is not np.newaxis:
theano.tensor.subtensor.Subtensor.convert(arg)
except theano.tensor.subtensor.AdvancedIndexingError:
if advanced:
......@@ -532,14 +532,14 @@ class _tensor_py_operators(object):
all(isinstance(a, slice) and
equal_slices(a, slice(None)) for a in args[axis + 1:]) and
isinstance(args[axis],
(numpy.ndarray, list,
(np.ndarray, list,
TensorVariable, TensorConstant,
theano.tensor.sharedvar.TensorSharedVariable))):
return self.take(args[axis], axis)
else:
return theano.tensor.subtensor.advanced_subtensor(self, *args)
else:
if numpy.newaxis in args:
if np.newaxis in args:
# None (aka np.newaxis) in numpy indexing means to add a
# broadcastable dimension, which theano traditionally did with
# the dimshuffle op. The following code converts numpy-style
......@@ -550,7 +550,7 @@ class _tensor_py_operators(object):
pattern = []
new_args = []
for arg in args:
if arg == numpy.newaxis:
if arg == np.newaxis:
pattern.append('x')
new_args.append(slice(None, None, None))
else:
......@@ -642,7 +642,7 @@ class _tensor_py_operators(object):
def norm(self, L, axis=None, keepdims=False):
if L == 0:
raise NotImplementedError()
if numpy.isinf(L):
if np.isinf(L):
raise NotImplementedError()
# optimizations will/should catch cases like L=1, L=2
y = theano.tensor.basic.pow(
......@@ -862,7 +862,7 @@ class TensorConstantSignature(tuple):
# (note that if there are NaN values in d1, this will return
# False, which is why we do not bother with testing `other.has_nan`
# here).
return (self.sum == other.sum) and numpy.all(d0 == d1)
return (self.sum == other.sum) and np.all(d0 == d1)
def __hash__(self):
t, d = self
......@@ -880,25 +880,25 @@ class TensorConstantSignature(tuple):
self._sum = self.no_nan.sum()
# The following 2 lines are needede as in Python 3.3 with NumPy
# 1.7.1, numpy.ndarray and numpy.memmap aren't hashable.
if type(self._sum) is numpy.memmap:
self._sum = numpy.asarray(self._sum).item()
if type(self._sum) is np.memmap:
self._sum = np.asarray(self._sum).item()
if self.has_nan and self.no_nan.mask.all():
# In this case the sum is not properly computed by numpy.
self._sum = 0
if numpy.isinf(self._sum) or numpy.isnan(self._sum):
if np.isinf(self._sum) or np.isnan(self._sum):
# NaN may happen when there are both -inf and +inf values.
if self.has_nan:
# Filter both NaN and Inf values.
mask = self.no_nan.mask + numpy.isinf(self[1])
mask = self.no_nan.mask + np.isinf(self[1])
else:
# Filter only Inf values.
mask = numpy.isinf(self[1])
mask = np.isinf(self[1])
if mask.all():
self._sum = 0
else:
self._sum = numpy.ma.masked_array(self[1], mask).sum()
self._sum = np.ma.masked_array(self[1], mask).sum()
# At this point there should be no more NaN.
assert not numpy.isnan(self._sum)
assert not np.isnan(self._sum)
return self._sum
sum = property(_get_sum)
......@@ -906,9 +906,9 @@ class TensorConstantSignature(tuple):
try:
return self._no_nan
except AttributeError:
nan_mask = numpy.isnan(self[1])
nan_mask = np.isnan(self[1])
if nan_mask.any():
self._no_nan = numpy.ma.masked_array(self[1], nan_mask)
self._no_nan = np.ma.masked_array(self[1], nan_mask)
self.has_nan = True
else:
self._no_nan = self[1]
......@@ -926,7 +926,7 @@ class TensorConstant(_tensor_py_operators, Constant):
def __init__(self, type, data, name=None):
Constant.__init__(self, type, data, name)
self.tag.unique_value = None
if isinstance(data, numpy.ndarray) and data.ndim > 0:
if isinstance(data, np.ndarray) and data.ndim > 0:
flat_data = data.ravel()
if flat_data.shape[0]:
if (flat_data == flat_data[0]).all():
......@@ -949,7 +949,7 @@ class TensorConstant(_tensor_py_operators, Constant):
def equals(self, other):
# Override Contant.equals to allow to compare with
# numpy.ndarray, and python type.
if isinstance(other, (numpy.ndarray, int, float)):
if isinstance(other, (np.ndarray, int, float)):
# Make a TensorConstant to be able to compare
other = theano.tensor.basic.constant(other)
return (isinstance(other, TensorConstant) and
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论