提交 3c4b014b authored 作者: Olivier Breuleux's avatar Olivier Breuleux

better serialization

上级 78928528
...@@ -155,6 +155,9 @@ class SymbolicOutput(object): ...@@ -155,6 +155,9 @@ class SymbolicOutput(object):
self.result = result self.result = result
self.borrow = borrow self.borrow = borrow
def __str__(self):
return "Out(%s)" % self.result
Out = SymbolicOutput Out = SymbolicOutput
...@@ -491,7 +491,7 @@ class Module(Composite): ...@@ -491,7 +491,7 @@ class Module(Composite):
def __init__(self, components = {}, **kwcomponents): def __init__(self, components = {}, **kwcomponents):
super(Module, self).__init__() super(Module, self).__init__()
components = dict(components, **kwcomponents) components = dict(components, **kwcomponents)
self._components = components self.__dict__['_components'] = components
def resolve(self, name): def resolve(self, name):
name = canonicalize(name) name = canonicalize(name)
...@@ -589,6 +589,8 @@ class Curry: ...@@ -589,6 +589,8 @@ class Curry:
class FancyModuleInstance(ModuleInstance): class FancyModuleInstance(ModuleInstance):
def __getattr__(self, attr): def __getattr__(self, attr):
if attr == '__items__' and '__items__' not in self.__dict__:
self.__dict__['__items__'] = {}
try: try:
return self[attr] return self[attr]
except KeyError: except KeyError:
...@@ -607,6 +609,8 @@ class FancyModule(Module): ...@@ -607,6 +609,8 @@ class FancyModule(Module):
return wrap(x) return wrap(x)
def __getattr__(self, attr): def __getattr__(self, attr):
if attr == '_components' and '_components' not in self.__dict__:
self.__dict__['_components'] = {}
try: try:
rval = self[attr] rval = self[attr]
except KeyError: except KeyError:
...@@ -616,12 +620,13 @@ class FancyModule(Module): ...@@ -616,12 +620,13 @@ class FancyModule(Module):
return rval return rval
def __setattr__(self, attr, value): def __setattr__(self, attr, value):
if attr == 'parent': if attr in ('parent', '_components'):
self.__dict__[attr] = value self.__dict__[attr] = value
return return
elif attr == 'name': elif attr == 'name':
self.__set_name__(value) self.__set_name__(value)
return return
value = self.__wrapper__(value) value = self.__wrapper__(value)
try: try:
self[attr] = value self[attr] = value
......
...@@ -262,6 +262,7 @@ class Elemwise(Op): ...@@ -262,6 +262,7 @@ class Elemwise(Op):
def __getstate__(self): def __getstate__(self):
d = copy(self.__dict__) d = copy(self.__dict__)
d.pop('ufunc') d.pop('ufunc')
d.pop('__epydoc_asRoutine', None)
return d return d
def __setstate__(self, d): def __setstate__(self, d):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论