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

Add Numpy strategy for basic_indexes(shape) #1930

Closed
Zac-HD opened this issue Apr 16, 2019 · 0 comments · Fixed by #2123
Closed

Add Numpy strategy for basic_indexes(shape) #1930

Zac-HD opened this issue Apr 16, 2019 · 0 comments · Fixed by #2123
Assignees
Labels
new-feature entirely novel capabilities or strategies

Comments

@Zac-HD
Copy link
Member

Zac-HD commented Apr 16, 2019

This issue is extracted from #1829, and depends on slices() from #1929.

MyGrad defines a strategy for basic_indexes, and we would like to bring a simpler version of it into the upstream hypothesis.extra.numpy.

Given an array shape, it generates valid indices for an array of that shape which conform to the basic (i.e. no-copy) indexing specification. Examples from this strategy shrink from indices that produce high-dimensional views of the input array, down to indices that select a single element from the array.

An initial implementation could work something like:

def basic_indexes(shape):
    # Validation logic for shape here - consider extracting a check_shape helper.
    return tuples(*(slices(s) for s in shape))

An optional extension would add an allow_ellipsis=True flag, which picks 0-2 dims to replace with ... - only a few to ensure that the resulting arrays are typically reasonably small compared to the input shape, but may still generate a slice with a length != the number of dimensions to index.

np.newaxis (aka None) is also supported to add size-1 dimensions in any position, but we would put this behind a allow_newaxis=False flag. As a disabled-by-default additional feature, we would prefer to receive a follow-up pull request to support newaxis after the initial version is complete and released to users.

@Zac-HD Zac-HD added the new-feature entirely novel capabilities or strategies label Apr 16, 2019
lmount added a commit to lmount/hypothesis that referenced this issue Jul 13, 2019
@Zac-HD Zac-HD self-assigned this Oct 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-feature entirely novel capabilities or strategies
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant