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