提交 fb4a7b3c authored 作者: David Warde-Farley's avatar David Warde-Farley 提交者: Arnaud Bergeron

Use integer_types in place of long.

上级 61c3957b
......@@ -16,7 +16,7 @@ from itertools import count
import theano
import warnings
from theano.gof import utils
from theano.compat.six import string_types
from theano.compat.six import string_types, integer_types
from theano.misc.ordered_set import OrderedSet
# Lazy imports to avoid circular dependencies.
......@@ -147,7 +147,7 @@ class Apply(Node):
else:
raise AttributeError(
"%s.default_output should be an output index." % self.op)
elif not isinstance(do, (int, long)):
elif not isinstance(do, integer_types):
raise AttributeError("%s.default_output should be an int or long" %
self.op)
elif do < 0 or do >= len(self.outputs):
......
......@@ -13,7 +13,7 @@ import hashlib
import numpy as np
import collections
from theano.compat.six import string_types
from theano.compat.six import string_types, integer_types
try:
import pydot as pd
......@@ -112,7 +112,7 @@ def debugprint(obj, depth=-1, print_type=False,
results_to_print.extend(obj.outputs)
profile_list.extend([None for item in obj.outputs])
order = obj.toposort()
elif isinstance(obj, (int, long, float, np.ndarray)):
elif isinstance(obj, (integer_types, float, np.ndarray)):
print(obj)
elif isinstance(obj, (theano.In, theano.Out)):
results_to_print.append(obj.variable)
......
......@@ -67,6 +67,7 @@ from theano import tensor
from theano.tensor import opt, get_scalar_constant_value
from theano import gof
from theano.compat import OrderedDict
from theano.compat.six import integer_types
from theano.gof.opt import Optimizer
from theano.gof import toolbox, DestroyHandler, InconsistencyError
from theano.compile import optdb
......@@ -1163,15 +1164,15 @@ class ScanSaveMem(gof.Optimizer):
if isinstance(stop, tensor.Variable):
global_nsteps['sym'] += [stop]
# not if it is maxsize
elif (type(stop) in (int, long) and
elif (type(stop) in integer_types and
stop == maxsize):
global_nsteps = None
# yes if it is a int k, 0 < k < maxsize
elif (type(stop) in (int, long) and
elif (type(stop) in integer_types and
global_nsteps['real'] < stop):
global_nsteps['real'] = stop
# yes if it is a int k, 0 < k < maxsize
elif (type(stop) in (int, long) and stop > 0):
elif (type(stop) in integer_types and stop > 0):
pass
# not otherwise
else:
......
......@@ -357,7 +357,7 @@ def constant_or_value(x, rtype, name=None, ndim=None, dtype=None):
x_ = autocast_int(x)
elif rtype is TensorConstant and isinstance(x, float):
x_ = autocast_float(x)
elif rtype is TensorConstant and isinstance(x, long):
elif rtype is TensorConstant and isinstance(x, integer_types):
# We need to address the case where a long number is used in a
# Theano graph, because on Windows 64, all shapes are expressed
# with longs.
......@@ -3870,8 +3870,8 @@ def stack(*tensors):
# See ticket #660
if numpy.all(
[ # in case there is direct int in tensors.
isinstance(t, (numpy.number, float, int, python_complex,
long)) or
isinstance(t, (numpy.number, float, integer_types,
python_complex)) or
(isinstance(t, Variable) and
isinstance(t.type, TensorType) and
t.ndim == 0)
......@@ -4436,7 +4436,7 @@ def tile(x, reps, ndim=None):
iter(reps)
except TypeError:
raise ValueError("reps must be iterable")
if not numpy.all([isinstance(r, (int, long)) or
if not numpy.all([isinstance(r, integer_types) or
(isinstance(r, TensorVariable) and
r.dtype in ["int8", "int16", "int32", "int64"]) for r in reps]):
raise ValueError("elements of reps must be scalars of integer dtype")
......
......@@ -21,6 +21,7 @@ import numpy as N # guys... please don't do this in the library :(
import theano
from theano import gof
from theano.compat.six import integer_types
from theano.compat.six.moves import reduce
from theano.gof import opt, InconsistencyError, TopoOptimizer, graph
from theano.gof import Variable, Constant
......@@ -840,7 +841,7 @@ class ShapeFeature(object):
# don't make the optimizer merge a zillion ones together
# by always returning the same object to represent 1
return self.lscalar_one
if (type(s_i) in (int, long) or
if (type(s_i) in integer_types or
isinstance(s_i, numpy.integer) or
(isinstance(s_i, numpy.ndarray) and s_i.ndim == 0)):
# this shape is a constant
......
......@@ -10,6 +10,7 @@ _logger = logging.getLogger("theano.tensor.subtensor")
import numpy
import theano
from theano.compat.six import integer_types
from theano.gradient import DisconnectedType
from theano import gof
from theano.gof import Apply, Constant, hashtype, Op, Type, MethodNotDefined
......@@ -59,7 +60,7 @@ def make_constant(args):
return slice(conv(a.start),
conv(a.stop),
conv(a.step))
elif isinstance(a, (int, long, numpy.integer)):
elif isinstance(a, (integer_types, numpy.integer)):
return scal.ScalarConstant(scal.int64, a)
else:
return a
......@@ -376,7 +377,7 @@ class Subtensor(Op):
slice_c = None
return slice(slice_a, slice_b, slice_c)
elif isinstance(entry, (int, long, numpy.integer)):
elif isinstance(entry, (integer_types, numpy.integer)):
# Disallow the use of python scalars in idx_list
raise TypeError("Python scalar in idx_list."
"Please report this error to theano-dev.")
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论