in hypothesis_gufunc/gufunc.py [0:0]
def _tuple_of_arrays(draw, shapes, dtype, elements, unique=False):
"""Strategy to generate a tuple of ndarrays with specified shapes.
Parameters
----------
shapes : list of tuples of int
List of tuples where each tuple is the shape of an argument. A
`SearchStrategy` for list of tuples is also supported.
dtype : list-like of 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-like of strategy
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-like of 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.
Returns
-------
res : tuple of ndarrays
Resulting ndarrays with shape of `shapes` and elements from `elements`.
"""
if isinstance(shapes, SearchStrategy):
shapes = draw(shapes)
n = len(shapes)
# Need this since broadcast_to does not like vars of type type
if isinstance(dtype, type):
dtype = [dtype]
dtype = np.broadcast_to(dtype, (n,))
elements = np.broadcast_to(elements, (n,))
unique = np.broadcast_to(unique, (n,))
# This could somewhat easily be done using builds and avoid need for
# composite if shape is always given and not strategy. Otherwise, we need
# to chain strategies and probably not worth the effort.
res = tuple(draw(arrays(dd, ss, elements=ee, unique=uu)) for dd, ss, ee, uu in zip(dtype, shapes, elements, unique))
return res