提交 a0eb0ad0 authored 作者: Michael Osthege's avatar Michael Osthege 提交者: Thomas Wiecki

Move constants and helper functions in configdefaults

+ BITWIDTHs are now constants in utils. + Lambdas and local functions for default/filter/validate are now module-level local functions. This fixes pickleability (closes #240).
上级 cd98c61a
...@@ -242,16 +242,16 @@ def test_no_more_dotting(): ...@@ -242,16 +242,16 @@ def test_no_more_dotting():
def test_mode_apply(): def test_mode_apply():
assert configdefaults.filter_mode("DebugMode") == "DebugMode" assert configdefaults._filter_mode("DebugMode") == "DebugMode"
with pytest.raises(ValueError, match="Expected one of"): with pytest.raises(ValueError, match="Expected one of"):
configdefaults.filter_mode("not_a_mode") configdefaults._filter_mode("not_a_mode")
# test with theano.Mode instance # test with theano.Mode instance
import theano.compile.mode import theano.compile.mode
assert ( assert (
configdefaults.filter_mode(theano.compile.mode.FAST_COMPILE) configdefaults._filter_mode(theano.compile.mode.FAST_COMPILE)
== theano.compile.mode.FAST_COMPILE == theano.compile.mode.FAST_COMPILE
) )
......
差异被折叠。
...@@ -23,13 +23,13 @@ import numpy.distutils ...@@ -23,13 +23,13 @@ import numpy.distutils
import theano import theano
from theano import config from theano import config
from theano.configdefaults import gcc_version_str, local_bitwidth from theano.configdefaults import gcc_version_str
# we will abuse the lockfile mechanism when reading and writing the registry # we will abuse the lockfile mechanism when reading and writing the registry
from theano.gof import compilelock from theano.gof import compilelock
from theano.gof.utils import flatten, hash_from_code from theano.gof.utils import flatten, hash_from_code
from theano.link.c.exceptions import MissingGXX from theano.link.c.exceptions import MissingGXX
from theano.utils import output_subprocess_Popen, subprocess_Popen from theano.utils import LOCAL_BITWIDTH, output_subprocess_Popen, subprocess_Popen
importlib = None importlib = None
...@@ -2308,7 +2308,7 @@ class GCC_compiler(Compiler): ...@@ -2308,7 +2308,7 @@ class GCC_compiler(Compiler):
if not any(["arm" in flag for flag in cxxflags]) and not any( if not any(["arm" in flag for flag in cxxflags]) and not any(
arch in platform.machine() for arch in ["arm", "aarch"] arch in platform.machine() for arch in ["arm", "aarch"]
): ):
n_bits = local_bitwidth() n_bits = LOCAL_BITWIDTH
cxxflags.append(f"-m{int(n_bits)}") cxxflags.append(f"-m{int(n_bits)}")
_logger.debug(f"Compiling for {n_bits} bit architecture") _logger.debug(f"Compiling for {n_bits} bit architecture")
...@@ -2317,7 +2317,7 @@ class GCC_compiler(Compiler): ...@@ -2317,7 +2317,7 @@ class GCC_compiler(Compiler):
# '-fPIC ignored for target (all code is position independent)' # '-fPIC ignored for target (all code is position independent)'
cxxflags.append("-fPIC") cxxflags.append("-fPIC")
if sys.platform == "win32" and local_bitwidth() == 64: if sys.platform == "win32" and LOCAL_BITWIDTH == 64:
# Under 64-bit Windows installation, sys.platform is 'win32'. # Under 64-bit Windows installation, sys.platform is 'win32'.
# We need to define MS_WIN64 for the preprocessor to be able to # We need to define MS_WIN64 for the preprocessor to be able to
# link with libpython. # link with libpython.
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
import inspect import inspect
import os import os
import struct
import subprocess import subprocess
import sys import sys
import traceback import traceback
...@@ -21,12 +22,35 @@ __all__ = [ ...@@ -21,12 +22,35 @@ __all__ = [
"subprocess_Popen", "subprocess_Popen",
"call_subprocess_Popen", "call_subprocess_Popen",
"output_subprocess_Popen", "output_subprocess_Popen",
"LOCAL_BITWIDTH",
"PYTHON_INT_BITWIDTH",
] ]
__excepthooks = [] __excepthooks = []
LOCAL_BITWIDTH = struct.calcsize("P") * 8
"""
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.
Note that according to Python documentation, `platform.architecture()` is
not reliable on OS X with universal binaries.
Also, sys.maxsize does not exist in Python < 2.6.
'P' denotes a void*, and the size is expressed in bytes.
"""
PYTHON_INT_BITWIDTH = struct.calcsize("l") * 8
"""
The bit width of Python int (C long int).
Note that it can be different from the size of a memory pointer.
'l' denotes a C long int, and the size is expressed in bytes.
"""
def __call_excepthooks(type, value, trace): def __call_excepthooks(type, value, trace):
""" """
This function is meant to replace excepthook and do some This function is meant to replace excepthook and do some
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论