提交 e9264ec6 authored 作者: Olivier Delalleau's avatar Olivier Delalleau

Merge pull request #534 from lamblin/fix_for_win64

Fix for win64
...@@ -556,7 +556,7 @@ class Test_pfunc(unittest.TestCase): ...@@ -556,7 +556,7 @@ class Test_pfunc(unittest.TestCase):
def test_default_updates_input(self): def test_default_updates_input(self):
x = shared(0) x = shared(0)
y = shared(1) y = shared(1)
if theano.gof.cmodule.local_bitwidth() == 32: if theano.gof.cmodule.python_int_bitwidth() == 32:
a = iscalar('a') a = iscalar('a')
else: else:
a = lscalar('a') a = lscalar('a')
......
...@@ -16,7 +16,7 @@ class Test_SharedVariable(unittest.TestCase): ...@@ -16,7 +16,7 @@ class Test_SharedVariable(unittest.TestCase):
assert shared(7, dtype='float64').type == Scalar('float64') assert shared(7, dtype='float64').type == Scalar('float64')
else: else:
if theano.gof.cmodule.local_bitwidth()==32: if theano.gof.cmodule.python_int_bitwidth() == 32:
assert shared(7).type == theano.tensor.iscalar, shared(7).type assert shared(7).type == theano.tensor.iscalar, shared(7).type
else: else:
assert shared(7).type == theano.tensor.lscalar, shared(7).type assert shared(7).type == theano.tensor.lscalar, shared(7).type
......
...@@ -5,6 +5,7 @@ import cPickle ...@@ -5,6 +5,7 @@ import cPickle
import logging import logging
import operator import operator
import os import os
import platform
import shutil import shutil
import stat import stat
import StringIO import StringIO
...@@ -28,13 +29,23 @@ AddConfigVar('cmodule.mac_framework_link', ...@@ -28,13 +29,23 @@ AddConfigVar('cmodule.mac_framework_link',
BoolParam(False)) BoolParam(False))
def local_bitwidth(): def local_bitwidth():
"""Return 32 for 32bit arch, 64 for 64bit arch""" """
# Note - it seems from an informal survey of machines at scipy2010 Return 32 for 32bit arch, 64 for 64bit arch
# that platform.architecture is also a reliable way to get the bitwidth
try: By "architecture", we mean the size of memory pointers (size_t in C),
maxint = sys.maxint *not* the size of long int, as it can be different.
except AttributeError: # python 3 compatibility """
maxint = sys.maxsize # Platform.architecture is not reliable on OS X with universal binaries
maxsize = sys.maxsize
return len('%x' % maxsize) * 4
def python_int_bitwidth():
"""
Return the bit width of Python int (C long int).
Note that it can be different from the size of a memory pointer.
"""
maxint = sys.maxint
return len('%x' % maxint) * 4 return len('%x' % maxint) * 4
_logger=logging.getLogger("theano.gof.cmodule") _logger=logging.getLogger("theano.gof.cmodule")
......
...@@ -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,16 @@ class ScanSaveMem(gof.Optimizer): ...@@ -515,15 +515,16 @@ 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) in (int, long) 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 +756,7 @@ class ScanSaveMem(gof.Optimizer): ...@@ -755,7 +756,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
...@@ -1413,10 +1413,14 @@ class _tensor_py_operators: ...@@ -1413,10 +1413,14 @@ class _tensor_py_operators:
return cast(self, dtype) return cast(self, dtype)
#SLICING #SLICING
# def __getitem__(self, args): return Subtensor.from_idxs(self, # Do not define __getslice__ here:
# args).outputs[0] # When calling t[1:], for instance, the arguments passed to __getslice__
# def __getslice__(self, *args): return Subtensor.from_idxs(self, # are (1, sys.maxsize), which is a pain to deal with, and can even not be
# (slice(*args),)).outputs[0] # an int (but a long).
# If __getslice__ does not exist, __getitem__ is called instead, with
# argument slice(1, None, None), which is much more desirable.
# __getslice__ is deprecated in python 2.6 anyway.
def __getitem__(self, args): def __getitem__(self, args):
if not isinstance(args, tuple): if not isinstance(args, tuple):
args = args, args = args,
...@@ -1445,10 +1449,6 @@ class _tensor_py_operators: ...@@ -1445,10 +1449,6 @@ class _tensor_py_operators:
else: else:
return Subtensor(args)(self, *Subtensor.collapse(args, lambda entry: isinstance(entry, Variable))) return Subtensor(args)(self, *Subtensor.collapse(args, lambda entry: isinstance(entry, Variable)))
def __getslice__(self, *args):
args = slice(*args),
return self.__getitem__(args)
#COPYING #COPYING
def copy(self): def copy(self):
return tensor_copy(self) return tensor_copy(self)
...@@ -3124,7 +3124,10 @@ def get_canonical_form_slice(theslice, length): ...@@ -3124,7 +3124,10 @@ 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]:
# The special "maxsize" case is probably not needed here,
# as slices containing maxsize are not generated by
# __getslice__ anymore.
stop = defstop stop = defstop
else: else:
stop = switch(lt(stop,0), stop + length, stop) stop = switch(lt(stop,0), stop + length, stop)
...@@ -3246,7 +3249,10 @@ class Subtensor(Op): ...@@ -3246,7 +3249,10 @@ 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:
# The special "maxsize" case is probably not needed here,
# as slices containing maxsize are not generated by
# __getslice__ anymore.
slice_b = Subtensor.convert(b, False) slice_b = Subtensor.convert(b, False)
else: else:
slice_b = None slice_b = None
...@@ -3256,11 +3262,7 @@ class Subtensor(Op): ...@@ -3256,11 +3262,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
...@@ -3348,7 +3350,7 @@ class Subtensor(Op): ...@@ -3348,7 +3350,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:
...@@ -3420,7 +3422,9 @@ class Subtensor(Op): ...@@ -3420,7 +3422,9 @@ 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 = []
NONE_CODE = sys.maxint - 1 #TODO: change that, it might lead to unexpected results,
# see assembla-#767
NONE_CODE = sys.maxsize - 1
pos = [0,1] #annoying version of global variable for init_entry pos = [0,1] #annoying version of global variable for init_entry
def inc_spec_pos(amt): pos[0] += amt def inc_spec_pos(amt): pos[0] += amt
...@@ -3637,7 +3641,7 @@ class Subtensor(Op): ...@@ -3637,7 +3641,7 @@ class Subtensor(Op):
@staticmethod @staticmethod
def helper_c_code_cache_version(): def helper_c_code_cache_version():
return (3,) return (4,)
def c_code(self, node, name, inputs, outputs, sub): #DEBUG def c_code(self, node, name, inputs, outputs, sub): #DEBUG
part0 = self.helper_c_code(node, name, inputs, outputs, sub, part0 = self.helper_c_code(node, name, inputs, outputs, sub,
...@@ -3694,7 +3698,7 @@ class SubtensorPrinter: ...@@ -3694,7 +3698,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
...@@ -3705,10 +3709,6 @@ class SubtensorPrinter: ...@@ -3705,10 +3709,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.")
......
...@@ -1507,7 +1507,7 @@ def local_useless_subtensor(node): ...@@ -1507,7 +1507,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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论