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

better serialization

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