Generate vectorized (fancy) indexers where all arrays are broadcastable. In vectorized indexing, all array indexers must have compatible shapes that can be broadcast together, and the result shape is determined by broadcasting the indexer arrays. Parameters ---------- draw
(
draw,
/,
*,
sizes: dict[Hashable, int],
min_dims: int = 2,
max_dims: int | None = None,
min_ndim: int = 1,
max_ndim: int = 3,
min_size: int = 1,
max_size: int = 5,
)
| 636 | |
| 637 | @st.composite |
| 638 | def vectorized_indexers( |
| 639 | draw, |
| 640 | /, |
| 641 | *, |
| 642 | sizes: dict[Hashable, int], |
| 643 | min_dims: int = 2, |
| 644 | max_dims: int | None = None, |
| 645 | min_ndim: int = 1, |
| 646 | max_ndim: int = 3, |
| 647 | min_size: int = 1, |
| 648 | max_size: int = 5, |
| 649 | ) -> dict[Hashable, xr.DataArray]: |
| 650 | """Generate vectorized (fancy) indexers where all arrays are broadcastable. |
| 651 | |
| 652 | In vectorized indexing, all array indexers must have compatible shapes |
| 653 | that can be broadcast together, and the result shape is determined by |
| 654 | broadcasting the indexer arrays. |
| 655 | |
| 656 | Parameters |
| 657 | ---------- |
| 658 | draw : callable |
| 659 | The Hypothesis draw function (automatically provided by @st.composite). |
| 660 | sizes : dict[Hashable, int] |
| 661 | Dictionary mapping dimension names to their sizes. |
| 662 | min_dims : int, optional |
| 663 | Minimum number of dimensions to index. Default is 2, so that we always have a "trajectory". |
| 664 | Use ``outer_array_indexers`` for the ``min_dims==1`` case. |
| 665 | max_dims : int or None, optional |
| 666 | Maximum number of dimensions to index. |
| 667 | min_ndim : int, optional |
| 668 | Minimum number of dimensions for the result arrays. |
| 669 | max_ndim : int, optional |
| 670 | Maximum number of dimensions for the result arrays. |
| 671 | min_size : int, optional |
| 672 | Minimum size for each dimension in the result arrays. |
| 673 | max_size : int, optional |
| 674 | Maximum size for each dimension in the result arrays. |
| 675 | |
| 676 | Returns |
| 677 | ------- |
| 678 | sizes : mapping of hashable to DataArray or Variable |
| 679 | Indexers as a dict with keys randomly selected from sizes.keys(). |
| 680 | Values are DataArrays of integer indices that are all broadcastable |
| 681 | to a common shape. |
| 682 | |
| 683 | See Also |
| 684 | -------- |
| 685 | hypothesis.extra.numpy.arrays |
| 686 | """ |
| 687 | selected_dims = draw(unique_subset_of(sizes, min_size=min_dims, max_size=max_dims)) |
| 688 | |
| 689 | # Generate a common broadcast shape for all arrays |
| 690 | # Use min_ndim to max_ndim dimensions for the result shape |
| 691 | result_shape = draw( |
| 692 | st.lists( |
| 693 | st.integers(min_value=min_size, max_value=max_size), |
| 694 | min_size=min_ndim, |
| 695 | max_size=max_ndim, |
searching dependent graphs…