提交 f16aee3d authored 作者: nouiz's avatar nouiz

Merge pull request #547 from lamblin/yet_another_size_fix

Yet another size fix
......@@ -9,6 +9,7 @@ import platform
import shutil
import stat
import StringIO
import struct
import subprocess
import sys
import tempfile
......@@ -37,8 +38,9 @@ def local_bitwidth():
"""
# Note that according to Python documentation, `platform.architecture()` is
# not reliable on OS X with universal binaries.
maxsize = sys.maxsize
return len('%x' % maxsize) * 4
# Also, sys.maxsize does not exist in Python < 2.6.
# 'P' denotes a void*, and the size is expressed in bytes.
return struct.calcsize('P') * 8
def python_int_bitwidth():
"""
......@@ -46,8 +48,8 @@ def python_int_bitwidth():
Note that it can be different from the size of a memory pointer.
"""
maxint = sys.maxint
return len('%x' % maxint) * 4
# 'l' denotes a C long int, and the size is expressed in bytes.
return struct.calcsize('l') * 8
_logger=logging.getLogger("theano.gof.cmodule")
_logger.setLevel(logging.WARNING)
......
......@@ -130,5 +130,22 @@ if sys.version_info[:2] < (2,6):
for prod in result:
yield tuple(prod)
# For maxsize
class __Dummy(object):
"""
Dummy class used to know what is the max index of a slice.
This way, we do not have to rely on guesses for untested
architectures.
"""
def __getslice__(self, *args):
return args
# This "slice" should be a (1, maxsize) tuple
__dummy_slice = __Dummy()[1:]
maxsize = __dummy_slice[1]
del __dummy_slice, __Dummy
else:
from itertools import combinations, product
from sys import maxsize
......@@ -14,12 +14,12 @@ __contact__ = "Razvan Pascanu <r.pascanu@gmail>"
import logging
import numpy
import sys
import theano
from theano import tensor
from theano.tensor import opt, get_constant_value
from theano import gof
from theano.gof.python25 import maxsize
from theano.compile import optdb
from theano import config
from theano.compile.function_module import deep_copy_op
......@@ -497,7 +497,7 @@ class ScanSaveMem(gof.Optimizer):
stop = tensor.basic.extract_constant(cf_slice[0].stop)
else:
stop = tensor.basic.extract_constant(cf_slice[0]) + 1
if stop == sys.maxsize or stop == length:
if stop == maxsize or stop == length:
stop = None
else:
# there is a **gotcha** here ! Namely, scan returns an
......@@ -517,7 +517,7 @@ class ScanSaveMem(gof.Optimizer):
global_nsteps['sym'] += [stop]
# not if it is maxsize
elif (type(stop) in (int, long) and
stop == sys.maxsize):
stop == maxsize):
global_nsteps = None
# yes if it is a int k, 0 < k < maxsize
elif (type(stop) in (int, long) and
......@@ -756,7 +756,7 @@ class ScanSaveMem(gof.Optimizer):
start = (cnf_slice[0].start - nw_steps -
init_l[pos] + store_steps[pos])
if (cnf_slice[0].stop is not None and
cnf_slice[0].stop != sys.maxsize):
cnf_slice[0].stop != maxsize):
stop = (cnf_slice[0].stop - nw_steps -
init_l[pos] + store_steps[pos])
else:
......
......@@ -3,7 +3,7 @@
__docformat__ = "restructuredtext en"
import __builtin__
import sys # for sys.maxsize
import sys
from theano.configparser import config
import warnings
from itertools import izip
......@@ -17,7 +17,7 @@ from theano.gof import Apply, Constant, Op, Type, Value, Variable
import elemwise
from theano import scalar as scal
from theano.gof.python25 import partial, any, all
from theano.gof.python25 import partial, any, all, maxsize
from theano import compile, printing
from theano.printing import pprint, min_informative_str
from theano.tensor.utils import hash_from_ndarray
......@@ -3124,7 +3124,7 @@ def get_canonical_form_slice(theslice, length):
start = switch(ge(start,length)
, switch(lt(step,0),length-1,length)
, start)
if stop in [None, sys.maxsize]:
if stop in [None, maxsize]:
# The special "maxsize" case is probably not needed here,
# as slices containing maxsize are not generated by
# __getslice__ anymore.
......@@ -3249,7 +3249,7 @@ class Subtensor(Op):
else:
slice_a = None
if b is not None and b != sys.maxsize:
if b is not None and b != maxsize:
# The special "maxsize" case is probably not needed here,
# as slices containing maxsize are not generated by
# __getslice__ anymore.
......@@ -3350,7 +3350,7 @@ class Subtensor(Op):
# If it is the default (None, None, None) slice, or a variant,
# the shape will be xl
if ( (idx.start in [None, 0])
and (idx.stop in [None, sys.maxsize])
and (idx.stop in [None, maxsize])
and (idx.step is None or idx.step == 1) ):
outshp.append(xl)
else:
......@@ -3424,7 +3424,7 @@ class Subtensor(Op):
is_slice = []
#TODO: change that, it might lead to unexpected results,
# see assembla-#767
NONE_CODE = sys.maxsize - 1
NONE_CODE = maxsize - 1
pos = [0,1] #annoying version of global variable for init_entry
def inc_spec_pos(amt): pos[0] += amt
......@@ -3698,7 +3698,7 @@ class SubtensorPrinter:
else:
msg1 = entry.start
if entry.stop is None or entry.stop == sys.maxsize:
if entry.stop is None or entry.stop == maxsize:
msg2 = ""
else:
msg2 = entry.stop
......
......@@ -20,6 +20,7 @@ import theano
from theano import gof
from theano.gof import opt, InconsistencyError, TopoOptimizer, graph
from theano.gof import Variable, Constant
from theano.gof.python25 import maxsize
from theano.gof.utils import MethodNotDefined
from theano.configparser import config
from elemwise import Elemwise, DimShuffle
......@@ -1507,7 +1508,7 @@ def local_useless_subtensor(node):
# is not a useless subtensor
return False
length_pos_data = sys.maxsize
length_pos_data = maxsize
length_pos = shape_of[node.inputs[0]][pos]
try:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论