I am wondering what tf.strided_slice() operator actually does.
The doc says,
To a first order, this operation extracts a slice of siz
The conceptualization that really helped me understand this was that this function emulates the indexing behavior of numpy arrays.
If you're familiar with numpy arrays, you'll know that you can make slices via input[start1:end1:step1, start2:end2:step2, ... startN:endN:stepN]. Basically, a very succinct way of writing for loops to get certain elements of the array.
(If you're familiar with python indexing, you know that you can grab an array slice via input[start:end:step]. Numpy arrays, which may be nested, make use of the above tuple of slice objects.)
Well, strided_slice just allows you to do this fancy indexing without the syntactic sugar. The numpy example from above just becomes
# input[start1:end1:step1, start2:end2:step2, ... startN:endN:stepN]
tf.strided_slice(input, [start1, start2, ..., startN],
[end1, end2, ..., endN], [step1, step2, ..., stepN])
The documentation is a bit confusing about this in the sense that:
a) begin - end is not strictly the shape of the return value:
The documentation claims otherwise, but this is only true if your strides are all ones. Examples:
rank1 = tf.constant(list(range(10)))
# The below op is basically:
# rank1[1:10:2] => [1, 3, 5, 7, 9]
tf.strided_slice(rank1, [1], [10], [2])
# [10,10] grid of the numbers from 0 to 99
rank2 = tf.constant([[i+j*10 for i in range(10)] for j in range(10)])
# The below op is basically:
# rank2[3:7:1, 5:10:2] => numbers 30 - 69, ending in 5, 7, or 9
sliced = tf.strided_slice(rank2, [3, 5], [7, 10], [1, 2])
# The below op is basically:
# rank2[3:7:1] => numbers 30 - 69
sliced = tf.strided_slice(rank2, [3], [7], [1])
b) it states that "begin, end, and strides will be all length n, where n is in general not the same dimensionality as input"
It sounds like dimensionality means rank here - but input does have to be a tensor of at least rank-n; it can't be lower (see rank-2 example above).
N.B. I've said nothing/not really explored the masking feature, but that seems beyond the scope of the question.