提交 5c4aafee authored 作者: AdeB's avatar AdeB

fix some circular imports

上级 16474203
......@@ -7,15 +7,15 @@ import platform
import textwrap
import re
import socket
import struct
import theano
from theano.configparser import (AddConfigVar, BoolParam, ConfigParam, EnumStr,
FloatParam, IntParam, StrParam,
TheanoConfigParser, THEANO_FLAGS_DICT)
from theano.gof.compiledir import (local_bitwidth, python_int_bitwidth,
gcc_version_str)
from theano.misc.cpucount import cpuCount
from theano.misc.windows import call_subprocess_Popen
from theano.misc.windows import call_subprocess_Popen, output_subprocess_Popen
_logger = logging.getLogger('theano.configdefaults')
......@@ -1097,7 +1097,7 @@ AddConfigVar(
'warn.identify_1pexp_bug',
'Warn if Theano versions prior to 7987b51 (2011-12-18) could have '
'yielded a wrong result due to a bug in the is_1pexp function',
BoolParam(theano.configdefaults.warn_default('0.4.1')),
BoolParam(warn_default('0.4.1')),
in_c_key=False)
AddConfigVar('on_shape_error',
......@@ -1190,6 +1190,41 @@ period for running processes.""",
allow_override=False),
in_c_key=False)
try:
p_out = output_subprocess_Popen([config.cxx, '-dumpversion'])
gcc_version_str = p_out[0].strip().decode()
except OSError:
# Typically means gcc cannot be found.
gcc_version_str = 'GCC_NOT_FOUND'
def local_bitwidth():
"""
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.
"""
# 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.
return struct.calcsize('P') * 8
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.
"""
# 'l' denotes a C long int, and the size is expressed in bytes.
return struct.calcsize('l') * 8
compiledir_format_dict = {
"platform": platform.platform(),
"processor": platform.processor(),
......
......@@ -279,7 +279,7 @@ def AddConfigVar(name, doc, configparam, root=config, in_c_key=True):
try:
fetch_val_for_key(configparam.fullname)
# The user provided a value, filter it now.
configparam.__get__(root, type(root))
configparam.__get__(root, type(root), delete_key=True)
except KeyError:
pass
setattr(root.__class__, sections[0], configparam)
......@@ -307,12 +307,13 @@ class ConfigParam(object):
# Calling `filter` here may actually be harmful if the default value is
# invalid and causes a crash or has unwanted side effects.
def __get__(self, cls, type_):
def __get__(self, cls, type_, delete_key=False):
if cls is None:
return self
if not hasattr(self, 'val'):
try:
val_str = fetch_val_for_key(self.fullname, delete_key=True)
val_str = fetch_val_for_key(self.fullname,
delete_key=delete_key)
self.is_default = False
except KeyError:
if callable(self.default):
......
......@@ -32,7 +32,7 @@ from theano.misc.windows import (subprocess_Popen,
# we will abuse the lockfile mechanism when reading and writing the registry
from theano.gof import compilelock
from theano.gof.compiledir import gcc_version_str, local_bitwidth
from theano.configdefaults import gcc_version_str, local_bitwidth
from theano.configparser import AddConfigVar, BoolParam
......
from __future__ import print_function
import six.moves.cPickle as pickle
import errno
import logging
import os
import platform
import re
import shutil
import struct
import socket
import sys
import numpy
import theano
from six import string_types, iteritems
from theano.configparser import config, AddConfigVar, ConfigParam, StrParam
from theano.configparser import config
from theano.gof.utils import flatten
from theano.misc.windows import output_subprocess_Popen
_logger = logging.getLogger("theano.gof.compiledir")
try:
p_out = output_subprocess_Popen([theano.config.cxx, '-dumpversion'])
gcc_version_str = p_out[0].strip().decode()
except OSError:
# Typically means gcc cannot be found.
gcc_version_str = 'GCC_NOT_FOUND'
def local_bitwidth():
"""
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.
"""
# 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.
return struct.calcsize('P') * 8
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.
"""
# 'l' denotes a C long int, and the size is expressed in bytes.
return struct.calcsize('l') * 8
def cleanup():
"""
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论