Numpy2 uses .data property, DestroyHandler uses new view_map and destroy_map

上级 ad8c564c
...@@ -116,33 +116,33 @@ class Numpy2(ResultBase): ...@@ -116,33 +116,33 @@ class Numpy2(ResultBase):
################################ ################################
# Numpy2 specific functionality # Numpy2 specific functionality
# #
__array__ = property(lambda self: self._data.__array__ ) __array__ = property(lambda self: self.data.__array__ )
__array_struct__ = property(lambda self: self._data.__array_struct__ ) __array_struct__ = property(lambda self: self.data.__array_struct__ )
def data_alloc(self): def data_alloc(self):
return numpy.ndarray(self.shape, self.dtype) return numpy.ndarray(self.shape, self.dtype)
# self._dtype is used when self._data hasn't been set yet # self._dtype is used when self.data hasn't been set yet
def __dtype_get(self): def __dtype_get(self):
if self._data is None: if self.data is None:
return self._dtype return self._dtype
else: else:
return self._data.dtype return self.data.dtype
def __dtype_set(self, dtype): def __dtype_set(self, dtype):
if self._data is None: if self.data is None:
self._dtype = dtype self._dtype = dtype
else: else:
raise StateError('cannot set dtype after data has been set') raise StateError('cannot set dtype after data has been set')
dtype = property(__dtype_get, __dtype_set) dtype = property(__dtype_get, __dtype_set)
# self._shape is used when self._data hasn't been set yet # self._shape is used when self.data hasn't been set yet
def __shape_get(self): def __shape_get(self):
if self._data is None: if self.data is None:
return self._shape return self._shape
else: else:
return self._data.shape return self.data.shape
def __shape_set(self, shape): def __shape_set(self, shape):
if self._data is None: if self.data is None:
self._shape = shape self._shape = shape
else: else:
raise StateError('cannot set shape after data has been set') raise StateError('cannot set shape after data has been set')
......
from copy import copy
from op import Op from op import Op
from result import is_result, ResultBase from result import is_result, ResultBase
...@@ -185,9 +186,7 @@ class DestroyHandler(features.Listener, features.Constraint, features.Orderings) ...@@ -185,9 +186,7 @@ class DestroyHandler(features.Listener, features.Constraint, features.Orderings)
self.__detect_cycles_helper__(user, []) self.__detect_cycles_helper__(user, [])
def get_maps(self, op): def get_maps(self, op):
vmap = getattr(op, 'view_map',{}) return op.view_map(), op.destroy_map()
dmap = getattr(op, 'destoy_map', {})
return vmap, dmap
def on_import(self, op): def on_import(self, op):
view_map, destroy_map = self.get_maps(op) view_map, destroy_map = self.get_maps(op)
...@@ -347,6 +346,8 @@ class DestroyHandler(features.Listener, features.Constraint, features.Orderings) ...@@ -347,6 +346,8 @@ class DestroyHandler(features.Listener, features.Constraint, features.Orderings)
class NewPythonOp(Op): class NewPythonOp(Op):
__require__ = DestroyHandler
def view_map(self): def view_map(self):
return {} return {}
...@@ -358,8 +359,6 @@ class PythonOp(NewPythonOp): ...@@ -358,8 +359,6 @@ class PythonOp(NewPythonOp):
__metaclass__ = ClsInit __metaclass__ = ClsInit
__require__ = DestroyHandler
nout = 1 nout = 1
@staticmethod @staticmethod
...@@ -580,7 +579,7 @@ class PythonOpt(opt.Optimizer): ...@@ -580,7 +579,7 @@ class PythonOpt(opt.Optimizer):
class DummyOp(Op): class DummyOp(NewPythonOp):
def __init__(self, input): def __init__(self, input):
Op.__init__(self, [input], [ResultBase()]) Op.__init__(self, [input], [ResultBase()])
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论