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

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