提交 82ae38c6 authored 作者: Frederic's avatar Frederic

Document Type.may_share_memory and implement it in Scalar.

上级 ca8859d0
...@@ -138,6 +138,13 @@ default values. ...@@ -138,6 +138,13 @@ default values.
:return: the number of bytes taken by the object described by :return: the number of bytes taken by the object described by
``shape_info``. ``shape_info``.
.. method:: may_share_memory(a, b)
Optional. Only needed for DebugMode. Return True if the python
objects `a` and `b` could share memory. Return False
otherwise. It is used to debug when Ops didn't declare memory
aliaing between variables. Must be a static method.
For each method, the *default* is what ``Type`` defines For each method, the *default* is what ``Type`` defines
for you. So, if you create an instance of ``Type`` or an for you. So, if you create an instance of ``Type`` or an
instance of a subclass of ``Type``, you instance of a subclass of ``Type``, you
......
...@@ -145,6 +145,13 @@ class Scalar(Type): ...@@ -145,6 +145,13 @@ class Scalar(Type):
self.dtype = dtype self.dtype = dtype
self.dtype_specs() # error checking self.dtype_specs() # error checking
@staticmethod
def may_share_memory(a, b):
# This class represent basic c type, represented in python
# with numpy.scalar. They are read only. So from python, they
# can never share memory.
return False
def filter(self, data, strict=False, allow_downcast=None): def filter(self, data, strict=False, allow_downcast=None):
py_type = self.dtype_specs()[0] py_type = self.dtype_specs()[0]
if strict and not isinstance(data, py_type): if strict and not isinstance(data, py_type):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论