Can `slice` from relay support empty result?

Hi

For strided_slice(data, begin, end, strides=None) , when begin=[0] and end=[0], strided_slice should return an empty array. Currently strided_slice will raise an error.

Can we adjust the code so strided_slice will return an empty array instead of raising an error?

I have the same problem and add judgment:

if end == 0:
    return _expr.const([],dtype = dtype)

A new error is encountered later, and I’m not sure if it’s related to this return value

There’s another piece of information,an error occurred while obtaining the end value:

def _stridedSlice():
     xxxx
     end = _get_list_param(params, inputs[2])
     xxxx

error info:
<class 'tvm.relay.expr.Call'> has no attribute name_hint

So,I change the code:

try:
    end = _get_list_param(params, inputs[2])
except (IndexError, KeyError, AttributeError):
    end = _infer_value(inputs[2], params).asnumpy().tolist()

Finally,I get the ‘end’ value of 0(end = [0]).But begin = [-1], after running ‘_transform_mask’ function, begin = [3] (because input shape is (4,),so [-1:] == [3:]).

I think the ‘end = _infer_value(inputs[2], params).asnumpy().tolist()’ is wrong. if not have ‘end’,the ‘enc’ value may be ‘len(inputs[0])’. example:

input.shape = (4,)
input[-1:] = input[-1:4] = input[3:4]

@kevinthesun As @lsy643 said, Can we adjust the code so strided_slice will return an empty array instead of raising an error?

Such as when ‘begin > end’ or ‘end == 0’ or etc, we return an empty array or ‘_expr.const([],dtype = dtype)’

https://github.com/apache/incubator-tvm/blob/e89b19d95d/topi/include/topi/transform.h#L620 begin == end case is already supported.

@kevinthesun My code has been updated recently, but still error:

tvm/src/relay/op/tensor/transform.cc: Check failed: begin_v < end_v (0 vs 0) :stride_slice get empty slice at axis 1

begin = [0,0]
end = [15,0]

When have an ‘end_v < begin_v error’ , it still seems to throw an error instead of continuing. It’s not just “end_v == begin_v”.

In this case, same change need to be made for relay: CHECK_LT(begin_v, end_v) -> CHECK_LE(begin_v, end_v)