提交 c65bf858 authored 作者: Brandon T. Willard's avatar Brandon T. Willard

Make imports from theano.gof.utils explicit

上级 19515765
...@@ -19,8 +19,13 @@ import theano.gof.cc ...@@ -19,8 +19,13 @@ import theano.gof.cc
from theano import config from theano import config
from theano.gof import graph from theano.gof import graph
from theano.gof import utils from theano.gof.utils import (
from theano.gof.utils import TestValueError object2,
TestValueError,
get_variable_trace_string,
MethodNotDefined,
add_tag_trace,
)
from theano.gof.cmodule import GCC_compiler from theano.gof.cmodule import GCC_compiler
from theano.gof.fg import FunctionGraph from theano.gof.fg import FunctionGraph
...@@ -65,7 +70,7 @@ def compute_test_value(node): ...@@ -65,7 +70,7 @@ def compute_test_value(node):
) )
return return
elif config.compute_test_value == "raise": elif config.compute_test_value == "raise":
detailed_err_msg = utils.get_variable_trace_string(ins) detailed_err_msg = get_variable_trace_string(ins)
raise ValueError( raise ValueError(
"Cannot compute test value: input %i (%s) of Op %s missing default value. %s" "Cannot compute test value: input %i (%s) of Op %s missing default value. %s"
...@@ -144,7 +149,7 @@ class CLinkerObject(object): ...@@ -144,7 +149,7 @@ class CLinkerObject(object):
Subclass does not implement this method. Subclass does not implement this method.
""" """
raise utils.MethodNotDefined("c_headers", type(self), self.__class__.__name__) raise MethodNotDefined("c_headers", type(self), self.__class__.__name__)
def c_header_dirs(self): def c_header_dirs(self):
""" """
...@@ -167,9 +172,7 @@ class CLinkerObject(object): ...@@ -167,9 +172,7 @@ class CLinkerObject(object):
Subclass does not implement this method. Subclass does not implement this method.
""" """
raise utils.MethodNotDefined( raise MethodNotDefined("c_header_dirs", type(self), self.__class__.__name__)
"c_header_dirs", type(self), self.__class__.__name__
)
def c_libraries(self): def c_libraries(self):
""" """
...@@ -192,7 +195,7 @@ class CLinkerObject(object): ...@@ -192,7 +195,7 @@ class CLinkerObject(object):
Subclass does not implement this method. Subclass does not implement this method.
""" """
raise utils.MethodNotDefined("c_libraries", type(self), self.__class__.__name__) raise MethodNotDefined("c_libraries", type(self), self.__class__.__name__)
def c_lib_dirs(self): def c_lib_dirs(self):
""" """
...@@ -215,7 +218,7 @@ class CLinkerObject(object): ...@@ -215,7 +218,7 @@ class CLinkerObject(object):
Subclass does not implement this method. Subclass does not implement this method.
""" """
raise utils.MethodNotDefined("c_lib_dirs", type(self), self.__class__.__name__) raise MethodNotDefined("c_lib_dirs", type(self), self.__class__.__name__)
def c_support_code(self): def c_support_code(self):
""" """
...@@ -231,9 +234,7 @@ class CLinkerObject(object): ...@@ -231,9 +234,7 @@ class CLinkerObject(object):
Subclass does not implement this method. Subclass does not implement this method.
""" """
raise utils.MethodNotDefined( raise MethodNotDefined("c_support_code", type(self), self.__class__.__name__)
"c_support_code", type(self), self.__class__.__name__
)
def c_code_cache_version(self): def c_code_cache_version(self):
""" """
...@@ -271,9 +272,7 @@ class CLinkerObject(object): ...@@ -271,9 +272,7 @@ class CLinkerObject(object):
Subclass does not implement this method. Subclass does not implement this method.
""" """
raise utils.MethodNotDefined( raise MethodNotDefined("c_compile_args", type(self), self.__class__.__name__)
"c_compile_args", type(self), self.__class__.__name__
)
def c_no_compile_args(self): def c_no_compile_args(self):
""" """
...@@ -294,9 +293,7 @@ class CLinkerObject(object): ...@@ -294,9 +293,7 @@ class CLinkerObject(object):
The subclass does not override this method. The subclass does not override this method.
""" """
raise utils.MethodNotDefined( raise MethodNotDefined("c_no_compile_args", type(self), self.__class__.__name__)
"c_no_compile_args", type(self), self.__class__.__name__
)
def c_init_code(self): def c_init_code(self):
""" """
...@@ -309,7 +306,7 @@ class CLinkerObject(object): ...@@ -309,7 +306,7 @@ class CLinkerObject(object):
The subclass does not override this method. The subclass does not override this method.
""" """
raise utils.MethodNotDefined("c_init_code", type(self), self.__class__.__name__) raise MethodNotDefined("c_init_code", type(self), self.__class__.__name__)
class CLinkerOp(CLinkerObject): class CLinkerOp(CLinkerObject):
...@@ -363,7 +360,7 @@ class CLinkerOp(CLinkerObject): ...@@ -363,7 +360,7 @@ class CLinkerOp(CLinkerObject):
The subclass does not override this method. The subclass does not override this method.
""" """
raise utils.MethodNotDefined("%s.c_code" % self.__class__.__name__) raise MethodNotDefined("%s.c_code" % self.__class__.__name__)
def c_code_cache_version_apply(self, node): def c_code_cache_version_apply(self, node):
""" """
...@@ -424,7 +421,7 @@ class CLinkerOp(CLinkerObject): ...@@ -424,7 +421,7 @@ class CLinkerOp(CLinkerObject):
The subclass does not override this method. The subclass does not override this method.
""" """
raise utils.MethodNotDefined("%s.c_code_cleanup" % self.__class__.__name__) raise MethodNotDefined("%s.c_code_cleanup" % self.__class__.__name__)
def c_support_code_apply(self, node, name): def c_support_code_apply(self, node, name):
""" """
...@@ -452,7 +449,7 @@ class CLinkerOp(CLinkerObject): ...@@ -452,7 +449,7 @@ class CLinkerOp(CLinkerObject):
Subclass does not implement this method. Subclass does not implement this method.
""" """
raise utils.MethodNotDefined( raise MethodNotDefined(
"c_support_code_apply", type(self), self.__class__.__name__ "c_support_code_apply", type(self), self.__class__.__name__
) )
...@@ -481,9 +478,7 @@ class CLinkerOp(CLinkerObject): ...@@ -481,9 +478,7 @@ class CLinkerOp(CLinkerObject):
The subclass does not override this method. The subclass does not override this method.
""" """
raise utils.MethodNotDefined( raise MethodNotDefined("c_init_code_apply", type(self), self.__class__.__name__)
"c_init_code_apply", type(self), self.__class__.__name__
)
def c_init_code_struct(self, node, name, sub): def c_init_code_struct(self, node, name, sub):
""" """
...@@ -506,7 +501,7 @@ class CLinkerOp(CLinkerObject): ...@@ -506,7 +501,7 @@ class CLinkerOp(CLinkerObject):
The subclass does not override this method. The subclass does not override this method.
""" """
raise utils.MethodNotDefined( raise MethodNotDefined(
"c_init_code_struct", type(self), self.__class__.__name__ "c_init_code_struct", type(self), self.__class__.__name__
) )
...@@ -529,7 +524,7 @@ class CLinkerOp(CLinkerObject): ...@@ -529,7 +524,7 @@ class CLinkerOp(CLinkerObject):
Subclass does not implement this method. Subclass does not implement this method.
""" """
raise utils.MethodNotDefined( raise MethodNotDefined(
"c_support_code_struct", type(self), self.__class__.__name__ "c_support_code_struct", type(self), self.__class__.__name__
) )
...@@ -550,7 +545,7 @@ class CLinkerOp(CLinkerObject): ...@@ -550,7 +545,7 @@ class CLinkerOp(CLinkerObject):
The subclass does not override this method. The subclass does not override this method.
""" """
raise utils.MethodNotDefined( raise MethodNotDefined(
"c_cleanup_code_struct", type(self), self.__class__.__name__ "c_cleanup_code_struct", type(self), self.__class__.__name__
) )
...@@ -597,7 +592,7 @@ class PureOp(object): ...@@ -597,7 +592,7 @@ class PureOp(object):
The constructed `Apply` node. The constructed `Apply` node.
""" """
raise utils.MethodNotDefined("make_node", type(self), self.__class__.__name__) raise MethodNotDefined("make_node", type(self), self.__class__.__name__)
def __call__(self, *inputs, **kwargs): def __call__(self, *inputs, **kwargs):
"""Construct an `Apply` node using `self.make_node` and return its outputs. """Construct an `Apply` node using `self.make_node` and return its outputs.
...@@ -666,7 +661,7 @@ class PureOp(object): ...@@ -666,7 +661,7 @@ class PureOp(object):
# Convenience so that subclass implementers don't have to import utils # Convenience so that subclass implementers don't have to import utils
# just to self.add_tag_trace # just to self.add_tag_trace
add_tag_trace = staticmethod(utils.add_tag_trace) add_tag_trace = staticmethod(add_tag_trace)
def grad(self, inputs, output_grads): def grad(self, inputs, output_grads):
"""Construct a graph for the gradient with respect to each input variable. """Construct a graph for the gradient with respect to each input variable.
...@@ -779,7 +774,7 @@ class PureOp(object): ...@@ -779,7 +774,7 @@ class PureOp(object):
The subclass does not override this method. The subclass does not override this method.
""" """
raise utils.MethodNotDefined( raise MethodNotDefined(
"perform", "perform",
type(self), type(self),
self.__class__.__name__, self.__class__.__name__,
...@@ -809,7 +804,7 @@ class PureOp(object): ...@@ -809,7 +804,7 @@ class PureOp(object):
return True return True
class Op(utils.object2, PureOp, CLinkerOp): class Op(object2, PureOp, CLinkerOp):
""" """
Convenience class to bundle `PureOp` and `CLinkerOp`. Convenience class to bundle `PureOp` and `CLinkerOp`.
...@@ -833,7 +828,7 @@ class Op(utils.object2, PureOp, CLinkerOp): ...@@ -833,7 +828,7 @@ class Op(utils.object2, PureOp, CLinkerOp):
) )
# ParamsType.get_params() will apply filtering to attributes. # ParamsType.get_params() will apply filtering to attributes.
return self.params_type.get_params(self) return self.params_type.get_params(self)
raise theano.gof.utils.MethodNotDefined("get_params") raise MethodNotDefined("get_params")
def prepare_node(self, node, storage_map, compute_map, impl): def prepare_node(self, node, storage_map, compute_map, impl):
""" """
...@@ -984,7 +979,7 @@ class Op(utils.object2, PureOp, CLinkerOp): ...@@ -984,7 +979,7 @@ class Op(utils.object2, PureOp, CLinkerOp):
) )
try: try:
return self.make_c_thunk(node, storage_map, compute_map, no_recycling) return self.make_c_thunk(node, storage_map, compute_map, no_recycling)
except (NotImplementedError, utils.MethodNotDefined): except (NotImplementedError, MethodNotDefined):
# We requested the c code, so don't catch the error. # We requested the c code, so don't catch the error.
if impl == "c": if impl == "c":
raise raise
...@@ -1234,7 +1229,7 @@ def simple_meth(tag): ...@@ -1234,7 +1229,7 @@ def simple_meth(tag):
if tag in self.code_sections: if tag in self.code_sections:
return self.code_sections[tag] return self.code_sections[tag]
else: else:
raise utils.MethodNotDefined("c_" + tag, type(self), type(self).__name__) raise MethodNotDefined("c_" + tag, type(self), type(self).__name__)
f.__name__ = "c_" + tag f.__name__ = "c_" + tag
return f return f
...@@ -1248,7 +1243,7 @@ def apply_meth(tag): ...@@ -1248,7 +1243,7 @@ def apply_meth(tag):
define_macros, undef_macros = self.get_c_macros(node, name) define_macros, undef_macros = self.get_c_macros(node, name)
return "\n".join(["", define_macros, code, undef_macros]) return "\n".join(["", define_macros, code, undef_macros])
else: else:
raise utils.MethodNotDefined("c_" + tag, type(self), type(self).__name__) raise MethodNotDefined("c_" + tag, type(self), type(self).__name__)
f.__name__ = "c_" + tag f.__name__ = "c_" + tag
return f return f
...@@ -1435,7 +1430,7 @@ class COp(Op): ...@@ -1435,7 +1430,7 @@ class COp(Op):
wrapper.types[i].c_element_type(), wrapper.types[i].c_element_type(),
) )
) )
except utils.MethodNotDefined: except MethodNotDefined:
pass pass
return params return params
return [] return []
...@@ -1453,7 +1448,7 @@ class COp(Op): ...@@ -1453,7 +1448,7 @@ class COp(Op):
if "init_code" in self.code_sections: if "init_code" in self.code_sections:
return [self.code_sections["init_code"]] return [self.code_sections["init_code"]]
else: else:
raise utils.MethodNotDefined("c_init_code", type(self), type(self).__name__) raise MethodNotDefined("c_init_code", type(self), type(self).__name__)
c_init_code_apply = apply_meth("init_code_apply") c_init_code_apply = apply_meth("init_code_apply")
c_support_code = simple_meth("support_code") c_support_code = simple_meth("support_code")
...@@ -1575,7 +1570,7 @@ class COp(Op): ...@@ -1575,7 +1570,7 @@ class COp(Op):
["", def_macros, def_sub, op_code, undef_sub, undef_macros] ["", def_macros, def_sub, op_code, undef_sub, undef_macros]
) )
else: else:
raise utils.MethodNotDefined( raise MethodNotDefined(
"c_init_code_struct", type(self), type(self).__name__ "c_init_code_struct", type(self), type(self).__name__
) )
...@@ -1628,7 +1623,7 @@ class COp(Op): ...@@ -1628,7 +1623,7 @@ class COp(Op):
] ]
) )
else: else:
raise utils.MethodNotDefined("c_code", type(self), type(self).__name__) raise MethodNotDefined("c_code", type(self), type(self).__name__)
def c_code_cleanup(self, node, name, inputs, outputs, sub): def c_code_cleanup(self, node, name, inputs, outputs, sub):
""" """
...@@ -1653,6 +1648,4 @@ class COp(Op): ...@@ -1653,6 +1648,4 @@ class COp(Op):
] ]
) )
else: else:
raise utils.MethodNotDefined( raise MethodNotDefined("c_code_cleanup", type(self), type(self).__name__)
"c_code_cleanup", type(self), type(self).__name__
)
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论