Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There is no support for tf.strided_slice #28

Open
jeanlaroche opened this issue Apr 20, 2017 · 3 comments
Open

There is no support for tf.strided_slice #28

jeanlaroche opened this issue Apr 20, 2017 · 3 comments

Comments

@jeanlaroche
Copy link

Currently, there's no support for tf.strided_slice() so if somewhere in your graph you have x[:,:,:,None] the graph won't execute. It's a complicated function, so it won't be easy to implement.

@riga
Copy link
Owner

riga commented Apr 20, 2017

Although I don't have time to look into this right now ... Challenge accepted ;)

@celliern
Copy link

celliern commented Aug 22, 2017

I had to implement a very simple strided_slice implementation

class StridedSlice(td.Operation):
    @staticmethod
    def func(input_, begins, ends, strides):
        output = input_.copy()
        for dim, (begin, end, stride) in enumerate(zip(begins,
                                                       ends,
                                                       strides)):
            if dim >= len(input_.shape):
                raise ValueError("Dimension mismatch")
            end = end if end else None
            output = output[begin:end:stride].T

        return output,

It is sufficient for a "simple" strided slice, without new dimension add via array[None] or array[np.newaxis]

It is certainly not the best implementation, but it could be useful?

@jeanlaroche
Copy link
Author

@celliern: your implementation did not work for me, but this did for simple slices...

@Operation.factory()
def StridedSlice(input_, begins, ends,strides):
    dim = len(input_.shape)
    slices = [slice(b,e if e else None,s) for b,e,s in zip(begins,ends,strides)]
    return np.copy(input_)[slices],

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants