提交 df2fc88f authored 作者: abalkin's avatar abalkin

Issue #783: python3 compatible - remove relative imports.

This commit starts a series of changes to eliminate relative and redundant imports. - do not import theano.tests unless theano.test() function is called. - reuse TheanoConfigParser instance from configdefaults.
上级 5a421ca3
...@@ -36,18 +36,12 @@ logging_default_handler.setFormatter(logging_default_formatter) ...@@ -36,18 +36,12 @@ logging_default_handler.setFormatter(logging_default_formatter)
theano_logger.addHandler(logging_default_handler) theano_logger.addHandler(logging_default_handler)
theano_logger.setLevel(logging.WARNING) theano_logger.setLevel(logging.WARNING)
import configparser from theano.configdefaults import config
import configdefaults
config = configparser.TheanoConfigParser()
# Version information. # Version information.
import theano.version from theano.version import version as __version__
__version__ = theano.version.version
import gof
from gof import \ from theano.gof import \
CLinker, OpWiseCLinker, DualLinker, Linker, LocalLinker, PerformLinker, \ CLinker, OpWiseCLinker, DualLinker, Linker, LocalLinker, PerformLinker, \
Container, \ Container, \
InconsistencyError, FunctionGraph, \ InconsistencyError, FunctionGraph, \
...@@ -58,9 +52,7 @@ from gof import \ ...@@ -58,9 +52,7 @@ from gof import \
Type, Generic, generic, \ Type, Generic, generic, \
object2, utils object2, utils
import compile from theano.compile import \
from compile import \
SymbolicInput, In, \ SymbolicInput, In, \
SymbolicOutput, Out, \ SymbolicOutput, Out, \
Mode, \ Mode, \
...@@ -71,31 +63,23 @@ from compile import \ ...@@ -71,31 +63,23 @@ from compile import \
ProfileMode, \ ProfileMode, \
Param, shared Param, shared
from misc.safe_asarray import _asarray from theano.misc.safe_asarray import _asarray
import theano.tests
if hasattr(theano.tests, "TheanoNoseTester"):
test = theano.tests.TheanoNoseTester().test
else:
def test():
raise ImportError("The nose module is not installed."
" It is needed for Theano tests.")
FancyModule = Module FancyModule = Module
from printing import \ from theano.printing import pprint, pp
pprint, pp
import scan_module
from scan_module import scan, map, reduce, foldl, foldr, clone
from updates import Updates, OrderedUpdates from theano.scan_module import scan, map, reduce, foldl, foldr, clone
import tensor from theano.updates import Updates, OrderedUpdates
import scalar
# scan_module import above initializes tensor and scalar making these imports redundant
#import tensor
#import scalar
#we don't import by default as we don't want to force having scipy installed. #we don't import by default as we don't want to force having scipy installed.
#import sparse #import sparse
import gradient
from gradient import Rop, Lop, grad from theano.gradient import Rop, Lop, grad
if config.device.startswith('gpu') or config.init_gpu_device.startswith('gpu'): if config.device.startswith('gpu') or config.init_gpu_device.startswith('gpu'):
import theano.sandbox.cuda import theano.sandbox.cuda
...@@ -162,6 +146,9 @@ def dot(l, r): ...@@ -162,6 +146,9 @@ def dot(l, r):
(e0, e1)) (e0, e1))
return rval return rval
# Used by get_scalar_constant_value() below. Can be eliminated by looking into globals().
import theano
def get_scalar_constant_value(v): def get_scalar_constant_value(v):
"""return the constant scalar(0-D) value underlying variable `v` """return the constant scalar(0-D) value underlying variable `v`
...@@ -181,3 +168,13 @@ def get_scalar_constant_value(v): ...@@ -181,3 +168,13 @@ def get_scalar_constant_value(v):
data = v.owner.inputs[0] data = v.owner.inputs[0]
return tensor.get_scalar_constant_value(data) return tensor.get_scalar_constant_value(data)
return tensor.get_scalar_constant_value(v) return tensor.get_scalar_constant_value(v)
def test(**kwds):
try:
from theano.tests import TheanoNoseTester
except ImportError:
raise ImportError("The nose module is not installed."
" It is needed for Theano tests.")
else:
return TheanoNoseTester().test(**kwds)
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论