提交 de05e842 authored 作者: lamblin's avatar lamblin

Merge pull request #1224 from abalkin/no-relative-imports

Issue #783: python3 compatible - remove relative imports.
...@@ -31,36 +31,28 @@ import logging ...@@ -31,36 +31,28 @@ import logging
theano_logger = logging.getLogger("theano") theano_logger = logging.getLogger("theano")
logging_default_handler = logging.StreamHandler() logging_default_handler = logging.StreamHandler()
logging_default_formatter = logging.Formatter( logging_default_formatter = logging.Formatter(
fmt='%(levelname)s (%(name)s): %(message)s') fmt='%(levelname)s (%(name)s): %(message)s')
logging_default_handler.setFormatter(logging_default_formatter) 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
from theano.gof import \
import gof CLinker, OpWiseCLinker, DualLinker, Linker, LocalLinker, PerformLinker, \
Container, \
from gof import \ InconsistencyError, FunctionGraph, \
CLinker, OpWiseCLinker, DualLinker, Linker, LocalLinker, PerformLinker, \ Apply, Variable, Constant, \
Container, \ Op, OpenMPOp, \
InconsistencyError, FunctionGraph, \ opt, \
Apply, Variable, Constant, \ toolbox, \
Op, OpenMPOp,\ Type, Generic, generic, \
opt, \ object2, utils
toolbox, \
Type, Generic, generic, \ from theano.compile import \
object2, utils
import compile
from compile import \
SymbolicInput, In, \ SymbolicInput, In, \
SymbolicOutput, Out, \ SymbolicOutput, Out, \
Mode, \ Mode, \
...@@ -71,43 +63,37 @@ from compile import \ ...@@ -71,43 +63,37 @@ 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 theano.scan_module import scan, map, reduce, foldl, foldr, clone
from scan_module import scan, map, reduce, foldl, foldr, clone
from updates import Updates, OrderedUpdates from theano.updates import Updates, OrderedUpdates
import tensor # scan_module import above initializes tensor and scalar making these imports redundant
import scalar #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
# We can't test the driver during import of theano.sandbox.cuda as # We can't test the driver during import of theano.sandbox.cuda as
# this cause circular import dependency. So we also test it manually # this cause circular import dependency. So we also test it manually
# after the import # after the import
if theano.sandbox.cuda.cuda_available: if theano.sandbox.cuda.cuda_available:
import theano.sandbox.cuda.tests.test_driver import theano.sandbox.cuda.tests.test_driver
theano.sandbox.cuda.tests.test_driver.test_nvidia_driver1() theano.sandbox.cuda.tests.test_driver.test_nvidia_driver1()
# Use config.numpy to call numpy.seterr # Use config.numpy to call numpy.seterr
import numpy import numpy
if config.numpy.seterr_all == 'None': if config.numpy.seterr_all == 'None':
_all = None _all = None
else: else:
...@@ -129,11 +115,11 @@ if config.numpy.seterr_invalid == 'None': ...@@ -129,11 +115,11 @@ if config.numpy.seterr_invalid == 'None':
else: else:
_invalid = config.numpy.seterr_invalid _invalid = config.numpy.seterr_invalid
numpy.seterr( numpy.seterr(
all=_all, all=_all,
divide=_divide, divide=_divide,
over=_over, over=_over,
under=_under, under=_under,
invalid=_invalid) invalid=_invalid)
del _all, _divide, _over, _under, _invalid del _all, _divide, _over, _under, _invalid
## import scalar_opt ## import scalar_opt
...@@ -174,10 +160,28 @@ def get_scalar_constant_value(v): ...@@ -174,10 +160,28 @@ def get_scalar_constant_value(v):
If `v` is not some view of constant data, then raise a If `v` is not some view of constant data, then raise a
tensor.basic.NotScalarConstantError. tensor.basic.NotScalarConstantError.
""" """
if hasattr(theano, 'sparse') and isinstance(v.type, # Is it necessary to test for presence of theano.sparse at runtime?
theano.sparse.SparseType): if 'sparse' in globals() and isinstance(v.type, sparse.SparseType):
if v.owner is not None and isinstance(v.owner.op, if v.owner is not None and isinstance(v.owner.op, sparse.CSM):
theano.sparse.CSM):
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)
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.")
# This cannot be done in tensor/__init__.py due to a circular dependency -- randomstreams
# depends on raw_random which depends on tensor. As a work-around, we import RandomStreams
# here and inject an instance in tensor.
from theano import tensor
from theano.tensor.randomstreams import RandomStreams
# Imitate the numpy.random symbol with a tensor.random one
tensor.random = RandomStreams(seed=0xBAD5EED, no_warn=True)
del RandomStreams
__import__('theano.tensor.shared_randomstreams')
\ No newline at end of file
import ops from theano.compile.ops import (
from ops import (
DeepCopyOp, deep_copy_op, register_deep_copy_op_c_code, DeepCopyOp, deep_copy_op, register_deep_copy_op_c_code,
ViewOp, view_op, register_view_op_c_code) ViewOp, view_op, register_view_op_c_code)
import function_module from theano.compile.function_module import *
from function_module import *
import mode from theano.compile.mode import *
from mode import *
import io from theano.compile.io import *
from io import *
import builders from theano.compile.builders import *
from builders import *
import module from theano.compile.module import *
from module import *
import debugmode # register DEBUG_MODE from theano.compile.debugmode import DebugMode
from debugmode import DebugMode
from monitormode import MonitorMode from theano.compile.monitormode import MonitorMode
from profilemode import ProfileMode from theano.compile.profilemode import ProfileMode
from theano.compile.sharedvalue import shared, shared_constructor, SharedVariable from theano.compile.sharedvalue import shared, shared_constructor, SharedVariable
from theano.compile.pfunc import pfunc, Param, rebuild_collect_shared from theano.compile.pfunc import pfunc, Param, rebuild_collect_shared
from function import function from theano.compile.function import function
...@@ -5,9 +5,9 @@ __docformat__ = "restructuredtext en" ...@@ -5,9 +5,9 @@ __docformat__ = "restructuredtext en"
import logging import logging
_logger = logging.getLogger('theano.compile.function') _logger = logging.getLogger('theano.compile.function')
from io import In from theano.compile.io import In
from function_module import orig_function from theano.compile.function_module import orig_function
from pfunc import pfunc from theano.compile.pfunc import pfunc
from numpy import any # to work in python 2.4 from numpy import any # to work in python 2.4
import warnings import warnings
from theano import gof from theano import gof
......
...@@ -15,8 +15,8 @@ import numpy ...@@ -15,8 +15,8 @@ import numpy
import theano import theano
from theano import gof from theano import gof
from theano.gof.python25 import partial from theano.gof.python25 import partial
import mode as mode_module import theano.compile.mode
from io import In, SymbolicInput, SymbolicInputKit, SymbolicOutput from theano.compile.io import In, SymbolicInput, SymbolicInputKit, SymbolicOutput
from theano.compile.ops import deep_copy_op, view_op from theano.compile.ops import deep_copy_op, view_op
import logging import logging
...@@ -945,7 +945,7 @@ class FunctionMaker(object): ...@@ -945,7 +945,7 @@ class FunctionMaker(object):
- 'ignore': do not do anything - 'ignore': do not do anything
- None: Use the value in the Theano flags on_unused_input - None: Use the value in the Theano flags on_unused_input
""" """
mode = mode_module.get_mode(mode) mode = theano.compile.mode.get_mode(mode)
# figure out which profile object to use (if any) # figure out which profile object to use (if any)
# to help with forward-porting ProfileMode, # to help with forward-porting ProfileMode,
...@@ -1025,7 +1025,7 @@ class FunctionMaker(object): ...@@ -1025,7 +1025,7 @@ class FunctionMaker(object):
# initialize the linker # initialize the linker
if not hasattr(linker, 'accept'): if not hasattr(linker, 'accept'):
raise ValueError("'linker' parameter of FunctionFactory should be a Linker with an accept method " \ raise ValueError("'linker' parameter of FunctionFactory should be a Linker with an accept method " \
"or one of %s" % mode_module.predefined_linkers.keys()) "or one of %s" % theano.compile.mode.predefined_linkers.keys())
#the 'no_borrow' outputs are the ones for which that we can't return the internal storage pointer. #the 'no_borrow' outputs are the ones for which that we can't return the internal storage pointer.
assert len(fgraph.outputs) == len(outputs + additional_outputs) assert len(fgraph.outputs) == len(outputs + additional_outputs)
...@@ -1274,7 +1274,7 @@ def orig_function(inputs, outputs, mode=None, accept_inplace=False, ...@@ -1274,7 +1274,7 @@ def orig_function(inputs, outputs, mode=None, accept_inplace=False,
# instance if necessary: # instance if necessary:
t1 = time.time() t1 = time.time()
mode = mode_module.get_mode(mode) mode = theano.compile.mode.get_mode(mode)
inputs = map(convert_function_input, inputs) inputs = map(convert_function_input, inputs)
if outputs is not None: if outputs is not None:
......
...@@ -15,8 +15,8 @@ import warnings ...@@ -15,8 +15,8 @@ import warnings
from itertools import chain from itertools import chain
import function_module as F import theano.compile.function_module
import mode as get_mode import theano.compile.mode
#This module is imported by other parts of theano, and worse still, other #This module is imported by other parts of theano, and worse still, other
...@@ -106,7 +106,7 @@ class Component(object): ...@@ -106,7 +106,7 @@ class Component(object):
be called. be called.
""" """
if mode is None: if mode is None:
mode = get_mode.get_default_mode() mode = theano.compile.mode.get_default_mode()
memo = {} memo = {}
self.allocate(memo) self.allocate(memo)
rval = self.build(mode, memo) rval = self.build(mode, memo)
...@@ -120,7 +120,7 @@ class Component(object): ...@@ -120,7 +120,7 @@ class Component(object):
arguments and the keyword arguments. If 'mode' is in the arguments and the keyword arguments. If 'mode' is in the
keyword arguments it will be passed to build(). keyword arguments it will be passed to build().
""" """
mode = kwargs.pop('mode', get_mode.get_default_mode()) mode = kwargs.pop('mode', theano.compile.mode.get_default_mode())
rval = self.make_no_init(mode) rval = self.make_no_init(mode)
if hasattr(rval, 'initialize'): if hasattr(rval, 'initialize'):
rval.initialize(*args, **kwargs) rval.initialize(*args, **kwargs)
...@@ -503,7 +503,7 @@ class Method(Component): ...@@ -503,7 +503,7 @@ class Method(Component):
effective_mode = self.mode effective_mode = self.mode
# We ignore unused inputs, since all the inputs are passed # We ignore unused inputs, since all the inputs are passed
rval = F.orig_function(inputs, outputs, effective_mode, rval = theano.compile.function_module.orig_function(inputs, outputs, effective_mode,
on_unused_input='ignore') on_unused_input='ignore')
memo[self] = rval memo[self] = rval
return rval return rval
...@@ -1192,7 +1192,7 @@ class Module(ComponentDict): ...@@ -1192,7 +1192,7 @@ class Module(ComponentDict):
""" """
self.make_module_instance(args,kwargs) self.make_module_instance(args,kwargs)
mode = kwargs.pop('mode', get_mode.get_default_mode()) mode = kwargs.pop('mode', theano.compile.mode.get_default_mode())
rval = self.make_no_init(mode) rval = self.make_no_init(mode)
if hasattr(rval, 'initialize'): if hasattr(rval, 'initialize'):
rval.initialize(*args, **kwargs) rval.initialize(*args, **kwargs)
......
...@@ -3,12 +3,11 @@ ...@@ -3,12 +3,11 @@
__docformat__ = 'restructuredtext en' __docformat__ = 'restructuredtext en'
from profiling import ProfileStats
from theano import config from theano import config
from theano.compile import orig_function, In, Out from theano.compile import orig_function, In, Out
from theano.compile import UnusedInputError from theano.compile import UnusedInputError
from theano.compile.sharedvalue import SharedVariable, shared from theano.compile.sharedvalue import SharedVariable, shared
from theano.compile.profiling import ProfileStats
from theano.gof import Variable, Constant from theano.gof import Variable, Constant
from theano.gof.python25 import any from theano.gof.python25 import any
...@@ -293,6 +292,7 @@ class Param(object): ...@@ -293,6 +292,7 @@ class Param(object):
`mutable` flag. `mutable` flag.
False: do not permit any output to be aliased to the input False: do not permit any output to be aliased to the input
False: do not permit any output to be aliased to the input
:param strict: False -> function arguments may be copied or cast to match the :param strict: False -> function arguments may be copied or cast to match the
type required by the parameter `variable`. type required by the parameter `variable`.
True -> function arguments must exactly match the type True -> function arguments must exactly match the type
......
...@@ -4,7 +4,6 @@ __docformat__ = 'restructuredtext en' ...@@ -4,7 +4,6 @@ __docformat__ = 'restructuredtext en'
# Standard imports # Standard imports
import copy import copy
import logging import logging
import sys
# Third-party imports # Third-party imports
import numpy import numpy
......
...@@ -35,29 +35,27 @@ For more details and discussion, see the theano-dev ...@@ -35,29 +35,27 @@ For more details and discussion, see the theano-dev
e-mail thread "What is gof?" e-mail thread "What is gof?"
""" """
import sys from theano.gof.cc import \
from cc import \
CLinker, OpWiseCLinker, DualLinker CLinker, OpWiseCLinker, DualLinker
import compiledir # adds config vars import theano.gof.compiledir # adds config vars
from fg import \ from theano.gof.fg import \
InconsistencyError, MissingInputError, FunctionGraph InconsistencyError, MissingInputError, FunctionGraph
from destroyhandler import \ from theano.gof.destroyhandler import \
DestroyHandler DestroyHandler
from graph import \ from theano.gof.graph import \
Apply, Variable, Constant, view_roots Apply, Variable, Constant, view_roots
from link import \ from theano.gof.link import \
Container, Linker, LocalLinker, PerformLinker, WrapLinker, WrapLinkerMany Container, Linker, LocalLinker, PerformLinker, WrapLinker, WrapLinkerMany
from op import \ from theano.gof.op import \
Op, OpenMPOp, PureOp, ops_with_inner_function Op, OpenMPOp, PureOp, ops_with_inner_function
from opt import (Optimizer, optimizer, SeqOptimizer, from theano.gof.opt import (Optimizer, optimizer, SeqOptimizer,
MergeOptimizer, MergeOptMerge, MergeOptimizer, MergeOptMerge,
LocalOptimizer, local_optimizer, LocalOptGroup, LocalOptimizer, local_optimizer, LocalOptGroup,
OpSub, OpRemove, PatternSub, OpSub, OpRemove, PatternSub,
...@@ -65,18 +63,18 @@ from opt import (Optimizer, optimizer, SeqOptimizer, ...@@ -65,18 +63,18 @@ from opt import (Optimizer, optimizer, SeqOptimizer,
InplaceOptimizer, PureThenInplaceOptimizer, InplaceOptimizer, PureThenInplaceOptimizer,
OpKeyOptimizer) OpKeyOptimizer)
from optdb import \ from theano.gof.optdb import \
DB, Query, \ DB, Query, \
EquilibriumDB, SequenceDB, ProxyDB EquilibriumDB, SequenceDB, ProxyDB
from toolbox import \ from theano.gof.toolbox import \
Feature, \ Feature, \
Bookkeeper, History, Validator, ReplaceValidate, NodeFinder,\ Bookkeeper, History, Validator, ReplaceValidate, NodeFinder,\
PrintListener, ReplacementDidntRemovedError PrintListener, ReplacementDidntRemovedError
from type import \ from theano.gof.type import \
Type, Generic, generic Type, Generic, generic
from utils import \ from theano.gof.utils import \
object2, MethodNotDefined object2, MethodNotDefined
...@@ -44,13 +44,13 @@ AddConfigVar('gcc.cxxflags', ...@@ -44,13 +44,13 @@ AddConfigVar('gcc.cxxflags',
StrParam("")) StrParam(""))
# gof imports # gof imports
import graph from theano.gof import graph
import link from theano.gof import link
import utils from theano.gof import utils
from compilelock import get_lock, release_lock from theano.gof.compilelock import get_lock, release_lock
import cmodule from theano.gof import cmodule
import logging import logging
......
...@@ -25,8 +25,8 @@ from theano.gof.cc import hash_from_code ...@@ -25,8 +25,8 @@ from theano.gof.cc import hash_from_code
from theano.misc.windows import call_subprocess_Popen from theano.misc.windows import call_subprocess_Popen
# we will abuse the lockfile mechanism when reading and writing the registry # we will abuse the lockfile mechanism when reading and writing the registry
import compilelock from theano.gof import compilelock
from compiledir import gcc_version_str from theano.gof.compiledir import gcc_version_str
from theano.configparser import AddConfigVar, BoolParam from theano.configparser import AddConfigVar, BoolParam
......
import os import os
import sys import sys
from compilelock import get_lock, release_lock from theano.gof.compilelock import get_lock, release_lock
from theano import config from theano import config
# TODO These two lines may be removed in the future, when we are 100% sure # TODO These two lines may be removed in the future, when we are 100% sure
......
...@@ -5,14 +5,15 @@ Contains the FunctionGraph class and exception ...@@ -5,14 +5,15 @@ Contains the FunctionGraph class and exception
types that it can raise types that it can raise
""" """
import sys import sys
import graph from theano.gof import graph
import utils from theano.gof import utils
import toolbox from theano.gof import toolbox
from python25 import all from theano.gof.python25 import all
from theano import config from theano import config
import warnings import warnings
NullType = None NullType = None
from python25 import OrderedDict
from theano.gof.python25 import OrderedDict
from theano.misc.ordered_set import OrderedSet from theano.misc.ordered_set import OrderedSet
class InconsistencyError(Exception): class InconsistencyError(Exception):
......
"""WRITEME""" """WRITEME"""
import utils from theano.gof import utils
import graph from theano.gof import graph
from type import Type from theano.gof.type import Type
import sys, traceback import sys, traceback
from copy import copy from copy import copy
from theano.gof.python25 import all
__excepthook = sys.excepthook __excepthook = sys.excepthook
......
...@@ -11,7 +11,6 @@ __contact__ = "theano-dev <theano-dev@googlegroups.com>" ...@@ -11,7 +11,6 @@ __contact__ = "theano-dev <theano-dev@googlegroups.com>"
__docformat__ = "restructuredtext en" __docformat__ = "restructuredtext en"
import copy
import logging import logging
import os import os
import subprocess import subprocess
...@@ -22,10 +21,10 @@ import theano ...@@ -22,10 +21,10 @@ import theano
from theano import config from theano import config
from theano.misc.windows import call_subprocess_Popen from theano.misc.windows import call_subprocess_Popen
import cc import theano.gof.cc
import graph from theano.gof import graph
import utils from theano.gof import utils
from fg import FunctionGraph from theano.gof.fg import FunctionGraph
class CLinkerObject(object): class CLinkerObject(object):
...@@ -572,7 +571,7 @@ class Op(utils.object2, PureOp, CLinkerOp): ...@@ -572,7 +571,7 @@ class Op(utils.object2, PureOp, CLinkerOp):
e_no_recycling = [new_o e_no_recycling = [new_o
for (new_o, old_o) in zip(e.outputs, node.outputs) for (new_o, old_o) in zip(e.outputs, node.outputs)
if old_o in no_recycling] if old_o in no_recycling]
cl = cc.CLinker().accept(e, cl = theano.gof.cc.CLinker().accept(e,
no_recycling=e_no_recycling) no_recycling=e_no_recycling)
logger.debug('Trying CLinker.make_thunk') logger.debug('Trying CLinker.make_thunk')
......
...@@ -10,16 +10,15 @@ import time ...@@ -10,16 +10,15 @@ import time
import numpy import numpy
import graph from theano.gof import graph
from fg import InconsistencyError from theano.gof.fg import InconsistencyError
import op from theano.gof import op
import utils from theano.gof import utils
import unify from theano.gof import unify
import toolbox from theano.gof import toolbox
import theano import theano
from theano import config from theano import config
from theano.gof.python25 import any, all, deque from theano.gof.python25 import any, all, deque
from theano.configparser import AddConfigVar, BoolParam
#if sys.version_info[:2] >= (2,5): #if sys.version_info[:2] >= (2,5):
# from collections import defaultdict # from collections import defaultdict
......
import StringIO import StringIO
import sys import sys
from python25 import DefaultOrderedDict from theano.gof.python25 import DefaultOrderedDict
import numpy import numpy
import opt from theano.gof import opt
from theano.configparser import AddConfigVar, FloatParam from theano.configparser import AddConfigVar, FloatParam
from theano import config from theano import config
AddConfigVar('optdb.position_cutoff', AddConfigVar('optdb.position_cutoff',
......
from graph import list_of_nodes from theano.gof.graph import list_of_nodes
from theano.gof.python25 import any, defaultdict from theano.gof.python25 import any, defaultdict
......
...@@ -4,7 +4,7 @@ import time ...@@ -4,7 +4,7 @@ import time
from theano.gof.python25 import partial from theano.gof.python25 import partial
from theano.gof.python25 import OrderedDict from theano.gof.python25 import OrderedDict
import graph from theano.gof import graph
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
__docformat__ = "restructuredtext en" __docformat__ = "restructuredtext en"
import utils from theano.gof import utils
from utils import MethodNotDefined, object2 from theano.gof.utils import MethodNotDefined, object2
import graph from theano.gof import graph
######## ########
# Type # # Type #
......
...@@ -9,8 +9,8 @@ if there exists an assignment to all unification variables such that ...@@ -9,8 +9,8 @@ if there exists an assignment to all unification variables such that
""" """
from copy import copy from copy import copy
from python25 import partial from theano.gof.python25 import partial
from utils import * from theano.gof.utils import *
################################ ################################
......
...@@ -11,11 +11,10 @@ import warnings ...@@ -11,11 +11,10 @@ import warnings
from theano.gof.python25 import all from theano.gof.python25 import all
import theano
config = theano.config
from theano.configparser import config, AddConfigVar, BoolParam, ConfigParam from theano.configparser import config, AddConfigVar, BoolParam, ConfigParam
import theano.gof.cmodule
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
AddConfigVar('profile', AddConfigVar('profile',
......
...@@ -27,12 +27,12 @@ from theano.gof import PureOp, Apply ...@@ -27,12 +27,12 @@ from theano.gof import PureOp, Apply
import theano.tensor import theano.tensor
from theano.tensor import TensorType from theano.tensor import TensorType
import gof from theano import gof
from compile import optdb from theano.compile import optdb
from tensor import opt from theano.tensor import opt
from scan_module.scan_utils import find_up from theano.scan_module.scan_utils import find_up
from scan_module.scan_utils import clone from theano.scan_module.scan_utils import clone
_logger = logging.getLogger('theano.ifelse') _logger = logging.getLogger('theano.ifelse')
......
...@@ -24,9 +24,9 @@ except ImportError: ...@@ -24,9 +24,9 @@ except ImportError:
pydot_imported = False pydot_imported = False
import theano import theano
import gof from theano import gof
from theano import config from theano import config
from gof import Op, Apply from theano.gof import Op, Apply
from theano.gof.python25 import any from theano.gof.python25 import any
from theano.compile import Function, debugmode from theano.compile import Function, debugmode
from theano.compile.profilemode import ProfileMode from theano.compile.profilemode import ProfileMode
......
...@@ -6,7 +6,7 @@ __license__ = "3-clause BSD License" ...@@ -6,7 +6,7 @@ __license__ = "3-clause BSD License"
__contact__ = "theano-dev <theano-dev@googlegroups.com>" __contact__ = "theano-dev <theano-dev@googlegroups.com>"
__docformat__ = "restructuredtext en" __docformat__ = "restructuredtext en"
import gof from theano import gof
class Raise(gof.Op): class Raise(gof.Op):
"""Op whose perform() raises an exception. """Op whose perform() raises an exception.
......
...@@ -38,7 +38,7 @@ __authors__ = ("Razvan Pascanu " ...@@ -38,7 +38,7 @@ __authors__ = ("Razvan Pascanu "
__copyright__ = "(c) 2010, Universite de Montreal" __copyright__ = "(c) 2010, Universite de Montreal"
__contact__ = "Razvan Pascanu <r.pascanu@gmail>" __contact__ = "Razvan Pascanu <r.pascanu@gmail>"
import scan_opt from theano.scan_module import scan_opt
from scan import scan from theano.scan_module.scan import scan
from scan_views import map, reduce, foldl, foldr from theano.scan_module.scan_views import map, reduce, foldl, foldr
from scan_utils import clone, until from theano.scan_module.scan_utils import clone, until
...@@ -57,9 +57,9 @@ from theano.compile import ops ...@@ -57,9 +57,9 @@ from theano.compile import ops
from theano.gof.python25 import OrderedDict from theano.gof.python25 import OrderedDict
import scan_op from theano.scan_module import scan_op
import scan_utils from theano.scan_module import scan_utils
from scan_utils import safe_new, traverse from theano.scan_module.scan_utils import safe_new, traverse
# Logging function for sending warning or info # Logging function for sending warning or info
_logger = logging.getLogger('theano.scan_module.scan') _logger = logging.getLogger('theano.scan_module.scan')
......
...@@ -33,8 +33,8 @@ from theano.gradient import grad_undefined ...@@ -33,8 +33,8 @@ from theano.gradient import grad_undefined
from theano.gradient import DisconnectedType from theano.gradient import DisconnectedType
from theano.compile.profiling import ScanProfileStats from theano.compile.profiling import ScanProfileStats
import scan_utils from theano.scan_module import scan_utils
from scan_utils import safe_new, forced_replace from theano.scan_module.scan_utils import safe_new, forced_replace
# Logging function for sending warning or info # Logging function for sending warning or info
_logger = logging.getLogger('theano.scan_module.scan_op') _logger = logging.getLogger('theano.scan_module.scan_op')
......
...@@ -26,9 +26,9 @@ from theano.gof import toolbox, DestroyHandler, InconsistencyError ...@@ -26,9 +26,9 @@ from theano.gof import toolbox, DestroyHandler, InconsistencyError
from theano.compile import optdb from theano.compile import optdb
from theano.compile.function_module import deep_copy_op from theano.compile.function_module import deep_copy_op
import scan_op from theano.scan_module import scan_op
import scan_utils from theano.scan_module import scan_utils
from scan_utils import equal_computations, find_up, scan_args from theano.scan_module.scan_utils import equal_computations, find_up, scan_args
from theano.gof.opt import pre_constant_merge, pre_greedy_local_optimizer from theano.gof.opt import pre_constant_merge, pre_greedy_local_optimizer
# Logging function for sending warning or info # Logging function for sending warning or info
......
...@@ -15,7 +15,7 @@ __contact__ = "Razvan Pascanu <r.pascanu@gmail>" ...@@ -15,7 +15,7 @@ __contact__ = "Razvan Pascanu <r.pascanu@gmail>"
import logging import logging
import scan from theano.scan_module import scan
# Logging function for sending warning or info # Logging function for sending warning or info
_logger = logging.getLogger('theano.scan_module.scan_views') _logger = logging.getLogger('theano.scan_module.scan_views')
...@@ -58,7 +58,7 @@ def map(fn, ...@@ -58,7 +58,7 @@ def map(fn,
:param name: See ``scan``. :param name: See ``scan``.
""" """
return scan.scan(fn=fn, return scan(fn=fn,
sequences=sequences, sequences=sequences,
outputs_info=[], outputs_info=[],
non_sequences=non_sequences, non_sequences=non_sequences,
...@@ -101,7 +101,7 @@ def reduce(fn, ...@@ -101,7 +101,7 @@ def reduce(fn,
:param name: See ``scan``. :param name: See ``scan``.
""" """
rval = scan.scan(fn=fn, rval = scan(fn=fn,
sequences=sequences, sequences=sequences,
outputs_info=outputs_info, outputs_info=outputs_info,
non_sequences=non_sequences, non_sequences=non_sequences,
......
...@@ -4,13 +4,12 @@ import theano ...@@ -4,13 +4,12 @@ import theano
import numpy import numpy
from theano import gof, scalar, tensor from theano import gof, scalar, tensor
from theano.tensor import blas from theano.tensor import blas
from theano.sparse import (CSC, CSR, csm_properties, Remove0, from theano.sparse import (CSC, CSR, csm_properties,
register_specialize, register_specialize,
csm_grad, usmm) csm_grad, usmm)
from theano.sparse import basic as sparse from theano.sparse import basic as sparse
from basic import _is_sparse_variable _is_sparse_variable = sparse._is_sparse_variable
# This is tested in tests/test_opt.py:test_local_csm_properties_csm # This is tested in tests/test_opt.py:test_local_csm_properties_csm
@gof.local_optimizer([csm_properties]) @gof.local_optimizer([csm_properties])
......
import copy import copy
import scipy.sparse import scipy.sparse
from theano.compile import shared_constructor, SharedVariable from theano.compile import shared_constructor, SharedVariable
from theano import config from theano.sparse.basic import SparseType, _sparse_py_operators
from basic import SparseType, _sparse_py_operators
class SparseTensorSharedVariable(_sparse_py_operators, SharedVariable): class SparseTensorSharedVariable(_sparse_py_operators, SharedVariable):
pass pass
@shared_constructor @shared_constructor
def sparse_constructor(value, name=None, strict=False, allow_downcast=None, def sparse_constructor(value, name=None, strict=False, allow_downcast=None,
borrow=False, format = None): borrow=False, format=None):
"""SharedVariable Constructor for SparseType """SharedVariable Constructor for SparseType
writeme writeme
""" """
if not isinstance(value, scipy.sparse.spmatrix): if not isinstance(value, scipy.sparse.spmatrix):
raise TypeError("Expected a sparse matrix in the sparse shared variable constructor. Received: ",value.__class__) raise TypeError("Expected a sparse matrix in the sparse shared variable constructor. Received: ",
value.__class__)
if format is None: if format is None:
format = value.format format = value.format
type = SparseType(format =format, dtype = value.dtype) type = SparseType(format=format, dtype=value.dtype)
if not borrow: if not borrow:
value = copy.deepcopy(value) value = copy.deepcopy(value)
return SparseTensorSharedVariable(type=type, value=value, name=name, return SparseTensorSharedVariable(type=type, value=value, name=name,
strict=strict, allow_downcast=allow_downcast) strict=strict, allow_downcast=allow_downcast)
...@@ -3,34 +3,35 @@ __docformat__ = "restructuredtext en" ...@@ -3,34 +3,35 @@ __docformat__ = "restructuredtext en"
import warnings import warnings
from basic import * from theano.tensor.basic import *
import opt from theano.tensor import opt
import opt_uncanonicalize from theano.tensor import opt_uncanonicalize
import blas from theano.tensor import blas
import blas_scipy from theano.tensor import blas_scipy
import blas_c from theano.tensor import blas_c
import xlogx from theano.tensor import xlogx
import raw_random # These imports cannot be performed here because the modules depend on tensor. This is done at the
import randomstreams # end of theano.__init__.py instead.
import shared_randomstreams #from theano.tensor import raw_random
from randomstreams import \ #from theano.tensor import randomstreams
RandomStreams #from theano.tensor import shared_randomstreams
#from theano.tensor.randomstreams import \
# RandomStreams
random = RandomStreams(seed=0xBAD5EED, no_warn = True) #random = RandomStreams(seed=0xBAD5EED, no_warn = True)
"""Imitate the numpy.random symbol with a tensor.random one""" #"""Imitate the numpy.random symbol with a tensor.random one"""
from elemwise import \ from theano.tensor.elemwise import DimShuffle, Elemwise, CAReduce
DimShuffle, Elemwise, CAReduce
import sharedvar # adds shared-variable constructors from theano.tensor import sharedvar # adds shared-variable constructors
# We import as `_shared` instead of `shared` to avoid confusion between # We import as `_shared` instead of `shared` to avoid confusion between
# `theano.shared` and `tensor._shared`. # `theano.shared` and `tensor._shared`.
from sharedvar import tensor_constructor as _shared from theano.tensor.sharedvar import tensor_constructor as _shared
from io import * from theano.tensor.io import *
def shared(*args, **kw): def shared(*args, **kw):
""" """
...@@ -49,11 +50,11 @@ def shared(*args, **kw): ...@@ -49,11 +50,11 @@ def shared(*args, **kw):
return _shared(*args, **kw) return _shared(*args, **kw)
import nnet # used for softmax, sigmoid, etc. from theano.tensor import nnet # used for softmax, sigmoid, etc.
from theano.gradient import Rop, Lop, grad, numeric_grad, verify_grad, \ from theano.gradient import Rop, Lop, grad, numeric_grad, verify_grad, \
jacobian, hessian jacobian, hessian
from theano.tensor.sort import sort, argsort from theano.tensor.sort import sort, argsort
from extra_ops import (DiffOp, bincount, squeeze, from theano.tensor.extra_ops import (DiffOp, bincount, squeeze,
repeat, bartlett, fill_diagonal) repeat, bartlett, fill_diagonal)
...@@ -14,7 +14,7 @@ from theano.configparser import config ...@@ -14,7 +14,7 @@ from theano.configparser import config
from theano import gof from theano import gof
from theano.gof import Apply, Constant, Op, Type, Variable from theano.gof import Apply, Constant, Op, Type, Variable
import elemwise from theano.tensor import elemwise
from theano import scalar as scal from theano import scalar as scal
from theano.gof.python25 import partial, any, all, maxsize from theano.gof.python25 import partial, any, all, maxsize
from theano import compile, printing from theano import compile, printing
...@@ -29,7 +29,7 @@ from theano.gradient import grad_not_implemented ...@@ -29,7 +29,7 @@ from theano.gradient import grad_not_implemented
from theano.gradient import DisconnectedType from theano.gradient import DisconnectedType
### set up the external interface ### set up the external interface
from elemwise import Elemwise, DimShuffle, CAReduce, Sum from theano.tensor.elemwise import Elemwise, DimShuffle, CAReduce, Sum
import logging import logging
_logger = logging.getLogger("theano.tensor.basic") _logger = logging.getLogger("theano.tensor.basic")
......
from theano import config from theano import config
from blas import ldflags, blas_header_text from theano.tensor.blas import ldflags, blas_header_text
from blas import blas_optdb, optdb, local_optimizer, EquilibriumOptimizer from theano.tensor.blas import blas_optdb, optdb, local_optimizer, EquilibriumOptimizer
from blas import Ger, ger, ger_destructive from theano.tensor.blas import Ger, ger, ger_destructive
from blas import Gemv, gemv_inplace, gemv_no_inplace from theano.tensor.blas import Gemv, gemv_inplace, gemv_no_inplace
class BaseBLAS(object): class BaseBLAS(object):
......
...@@ -5,7 +5,6 @@ from itertools import izip ...@@ -5,7 +5,6 @@ from itertools import izip
import numpy import numpy
import elemwise_cgen as cgen
import theano import theano
from theano import gof from theano import gof
from theano.gof import Apply, Op from theano.gof import Apply, Op
...@@ -16,6 +15,7 @@ from theano.gof.python25 import all, any ...@@ -16,6 +15,7 @@ from theano.gof.python25 import all, any
from theano.tensor.utils import hash_from_dict from theano.tensor.utils import hash_from_dict
from theano.gradient import DisconnectedType from theano.gradient import DisconnectedType
from theano.gof.null_type import NullType from theano.gof.null_type import NullType
from theano.tensor import elemwise_cgen as cgen
config = theano.config config = theano.config
......
...@@ -2,9 +2,9 @@ import numpy as np ...@@ -2,9 +2,9 @@ import numpy as np
import numpy import numpy
import theano import theano
import basic from theano.tensor import basic
from theano import gof, scalar from theano import gof, scalar
import basic as tensor tensor = basic
from theano.gradient import DisconnectedType from theano.gradient import DisconnectedType
......
...@@ -2,7 +2,7 @@ import numpy ...@@ -2,7 +2,7 @@ import numpy
from theano import gof from theano import gof
from theano.gof import Constant, Generic, Op from theano.gof import Constant, Generic, Op
from theano.gof.sched import key_to_cmp from theano.gof.sched import key_to_cmp
from basic import tensor from theano.tensor import tensor
import theano import theano
########################## ##########################
# Disk Access # Disk Access
......
...@@ -23,9 +23,9 @@ from theano.gof import Variable, Constant ...@@ -23,9 +23,9 @@ from theano.gof import Variable, Constant
from theano.gof.python25 import maxsize from theano.gof.python25 import maxsize
from theano.gof.utils import MethodNotDefined from theano.gof.utils import MethodNotDefined
from theano.configparser import config from theano.configparser import config
from elemwise import Elemwise, DimShuffle from theano.tensor.elemwise import Elemwise, DimShuffle
from theano import scalar from theano import scalar
import basic as T from theano.tensor import basic as T
from theano import compile # to register the optimizer built by this file from theano import compile # to register the optimizer built by this file
from theano.gof.python25 import any, all from theano.gof.python25 import any, all
...@@ -33,7 +33,7 @@ from theano.gof.opt import (Optimizer, pre_constant_merge, ...@@ -33,7 +33,7 @@ from theano.gof.opt import (Optimizer, pre_constant_merge,
pre_greedy_local_optimizer) pre_greedy_local_optimizer)
from theano.gof.opt import merge_optimizer from theano.gof.opt import merge_optimizer
from theano.gof import toolbox, DestroyHandler from theano.gof import toolbox, DestroyHandler
from basic import get_scalar_constant_value, ShapeError, NotScalarConstantError from theano.tensor.basic import get_scalar_constant_value, ShapeError, NotScalarConstantError
theano.configparser.AddConfigVar('on_shape_error', theano.configparser.AddConfigVar('on_shape_error',
......
...@@ -29,13 +29,13 @@ import logging ...@@ -29,13 +29,13 @@ import logging
_logger = logging.getLogger('theano.tensor.opt') _logger = logging.getLogger('theano.tensor.opt')
from theano import gof from theano import gof
from elemwise import CAReduce from theano.tensor.elemwise import CAReduce
import basic as T from theano.tensor import basic as T
from theano.gof.opt import Optimizer from theano.gof.opt import Optimizer
from theano.gof import InconsistencyError, toolbox from theano.gof import InconsistencyError, toolbox
from basic import get_scalar_constant_value, NotScalarConstantError from theano.tensor.basic import get_scalar_constant_value, NotScalarConstantError
from theano.tensor.opt import register_uncanonicalize from theano.tensor.opt import register_uncanonicalize
from theano import scalar as scal from theano import scalar as scal
......
...@@ -7,8 +7,8 @@ import numpy ...@@ -7,8 +7,8 @@ import numpy
#local imports #local imports
import theano import theano
import basic as tensor from theano import tensor
import opt from theano.tensor import opt
from theano import gof from theano import gof
from theano.compile import optdb from theano.compile import optdb
......
...@@ -8,7 +8,7 @@ import numpy ...@@ -8,7 +8,7 @@ import numpy
from theano.compile.sharedvalue import (SharedVariable, shared_constructor, from theano.compile.sharedvalue import (SharedVariable, shared_constructor,
shared) shared)
import raw_random from theano.tensor import raw_random
class RandomStateSharedVariable(SharedVariable): class RandomStateSharedVariable(SharedVariable):
......
...@@ -3,7 +3,7 @@ import traceback ...@@ -3,7 +3,7 @@ import traceback
import numpy import numpy
import theano.tensor.basic import theano.tensor.basic
from basic import TensorType, _tensor_py_operators from theano.tensor.basic import TensorType, _tensor_py_operators
from theano.compile import shared_constructor, SharedVariable from theano.compile import shared_constructor, SharedVariable
......
...@@ -3,7 +3,7 @@ import numpy as np ...@@ -3,7 +3,7 @@ import numpy as np
import theano import theano
from theano.tensor import tensor from theano.tensor import tensor
from basic import mul from theano.tensor.basic import mul
class SortOp(theano.Op): class SortOp(theano.Op):
......
...@@ -66,7 +66,7 @@ class QuadraticDenoisingAA(module.Module): ...@@ -66,7 +66,7 @@ class QuadraticDenoisingAA(module.Module):
""" """
super(QuadraticDenoisingAA, self).__init__() super(QuadraticDenoisingAA, self).__init__()
self.random = T.RandomStreams() self.random = T.randomstreams.RandomStreams()
# MODEL CONFIGURATION # MODEL CONFIGURATION
# self.regularize = regularize # self.regularize = regularize
......
import numpy import numpy
from elemwise import Elemwise from theano.tensor.elemwise import Elemwise
from theano import scalar from theano import scalar
class XlogX(scalar.UnaryScalarOp): class XlogX(scalar.UnaryScalarOp):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论