def test_slice_canonical_form_2(self):
start = tensor.iscalar('b')
step = tensor.iscalar('s')
length = tensor.iscalar('l')
cnf = get_canonical_form_slice(slice(start, None, step), length)
f = self.function([start, step, length], [
tensor.as_tensor_variable(cnf[0].start),
tensor.as_tensor_variable(cnf[0].stop),
tensor.as_tensor_variable(cnf[0].step),
tensor.as_tensor_variable(cnf[1])], N=0, op=self.ops)
length = 5
a = numpy.arange(length)
for start in [-8, -5, -4, -1, 0, 1, 4, 5, 8]:
for step in [-6, -3, -1, 2, 5]:
out = f(start, step, length)
t_out = a[out[0]:out[1]:out[2]][::out[3]]
v_out = a[start:None:step]
assert numpy.all(t_out == v_out)
assert numpy.all(t_out.shape == v_out.shape)
评论列表
文章目录