提交 ebfbfe8a authored 作者: Frederic's avatar Frederic

Add support for neg start and stop.

上级 0926a6c5
......@@ -4252,14 +4252,20 @@ def get_vector_length(v):
v.owner.inputs, v.owner.op.idx_list)[0].stop)
step = extract_constant(theano.tensor.subtensor.get_idx_list(
v.owner.inputs, v.owner.op.idx_list)[0].step)
if start is None:
start = 0
ndim = v.owner.inputs[0].owner.inputs[0].ndim
types = (numbers.Integral, numpy.integer)
if start is None:
start = 0
elif isinstance(start, types) and start < 0:
start += ndim
if stop is None:
stop = ndim
elif isinstance(stop, types) and stop > ndim:
stop = ndim
elif isinstance(stop, types):
if stop > ndim:
stop = ndim
elif stop < 0:
stop += ndim
if step is None:
step = 1
......
......@@ -3354,7 +3354,13 @@ class T_GetVectorLength(unittest.TestCase):
assert len(list(x.shape[1:4])) == 3
assert len(list(x.shape[1:5])) == 3
assert len(list(x.shape[1:10])) == 3
# Test step
assert len(list(x.shape[1:10:2])) == 2
# Test neg start
assert len(list(x.shape[-1:4])) == 1
# test neg stop
assert len(list(x.shape[1:-2])) == 1
assert len(list(x.shape[1:-1])) == 2
class T_Join_and_Split(unittest.TestCase):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论