提交 d7a83e6c authored 作者: Pascal Lamblin's avatar Pascal Lamblin

pointer bitwidth and int bitwidth are different

上级 c4fa5db8
......@@ -556,7 +556,7 @@ class Test_pfunc(unittest.TestCase):
def test_default_updates_input(self):
x = shared(0)
y = shared(1)
if theano.gof.cmodule.local_bitwidth() == 32:
if theano.gof.cmodule.python_int_bitwidth() == 32:
a = iscalar('a')
else:
a = lscalar('a')
......
......@@ -16,7 +16,7 @@ class Test_SharedVariable(unittest.TestCase):
assert shared(7, dtype='float64').type == Scalar('float64')
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
else:
assert shared(7).type == theano.tensor.lscalar, shared(7).type
......
......@@ -29,12 +29,24 @@ AddConfigVar('cmodule.mac_framework_link',
BoolParam(False))
def local_bitwidth():
"""Return 32 for 32bit arch, 64 for 64bit arch"""
# Note - it seems from an informal survey of machines at scipy2010
# that platform.architecture is a reliable way to get the bitwidth
arch = platform.architecture()
bit_width = arch[0][:-3]
return int(bit_width)
"""
Return 32 for 32bit arch, 64 for 64bit arch
By "architecture", we mean the size of memory pointers (size_t in C),
*not* the size of long int, as it can be different.
"""
# 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
_logger=logging.getLogger("theano.gof.cmodule")
_logger.setLevel(logging.WARNING)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论