提交 2a84ab12 authored 作者: Pascal Lamblin's avatar Pascal Lamblin

Use sys.maxsize instead of maxint.

This should really be maxsize, but under linux and win32, both values are equal. That is not the case for win64, though. TODO: Maybe remove the special case for maxsize in slices, since no new slice with maxsize should be produced anymore.
上级 e9073c35
...@@ -497,7 +497,7 @@ class ScanSaveMem(gof.Optimizer): ...@@ -497,7 +497,7 @@ class ScanSaveMem(gof.Optimizer):
stop = tensor.basic.extract_constant(cf_slice[0].stop) stop = tensor.basic.extract_constant(cf_slice[0].stop)
else: else:
stop = tensor.basic.extract_constant(cf_slice[0]) + 1 stop = tensor.basic.extract_constant(cf_slice[0]) + 1
if stop == sys.maxint or stop == length: if stop == sys.maxsize or stop == length:
stop = None stop = None
else: else:
# there is a **gotcha** here ! Namely, scan returns an # there is a **gotcha** here ! Namely, scan returns an
...@@ -515,15 +515,15 @@ class ScanSaveMem(gof.Optimizer): ...@@ -515,15 +515,15 @@ class ScanSaveMem(gof.Optimizer):
# yes if it is a tensor # yes if it is a tensor
if isinstance(stop, tensor.Variable): if isinstance(stop, tensor.Variable):
global_nsteps['sym'] += [stop] global_nsteps['sym'] += [stop]
# not if it is maxint # not if it is maxsize
elif (type(stop) is int and stop == sys.maxint): elif (type(stop) is int and stop == sys.maxsize):
global_nsteps = None global_nsteps = None
# yes if it is a int k, 0 < k < maxint # yes if it is a int k, 0 < k < maxsize
elif (type(stop) is int and elif (type(stop) in (int, long) 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 < maxint # yes if it is a int k, 0 < k < maxsize
elif (type(stop) is int and stop > 0): elif (type(stop) in (int, long) and stop > 0):
pass pass
# not otherwise # not otherwise
else: else:
...@@ -755,7 +755,7 @@ class ScanSaveMem(gof.Optimizer): ...@@ -755,7 +755,7 @@ class ScanSaveMem(gof.Optimizer):
start = (cnf_slice[0].start - nw_steps - start = (cnf_slice[0].start - nw_steps -
init_l[pos] + store_steps[pos]) init_l[pos] + store_steps[pos])
if (cnf_slice[0].stop is not None and if (cnf_slice[0].stop is not None and
cnf_slice[0].stop != sys.maxint): cnf_slice[0].stop != sys.maxsize):
stop = (cnf_slice[0].stop - nw_steps - stop = (cnf_slice[0].stop - nw_steps -
init_l[pos] + store_steps[pos]) init_l[pos] + store_steps[pos])
else: else:
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
__docformat__ = "restructuredtext en" __docformat__ = "restructuredtext en"
import __builtin__ import __builtin__
import sys # for sys.maxint import sys # for sys.maxsize
from theano.configparser import config from theano.configparser import config
import warnings import warnings
from itertools import izip from itertools import izip
...@@ -3116,7 +3116,7 @@ def get_canonical_form_slice(theslice, length): ...@@ -3116,7 +3116,7 @@ def get_canonical_form_slice(theslice, length):
start = switch(ge(start,length) start = switch(ge(start,length)
, switch(lt(step,0),length-1,length) , switch(lt(step,0),length-1,length)
, start) , start)
if stop in [None, sys.maxint]: if stop in [None, sys.maxsize]:
stop = defstop stop = defstop
else: else:
stop = switch(lt(stop,0), stop + length, stop) stop = switch(lt(stop,0), stop + length, stop)
...@@ -3238,7 +3238,7 @@ class Subtensor(Op): ...@@ -3238,7 +3238,7 @@ class Subtensor(Op):
else: else:
slice_a = None slice_a = None
if b is not None: if b is not None and b != sys.maxsize:
slice_b = Subtensor.convert(b, False) slice_b = Subtensor.convert(b, False)
else: else:
slice_b = None slice_b = None
...@@ -3248,11 +3248,7 @@ class Subtensor(Op): ...@@ -3248,11 +3248,7 @@ class Subtensor(Op):
else: else:
slice_c = None slice_c = None
return slice(slice_a,slice_b,slice_c) return slice(slice_a, slice_b, slice_c)
#backport
#return slice(Subtensor.convert(a, False) if a is not None else None,
# Subtensor.convert(b, False) if b is not None else None,
# Subtensor.convert(c, False) if c is not None else None)
elif isinstance(entry, int): elif isinstance(entry, int):
return entry return entry
...@@ -3340,7 +3336,7 @@ class Subtensor(Op): ...@@ -3340,7 +3336,7 @@ class Subtensor(Op):
# If it is the default (None, None, None) slice, or a variant, # If it is the default (None, None, None) slice, or a variant,
# the shape will be xl # the shape will be xl
if ( (idx.start in [None, 0]) if ( (idx.start in [None, 0])
and (idx.stop in [None, sys.maxint]) and (idx.stop in [None, sys.maxsize])
and (idx.step is None or idx.step == 1) ): and (idx.step is None or idx.step == 1) ):
outshp.append(xl) outshp.append(xl)
else: else:
...@@ -3412,6 +3408,7 @@ class Subtensor(Op): ...@@ -3412,6 +3408,7 @@ class Subtensor(Op):
fail = sub['fail'] fail = sub['fail']
init_cmds = [] # initialization for subtensor_spec init_cmds = [] # initialization for subtensor_spec
is_slice = [] is_slice = []
#TODO: change that, there can be more than sys.maxint elements
NONE_CODE = sys.maxint - 1 NONE_CODE = sys.maxint - 1
pos = [0,1] #annoying version of global variable for init_entry pos = [0,1] #annoying version of global variable for init_entry
...@@ -3686,7 +3683,7 @@ class SubtensorPrinter: ...@@ -3686,7 +3683,7 @@ class SubtensorPrinter:
else: else:
msg1 = entry.start msg1 = entry.start
if entry.stop is None or entry.stop == sys.maxint: if entry.stop is None or entry.stop == sys.maxsize:
msg2 = "" msg2 = ""
else: else:
msg2 = entry.stop msg2 = entry.stop
...@@ -3697,10 +3694,6 @@ class SubtensorPrinter: ...@@ -3697,10 +3694,6 @@ class SubtensorPrinter:
msg3 = ":%s" % entry.step msg3 = ":%s" % entry.step
sidxs.append("%s:%s%s" % (msg1, msg2, msg3)) sidxs.append("%s:%s%s" % (msg1, msg2, msg3))
#backport
#sidxs.append("%s:%s%s" % ("" if entry.start is None or entry.start == 0 else entry.start,
# "" if entry.stop is None or entry.stop == sys.maxint else entry.stop,
# "" if entry.step is None else ":%s" % entry.step))
return "%s[%s]" % (pstate.pprinter.process(input, pstate.clone(precedence = 1000)), ", ".join(sidxs)) return "%s[%s]" % (pstate.pprinter.process(input, pstate.clone(precedence = 1000)), ", ".join(sidxs))
else: else:
raise TypeError("Can only print Subtensor.") raise TypeError("Can only print Subtensor.")
......
...@@ -1510,7 +1510,7 @@ def local_useless_subtensor(node): ...@@ -1510,7 +1510,7 @@ def local_useless_subtensor(node):
# is not a useless subtensor # is not a useless subtensor
return False return False
length_pos_data = sys.maxint length_pos_data = sys.maxsize
length_pos = shape_of[node.inputs[0]][pos] length_pos = shape_of[node.inputs[0]][pos]
try: try:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论