提交 dcd62712 authored 作者: Pascal Lamblin's avatar Pascal Lamblin

Add comments

上级 1b0b053d
......@@ -1413,6 +1413,14 @@ class _tensor_py_operators:
return cast(self, dtype)
#SLICING
# Do not define __getslice__ here:
# When calling t[1:], for instance, the arguments passed to __getslice__
# are (1, sys.maxsize), which is a pain to deal with, and can even not be
# an int (but a long).
# If __getslice__ does not exist, __getitem__ is called instead, with
# argument slice(1, None, None), which is much more desirable.
# __getslice__ is deprecated in python 2.6 anyway.
def __getitem__(self, args):
if not isinstance(args, tuple):
args = args,
......@@ -3117,6 +3125,9 @@ def get_canonical_form_slice(theslice, length):
, switch(lt(step,0),length-1,length)
, start)
if stop in [None, sys.maxsize]:
# The special "maxsize" case is probably not needed here,
# as slices containing maxsize are not generated by
# __getslice__ anymore.
stop = defstop
else:
stop = switch(lt(stop,0), stop + length, stop)
......@@ -3239,6 +3250,9 @@ class Subtensor(Op):
slice_a = None
if b is not None and b != sys.maxsize:
# The special "maxsize" case is probably not needed here,
# as slices containing maxsize are not generated by
# __getslice__ anymore.
slice_b = Subtensor.convert(b, False)
else:
slice_b = None
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论