-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #166 from asmeurer/selected_indices
Implement selected_indices()
- Loading branch information
Showing
11 changed files
with
178 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from numpy import arange | ||
|
||
from hypothesis import given, example | ||
from hypothesis.strategies import integers, one_of | ||
|
||
from ..ndindex import ndindex | ||
from ..tuple import Tuple | ||
from ..integer import Integer | ||
from .helpers import ndindices, check_same, short_shapes, prod | ||
|
||
@example(([False], None), (1,)) | ||
@example((False, slice(0, 10)), (5, 2)) | ||
@example((None, True, 0), (5, 2)) | ||
@example((slice(0, 10), [0, -1]), (5, 2)) | ||
@example(slice(0, 10), 5) | ||
@example([0, 1, 2], 3) | ||
@example(([0, 1, 2],), 3) | ||
@given(ndindices, one_of(short_shapes, integers(0, 10))) | ||
def test_selected_indices_hypothesis(idx, shape): | ||
if isinstance(shape, int): | ||
a = arange(shape) | ||
else: | ||
a = arange(prod(shape)).reshape(shape) | ||
|
||
ndindex(idx) | ||
|
||
def raw_func(a, idx): | ||
return list(a[idx].flat) | ||
|
||
def ndindex_func(a, index): | ||
indices = list(index.selected_indices(shape)) | ||
for i in indices: | ||
if len(a.shape) == 1: | ||
assert isinstance(i, Integer) | ||
else: | ||
assert isinstance(i, Tuple) | ||
assert all(isinstance(j, Integer) for j in i.args) | ||
|
||
return [a[i.raw] for i in indices] | ||
|
||
def assert_equal(a, b): | ||
assert a == b | ||
|
||
check_same(a, idx, raw_func=raw_func, ndindex_func=ndindex_func, | ||
assert_equal=assert_equal, same_exception=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters