Generate outer array indexers (vectorized/orthogonal indexing). Parameters ---------- draw : callable The Hypothesis draw function (automatically provided by @st.composite). sizes : dict[Hashable, int] Dictionary mapping dimension names to their sizes. min_dims :
(
draw,
/,
*,
sizes: dict[Hashable, int],
min_dims: int = 0,
max_dims: int | None = None,
max_size: int = 10,
)
| 589 | |
| 590 | @st.composite |
| 591 | def outer_array_indexers( |
| 592 | draw, |
| 593 | /, |
| 594 | *, |
| 595 | sizes: dict[Hashable, int], |
| 596 | min_dims: int = 0, |
| 597 | max_dims: int | None = None, |
| 598 | max_size: int = 10, |
| 599 | ) -> dict[Hashable, np.ndarray]: |
| 600 | """Generate outer array indexers (vectorized/orthogonal indexing). |
| 601 | |
| 602 | Parameters |
| 603 | ---------- |
| 604 | draw : callable |
| 605 | The Hypothesis draw function (automatically provided by @st.composite). |
| 606 | sizes : dict[Hashable, int] |
| 607 | Dictionary mapping dimension names to their sizes. |
| 608 | min_dims : int, optional |
| 609 | Minimum number of dimensions to index |
| 610 | max_dims : int or None, optional |
| 611 | Maximum number of dimensions to index |
| 612 | |
| 613 | Returns |
| 614 | ------- |
| 615 | sizes : mapping of hashable to np.ndarray |
| 616 | Indexers as a dict with keys randomly selected from ``sizes.keys()``. |
| 617 | Values are 1D numpy arrays of integer indices for each dimension. |
| 618 | |
| 619 | See Also |
| 620 | -------- |
| 621 | hypothesis.extra.numpy.arrays |
| 622 | """ |
| 623 | selected_dims = draw(unique_subset_of(sizes, min_size=min_dims, max_size=max_dims)) |
| 624 | idxr = { |
| 625 | dim: draw( |
| 626 | npst.arrays( |
| 627 | dtype=np.int64, |
| 628 | shape=st.integers(min_value=1, max_value=min(size, max_size)), |
| 629 | elements=st.integers(min_value=-size, max_value=size - 1), |
| 630 | ) |
| 631 | ) |
| 632 | for dim, size in selected_dims.items() |
| 633 | } |
| 634 | return idxr |
| 635 | |
| 636 | |
| 637 | @st.composite |
searching dependent graphs…