def gufunc_args()

in hypothesis_gufunc/gufunc.py [0:0]


def gufunc_args(signature, dtype, elements, unique=False, excluded=(), min_side=0, max_side=5, max_dims_extra=0):
    """Strategy to generate a tuple of ndarrays for arguments to a function
    consistent with its signature with extra dimensions to test broadcasting.

    Parameters
    ----------
    signature : str
        Signature for shapes to be compatible with. Expects string in format
        of numpy generalized universal function signature, e.g.,
        `'(m,n),(n)->(m)'` for vectorized matrix-vector multiplication.
    dtype : list(:class:`numpy:numpy.dtype`)
        List of numpy `dtype` for each argument. These can be either strings
        (``'int64'``), type (``np.int64``), or numpy `dtype`
        (``np.dtype('int64')``). Built in Python types (`int`, `float`, etc)
        also work. A single `dtype` can be supplied for all arguments.
    elements : list
        List of strategies to fill in array elements on a per argument basis.
        One can also specify a single strategy
        (e.g., :func:`~hypothesis.strategies.floats`)
        and have it applied to all arguments.
    unique : list(bool)
        Boolean flag to specify if all elements in an array must be unique.
        One can also specify a single boolean to apply it to all arguments.
    excluded : set(int)
        Set of integers representing the positional for which the function will
        not be vectorized. Uses same format as :obj:`numpy.vectorize`.
    min_side : int or dict
        Minimum size of any side of the arrays. It is good to test the corner
        cases of 0 or 1 sized dimensions when applicable, but if not, a min
        size can be supplied here. Minimums can be provided on a per-dimension
        basis using a dict, e.g. ``min_side={'n': 2}``. One can use, e.g.,
        ``min_side={hypothesis_gufunc.gufunc.BCAST_DIM: 2}`` to limit the size
        of the broadcasted dimensions.
    max_side : int or dict
        Maximum size of any side of the arrays. This can usually be kept small
        and still find most corner cases in testing. Dictionaries can be
        supplied as with `min_side`.
    max_dims_extra : int
        Maximum number of extra dimensions that can be appended on left of
        arrays for broadcasting. This should be kept small as the memory used
        grows exponentially with extra dimensions. By default, no extra
        dimensions are added.

    Returns
    -------
    res : tuple(:class:`numpy:numpy.ndarray`)
        Resulting ndarrays with shapes consistent with `signature` and elements
        from `elements`. Extra dimensions for broadcasting will be present.

    Examples
    --------
    .. code-block:: pycon

      >>> from hypothesis_gufunc.gufunc import BCAST_DIM
      >>> from hypothesis.strategies import integers, booleans
      >>> gufunc_args('(m,n),(n)->(m)',
                      dtype=np.int_, elements=integers(0, 9), max_side=3,
                      min_side={'m': 1, 'n': 2, BCAST_DIM: 3}).example()
      (array([[9, 8, 1],
              [1, 7, 1]]), array([5, 6, 5]))
      >>> gufunc_args('(m,n),(n)->(m)', dtype=['bool', 'int32'],
                           elements=[booleans(), integers(0, 100)],
                           unique=[False, True], max_dims_extra=3).example()
      (array([[[[[ True,  True,  True,  True,  True],
                 [False,  True,  True,  True, False]]]]], dtype=bool),
       array([67, 43,  0, 34, 66], dtype=int32))

    """
    shape_st = gufunc_arg_shapes(
        signature, excluded=excluded, min_side=min_side, max_side=max_side, max_dims_extra=max_dims_extra
    )
    return _tuple_of_arrays(shape_st, dtype=dtype, elements=elements, unique=unique)