Array helpers#

ivy_tests.test_ivy.helpers.hypothesis_helpers.array_helpers.array_and_broadcastable_shape(dtype)[source]#

Return an array and a shape that the array can be broadcast to.

Return type:

SearchStrategy

ivy_tests.test_ivy.helpers.hypothesis_helpers.array_helpers.array_bools(*, size=shared(ints(min_value=1, max_value=4), key='size'))[source]#

Draws a list of booleans with a given size.

Parameters:
  • draw – special function that draws data randomly (but is reproducible) from a given data-set (ex. list).

  • size – size of the list.

Return type:

SearchStrategy

Returns:

ret – A strategy that draws a list.

Examples

>>> array_bools(size=5)
[False, True, False, False, False]
>>> array_bools(size=5)
[False, False, False, False, False]
>>> array_bools(size=5)
[True, False, False, False, False]
>>> array_bools(size=1)
[True]
>>> array_bools(size=1)
[False]
>>> array_bools(size=1)
[True]
>>> array_bools()
[False, False, False, False]
>>> array_bools()
[True, True, True, False]
>>> array_bools()
[True]
ivy_tests.test_ivy.helpers.hypothesis_helpers.array_helpers.array_indices_axis(*, array_dtypes, indices_dtypes=get_dtypes(), disable_random_axis=False, axis_zero=False, allow_inf=False, min_num_dims=1, max_num_dims=5, min_dim_size=1, max_dim_size=10, first_dimension_only=False, indices_same_dims=False, valid_bounds=True)[source]#

Generate two arrays x & indices, the values in the indices array are indices of the array x. Draws an integers randomly from the minimum and maximum number of positional arguments a given function can take.

Parameters:
  • draw – special function that draws data randomly (but is reproducible) from a given data-set (ex. list).

  • array_dtypes – list of data type to draw the array dtype from.

  • indices_dtypes – list of data type to draw the indices dtype from.

  • disable_random_axis – axis is randomly generated with hypothesis if False. If True, axis is set to 0 if axis_zero is True, -1 otherwise.

  • axis_zero – If True, axis is set to zero if disable_random_axis is True.

  • allow_inf – inf values are allowed to be generated in the values array when True.

  • min_num_dims – The minimum number of dimensions the arrays can have.

  • max_num_dims – The maximum number of dimensions the arrays can have.

  • min_dim_size – The minimum size of the dimensions of the arrays.

  • max_dim_size – The maximum size of the dimensions of the arrays.

  • indices_same_dims – Set x and indices dimensions to be the same

  • valid_bounds – If False, the strategy may produce out-of-bounds indices.

Return type:

SearchStrategy

Returns:

ret – A strategy that can be used in the @given hypothesis decorator which generates arrays of values and indices.

Examples

@given(
array_indices_axis=array_indices_axis(

array_dtypes=helpers.get_dtypes(“valid”), indices_dtypes=helpers.get_dtypes(“integer”), min_num_dims=1, max_num_dims=5, min_dim_size=1, max_dim_size=10 )

)

>>> array_indices_axis(
...    array_dtypes=get_dtypes("valid"),
...     indices_dtypes=["int64"],
...     max_num_dims=1,
...     indices_same_dims=True,
...     disable_random_axis=True,
...     axis_zero=True,
... )
(['int64', 'int64'], array([-65536]), array([0]))
>>> array_indices_axis(
...    array_dtypes=get_dtypes("valid"),
...     indices_dtypes=["int64"],
...     max_num_dims=1,
...     indices_same_dims=True,
...     disable_random_axis=True,
...     axis_zero=True,
... )
(['bool', 'int64'], array([False, False, False, True,
    False, False, False, False]), array([0, 0, 2, 4,
    0, 0, 0, 1]))
>>> array_indices_axis(
...    array_dtypes=get_dtypes("valid"),
...     indices_dtypes=["int64"],
...     max_num_dims=1,
...     indices_same_dims=True,
...     disable_random_axis=True,
...     axis_zero=True,
... )
(['int64', 'int64'], array([0]), array([0]))
>>> array_indices_axis(
...     array_dtypes=get_dtypes("valid"),
...     indices_dtypes=get_dtypes("integer"),
...     disable_random_axis=True,
...     first_dimension_only=True,
... )
(['float64', 'uint64'], array([-2.44758124e-308]),
    array([0], dtype=uint64))
>>> array_indices_axis(
...     array_dtypes=get_dtypes("valid"),
...     indices_dtypes=get_dtypes("integer"),
...     disable_random_axis=True,
...     first_dimension_only=True,
... )
(['bool', 'uint64'], array([False]), array([0], dtype=uint64))
>>> array_indices_axis(
...     array_dtypes=get_dtypes("valid"),
...     indices_dtypes=get_dtypes("integer"),
...     disable_random_axis=True,
...     first_dimension_only=True,
... )
(['bool', 'int8'], array([False]), array([[0, 0, 0, 0],
   [0, 0, 0, 0],
   [0, 0, 0, 0],
   [0, 0, 0, 0]], dtype=int8))
>>> array_indices_axis(
...     array_dtypes=get_dtypes("valid"),
...     indices_dtypes=["int64"],
...     max_num_dims=1,
...     indices_same_dims=True,
... )
(['float16', 'int64'], array([-256.], dtype=float16),
    array([0]), 0, 0)
>>> array_indices_axis(
...     array_dtypes=get_dtypes("valid"),
...     indices_dtypes=["int64"],
...     max_num_dims=1,
...     indices_same_dims=True,
... )
(['uint8', 'int64'], array([1], dtype=uint8),
    array([0]), -1, 0)
>>> array_indices_axis(
...     array_dtypes=get_dtypes("valid"),
...     indices_dtypes=["int64"],
...     max_num_dims=1,
...     indices_same_dims=True,
... )
(['uint64', 'int64'], array([0], dtype=uint64),
    array([0]), 0, 0)
ivy_tests.test_ivy.helpers.hypothesis_helpers.array_helpers.array_values(*, dtype, shape, abs_smallest_val=None, min_value=None, max_value=None, allow_nan=False, allow_subnormal=False, allow_inf=False, exclude_min=True, exclude_max=True, large_abs_safety_factor=1.1, small_abs_safety_factor=1.1, safety_factor_scale='linear')[source]#

Draws a list (of lists) of a given shape containing values of a given data type.

Parameters:
  • draw – special function that draws data randomly (but is reproducible) from a given data-set (ex. list).

  • dtype – data type of the elements of the list.

  • shape – shape of the required list.

  • abs_smallest_val – sets the absolute smallest value to be generated for float data types, this has no effect on integer data types. If none, the default data type absolute smallest value is used.

  • min_value – minimum value of elements in the list.

  • max_value – maximum value of elements in the list.

  • allow_nan – if True, allow Nans in the list.

  • allow_subnormal – if True, allow subnormals in the list.

  • allow_inf – if True, allow inf in the list.

  • exclude_min – if True, exclude the minimum limit.

  • exclude_max – if True, exclude the maximum limit.

  • large_abs_safety_factor

    A safety factor of 1 means that all values are included without limitation,

    when a “linear” safety factor scaler is used, a safety factor of 2 means that only 50% of the range is included, a safety factor of 3 means that only 33% of the range is included etc.

    when a “log” safety factor scaler is used, a data type with maximum value of 2^32 and a safety factor of 2 transforms the maximum to 2^16.

  • small_abs_safety_factor

    A safety factor of 1 means that all values are included without limitation, this has no effect on integer data types.

    when a “linear” safety factor scaler is used, a data type with minimum representable number of 0.0001 and a safety factor of 2 transforms the minimum to 0.0002, a safety factor of 3 transforms the minimum to 0.0003 etc.

    when a “log” safety factor scaler is used, a data type with minimum representable number of 0.5 * 2^-16 and a safety factor of 2 transforms the minimum to 0.5 * 2^-8, a safety factor of 3 transforms the minimum to 0.5 * 2^-4

  • safety_factor_scale – The operation to use when calculating the maximum value of the list. Can be “linear” or “log”. Default value = “linear”.

  • range (the) –

  • limit (the invalid value will be replaced by data type) –

  • range

  • preserved. (of the numbers in that case is not) –

Return type:

SearchStrategy

Returns:

A strategy that draws a list.

Examples

>>> array_values(
...     dtype=get_dtypes("valid"),
...     shape=get_shape(),
... )
[1806 87 36912 6955 59576]
>>> array_values(
...     dtype=get_dtypes("valid"),
...     shape=get_shape(),
... )
1025
ivy_tests.test_ivy.helpers.hypothesis_helpers.array_helpers.arrays_and_axes(available_dtypes=get_dtypes(kind='float'), allow_none=False, min_num_dims=1, max_num_dims=5, min_dim_size=1, max_dim_size=10, num=2, return_dtype=False, force_int_axis=False)[source]#

Generate a list of arrays and axes.

Parameters:
  • draw – special function that draws data randomly (but is reproducible) from a given data-set (ex. list).

  • available_dtypes – if dtype is None, data type is drawn from this list randomly.

  • allow_none – if True, one of the dimensions can be None

  • min_num_dims – The minimum number of dimensions the arrays can have.

  • max_num_dims – The maximum number of dimensions the arrays can have.

  • min_dim_size – The minimum size of the dimensions of the arrays.

  • max_dim_size – The maximum size of the dimensions of the arrays.

  • num – The number of arrays to be generated

  • return_dtype – If True, return a tuple of the form (dtype, arrays, axes) instead of (arrays, axes)

  • force_int_axis – If True and only one axis is drawn for each array, the returned axis will be an integer instead of a tuple containing one integer or None

Return type:

SearchStrategy

Returns:

A strategy that draws arrays and their axes

Examples

>>> arrays_and_axes(
...     allow_none=False,
...     min_num_dims=1,
...     max_num_dims=2,
...     min_dim_size=2,
...     max_dim_size=4,
...     num=2,
...     return_dtype=True,
... )
(['float16', 'float16'], [array([[-1., -1.],
    [-1., -1.]], dtype=float16), array([[-1., -1.],
    [-1., -1.]], dtype=float16)], (None, None))
>>> arrays_and_axes(
...     allow_none=False,
...     min_num_dims=1,
...     max_num_dims=2,
...     min_dim_size=2,
...     max_dim_size=4,
...     num=2,
...     return_dtype=True,
... )
(['float16', 'float32'],
    [array([ 1.5 , -8.33], dtype=float16),
    array([8.26e+00, 9.10e+00, 6.72e-05], dtype=float16)],
    (0, None))
>>> arrays_and_axes(
...     allow_none=False,
...     min_num_dims=1,
...     max_num_dims=2,
...     min_dim_size=2,
...     max_dim_size=4,
...     num=2,
...     return_dtype=True,
... )
(['float64', 'float32'],
    [array([-1.1, -12.24322108]),
    array([[-2.44758124e-308, 8.26446279e+000, 5.96046448e-008],
    [1.17549435e-038, 1.06541027e-001, 1.13725760e+001]])],
    (None, None))
>>> arrays_and_axes(
...     num=1,
...     force_int_axis=True,
... )
([array([0.07143888])], 0)
>>> arrays_and_axes(
...     num=1,
...     force_int_axis=True,
... )
([array([-2.44758124e-308])], None)
>>> arrays_and_axes(
...     num=1,
...     force_int_axis=True,
... )
([array([-6.72e-05, -6.72e-05, -6.72e-05, -6.72e-05, -6.72e-05],
    dtype=float16)], 0)
ivy_tests.test_ivy.helpers.hypothesis_helpers.array_helpers.arrays_for_pooling(min_dims, max_dims, min_side, max_side, explicit_or_str_padding=False, only_explicit_padding=False, return_dilation=False, data_format='channel_last')[source]#
Return type:

SearchStrategy

ivy_tests.test_ivy.helpers.hypothesis_helpers.array_helpers.broadcast_shapes(*shapes)[source]#
ivy_tests.test_ivy.helpers.hypothesis_helpers.array_helpers.dtype_and_values(*, available_dtypes=get_dtypes(), num_arrays=1, abs_smallest_val=None, min_value=None, max_value=None, large_abs_safety_factor=1.1, small_abs_safety_factor=1.1, safety_factor_scale='linear', allow_inf=False, allow_nan=False, exclude_min=False, exclude_max=False, min_num_dims=0, max_num_dims=5, min_dim_size=1, max_dim_size=10, shape=None, shared_dtype=False, ret_shape=False, dtype=None, array_api_dtypes=False)[source]#

Draws a list of arrays with elements from the given corresponding data types.

Parameters:
  • draw – special function that draws data randomly (but is reproducible) from a given data-set (ex. list).

  • available_dtypes – if dtype is None, data types are drawn from this list randomly.

  • num_arrays – Number of arrays to be drawn.

  • abs_smallest_val – sets the absolute smallest value to be generated for float data types, this has no effect on integer data types. If none, the default data type absolute smallest value is used.

  • min_value – minimum value of elements in each array.

  • max_value – maximum value of elements in each array.

  • large_abs_safety_factor

    A safety factor of 1 means that all values are included without limitation,

    when a “linear” safety factor scaler is used, a safety factor of 2 means that only 50% of the range is included, a safety factor of 3 means that only 33% of the range is included etc.

    when a “log” safety factor scaler is used, a data type with maximum value of 2^32 and a safety factor of 2 transforms the maximum to 2^16.

  • small_abs_safety_factor

    A safety factor of 1 means that all values are included without limitation, this has no effect on integer data types.

    when a “linear” safety factor scaler is used, a data type with minimum representable number of 0.0001 and a safety factor of 2 transforms the minimum to 0.0002, a safety factor of 3 transforms the minimum to 0.0003 etc.

    when a “log” safety factor scaler is used, a data type with minimum representable number of 0.5 * 2^-16 and a safety factor of 2 transforms the minimum to 0.5 * 2^-8, a safety factor of 3 transforms the minimum to 0.5 * 2^-4

  • safety_factor_scale – The operation to use for the safety factor scaling. Can be “linear” or “log”. Default value = “linear”.

  • allow_inf – if True, allow inf in the arrays.

  • allow_nan – if True, allow Nans in the arrays.

  • exclude_min – if True, exclude the minimum limit.

  • exclude_max – if True, exclude the maximum limit.

  • min_num_dims – minimum size of the shape tuple.

  • max_num_dims – maximum size of the shape tuple.

  • min_dim_size – minimum value of each integer in the shape tuple.

  • max_dim_size – maximum value of each integer in the shape tuple.

  • shape – shape of the arrays in the list.

  • shared_dtype – if True, if dtype is None, a single shared dtype is drawn for all arrays.

  • ret_shape – if True, the shape of the arrays is also returned.

  • dtype – A list of data types for the given arrays.

  • array_api_dtypes – if True, use data types that can be promoted with the array_api_promotion table.

Return type:

SearchStrategy

Returns:

ret – A strategy that draws a tuple of a list of dtypes and a list of their respective arrays.

Examples

>>> dtype_and_values(
...     num_arrays=3,
... )
(['uint16', 'float16', 'uint16'], [array([37915, 6322, 26765, 12413,
    26986, 34665], dtype=uint16), array([-5.000e-01, -5.000e-01,
    -2.000e+00, -6.711e-05, -1.100e+00, -5.955e+04], dtype=float16),
    array([40817, 56193, 29200, 0, 5851, 9746], dtype=uint16)])
>>> dtype_and_values(
...     num_arrays=3,
... )
(['bool', 'uint32', 'bool'], [array(False), array(0, dtype=uint32),
    array(False)])
>>> dtype_and_values(
...     num_arrays=3,
... )
(['int8', 'int8', 'int8'], [array(0, dtype=int8), array(0, dtype=int8),
    array(0, dtype=int8)])
>>> dtype_and_values(
...     available_dtypes=get_dtypes("numeric"),
...     min_value=-10,
...     max_value=10,
...     num_arrays=2,
...     shared_dtype=True,
... ),
(['float32', 'float32'], [array([1.1, 1.5], dtype=float32),
    array([-5.9604645e-08, 5.9604645e-08], dtype=float32)])
>>> dtype_and_values(
...     available_dtypes=get_dtypes("numeric"),
...     min_value=-10,
...     max_value=10,
...     num_arrays=2,
...     shared_dtype=True,
... ),
(['int32', 'int32'], [array(-5, dtype=int32), array(-1, dtype=int32)])
>>> dtype_and_values(
...     available_dtypes=get_dtypes("numeric"),
...     min_value=-10,
...     max_value=10,
...     num_arrays=2,
...     shared_dtype=True,
... ),
(['uint64', 'uint64'], [array([0], dtype=uint64), array([0],
    dtype=uint64)])
>>> dtype_and_values(
...     available_dtypes=get_dtypes("numeric"),
...     num_arrays=2,
...     ret_shape=True
... )
(['int8', 'int32'], [array([27], dtype=int8), array([192],
    dtype=int32)], (1,))
>>> dtype_and_values(
...     available_dtypes=get_dtypes("numeric"),
...     num_arrays=2,
...     ret_shape=True
... )
(['int32', 'int16'], [array(0, dtype=int32), array(0,
    dtype=int16)], ())
>>> dtype_and_values(
...     available_dtypes=get_dtypes("numeric"),
...     num_arrays=2,
...     ret_shape=True
... )
(['int32', 'int16'], [array([[-103, 12, -41795, 1170789994,
    44251, 44209, 433075925]], dtype=int32), array([[24791,
    -24691, 24892, 16711, 7696, 972, 15357]], dtype=int16)],
    (1, 7))
>>> dtype_and_values(
...     available_dtypes=get_dtypes("numeric"),
...     num_arrays=1,
...     ret_shape=True,
... )
(['uint8'], [array([0], dtype=uint8)], (1,))
>>> dtype_and_values(
...     available_dtypes=get_dtypes("numeric"),
...     num_arrays=1,
...     ret_shape=True,
... )
(['float32'], [array(-1., dtype=float32)], ())
>>> dtype_and_values(
...     available_dtypes=get_dtypes("numeric"),
...     num_arrays=1,
...     ret_shape=True,
... )
(['int64'], [array(72057594037927936)], ())
ivy_tests.test_ivy.helpers.hypothesis_helpers.array_helpers.dtype_array_index(*, available_dtypes, min_num_dims=1, max_num_dims=3, min_dim_size=1, max_dim_size=10, allow_slices=True, allow_neg_step=True)[source]#
Return type:

SearchStrategy

ivy_tests.test_ivy.helpers.hypothesis_helpers.array_helpers.dtype_values_axis(*, available_dtypes, num_arrays=1, abs_smallest_val=None, min_value=None, max_value=None, large_abs_safety_factor=1.1, small_abs_safety_factor=1.1, safety_factor_scale='linear', allow_inf=False, allow_nan=False, exclude_min=False, exclude_max=False, min_num_dims=0, max_num_dims=5, min_dim_size=1, max_dim_size=10, shape=None, shared_dtype=False, min_axis=None, max_axis=None, valid_axis=False, allow_neg_axes=True, min_axes_size=1, max_axes_size=None, force_int_axis=False, force_tuple_axis=False, ret_shape=False)[source]#

Draws a list of arrays with elements from the given data type, and a random axis of the arrays.

Parameters:
  • draw – special function that draws data randomly (but is reproducible) from a given data-set (ex. list).

  • available_dtypes – if dtype is None, data type is drawn from this list randomly.

  • num_arrays – Number of arrays to be drawn.

  • abs_smallest_val – sets the absolute smallest value to be generated for float data types, this has no effect on integer data types. If none, the default data type absolute smallest value is used.

  • min_value – minimum value of elements in the array.

  • max_value – maximum value of elements in the array.

  • large_abs_safety_factor

    A safety factor of 1 means that all values are included without limitation,

    when a “linear” safety factor scaler is used, a safety factor of 2 means that only 50% of the range is included, a safety factor of 3 means that only 33% of the range is included etc.

    when a “log” safety factor scaler is used, a data type with maximum value of 2^32 and a safety factor of 2 transforms the maximum to 2^16.

  • small_abs_safety_factor

    A safety factor of 1 means that all values are included without limitation, this has no effect on integer data types.

    when a “linear” safety factor scaler is used, a data type with minimum representable number of 0.0001 and a safety factor of 2 transforms the minimum to 0.0002, a safety factor of 3 transforms the minimum to 0.0003 etc.

    when a “log” safety factor scaler is used, a data type with minimum representable number of 0.5 * 2^-16 and a safety factor of 2 transforms the minimum to 0.5 * 2^-8, a safety factor of 3 transforms the minimum to 0.5 * 2^-4

  • safety_factor_scale – The operation to use when calculating the maximum value of the list. Can be “linear” or “log”. Default value = “linear”.

  • allow_inf – if True, allow inf in the array.

  • allow_nan – if True, allow Nans in the arrays.

  • exclude_min – if True, exclude the minimum limit.

  • exclude_max – if True, exclude the maximum limit.

  • min_num_dims – minimum size of the shape tuple.

  • max_num_dims – maximum size of the shape tuple.

  • min_dim_size – minimum value of each integer in the shape tuple.

  • max_dim_size – maximum value of each integer in the shape tuple.

  • valid_axis – if True, a valid axis will be drawn from the array dimensions.

  • allow_neg_axes – if True, returned axes may include negative axes.

  • min_axes_size – minimum size of the axis tuple.

  • max_axes_size – maximum size of the axis tuple.

  • force_tuple_axis – if true, all axis will be returned as a tuple.

  • force_int_axis – if true and only one axis is drawn, the returned axis will be an int.

  • shape – shape of the array. if None, a random shape is drawn.

  • shared_dtype – if True, if dtype is None, a single shared dtype is drawn for all arrays.

  • min_axis – if shape is None, axis is drawn from the range [min_axis, max_axis].

  • max_axis – if shape is None, axis is drawn from the range [min_axis, max_axis].

  • ret_shape – if True, the shape of the arrays is also returned.

Return type:

SearchStrategy

Returns:

ret – A strategy that draws a tuple of a list of dtypes, a list of arrays, and an axis.

Examples

>>> dtype_values_axis()
(['int16'], [array(29788, dtype=int16)])
>>> dtype_values_axis()
(['complex128'], [array(1.62222885e+156-2.68281172e-257j)])
>>> dtype_values_axis()
(['float64'], [array(-1.40129846e-45)])
>>> dtype_values_axis(
...     available_dtypes=get_dtypes("numeric"),
...     num_arrays=2,
... )
(['int8', 'int16'], [array([[0]], dtype=int8), array([[1]], dtype=int16)], 0)
>>> dtype_values_axis(
...     available_dtypes=get_dtypes("numeric"),
...     num_arrays=2,
... )
(['uint16', 'uint16'], [array(0, dtype=uint16), array(0, dtype=uint16)], 0)
>>> dtype_values_axis(
...     available_dtypes=get_dtypes("numeric"),
...     num_arrays=2,
... )
(['float64', 'int16'], [array(-2.44758124e-308), array(0, dtype=int16)], 0)
>>> dtype_values_axis(
...     available_dtypes=get_dtypes("float"),
...     min_num_dims=2,
...     max_num_dims=3,
...     min_dim_size=2,
...     max_dim_size=5,
...     min_axis=-2,
...     max_axis=1,
... )
(['float64'], [array([[1.90000000e+000, 1.63426649e+308],
    [-1.50000000e+000, -1.91931887e+234]])], -1)
>>> dtype_values_axis(
...     available_dtypes=get_dtypes("float"),
...     min_num_dims=2,
...     max_num_dims=3,
...     min_dim_size=2,
...     max_dim_size=5,
...     min_axis=-2,
...     max_axis=1,
... )
(['bfloat16'], [array([[-1.29488e-38, -1.29488e-38],
    [-1.29488e-38, -1.29488e-38]], dtype=bfloat16)], 0)
>>> dtype_values_axis(
...     available_dtypes=get_dtypes("float"),
...     min_num_dims=2,
...     max_num_dims=3,
...     min_dim_size=2,
...     max_dim_size=5,
...     min_axis=-2,
...     max_axis=1,
... )
(['float64'], [array([[-2.44758124e-308, -2.44758124e-308],
    [-2.44758124e-308, -2.44758124e-308]])], 0)
>>> dtype_values_axis(
...     available_dtypes=get_dtypes("numeric"),
...     num_arrays=1,
...     allow_inf=True,
...     allow_nan=True,
... )
(['float64'], [array([inf, -5.14361019e+16, 5.96046448e-08, 1.50000000e+00])], -51)
>>> dtype_values_axis(
...     available_dtypes=get_dtypes("numeric"),
...     num_arrays=1,
...     allow_inf=True,
...     allow_nan=True,
... )
(['int16'], [array(12445, dtype=int16)], 171)
>>> dtype_values_axis(
...     available_dtypes=get_dtypes("numeric"),
...     num_arrays=1,
...     allow_inf=True,
...     allow_nan=True,
... )
(['uint32'], [array([0], dtype=uint32)], 0)
ivy_tests.test_ivy.helpers.hypothesis_helpers.array_helpers.list_of_size(*, x, size)[source]#

Return a list of the given length with elements drawn randomly from x.

Parameters:
  • x – a list to draw elements from.

  • size – length of the list.

Returns:

ret – A strategy that draws a list.

Examples

>>> list_of_size(
...     x=st.sampled_from([-1, 5, 9]),
...     size=4,
... )
[-1, 5, -1, -1]
>>> list_of_size(
...     x=st.sampled_from([-1, 5, 9]),
...     size=4,
... )
[9, -1, -1, -1]
>>> list_of_size(
...     x=st.sampled_from([-1, 5, 9]),
...     size=4,
... )
[9, 9, -1, 9]
>>> list_of_size(
...     x=st.integers(min_value=0, max_value=4),
...     size=10,
... )
[3, 0, 0, 0, 0, 0, 0, 0, 0, 0]
>>> list_of_size(
...     x=st.integers(min_value=0, max_value=4),
...     size=10,
... )
[3, 3, 2, 4, 1, 0, 4, 2, 1, 2]
>>> list_of_size(
...     x=st.integers(min_value=0, max_value=4),
...     size=10,
... )
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
>>> list_of_size(
...     x=st.booleans(),
...     size=3,
... )
[False, False, False]
>>> list_of_size(
...     x=st.booleans(),
...     size=3,
... )
[True, True, False]
>>> list_of_size(
...     x=st.booleans(),
...     size=3,
... )
[False, True, False]
ivy_tests.test_ivy.helpers.hypothesis_helpers.array_helpers.lists(*, x, min_size=None, max_size=None, size_bounds=None)[source]#

Draws a list with a random bounded size from the data-set x.

Parameters:
  • draw – special function that draws data randomly (but is reproducible) from a given data-set (ex. list).

  • x – data-set of elements.

  • min_size – minimum size of the list.

  • max_size – max size of the list.

  • size_bounds – if min_size or max_size is None, draw them randomly from the range [size_bounds[0], size_bounds[1]].

Return type:

SearchStrategy

Returns:

ret – A strategy that draws a list.

Examples

>>> lists(
...     x=st.sampled_from([-1, 5, 9]),
...     min_size=4,
...     max_size=5,
... )
[5, 5, 5, 9, 9]
>>> lists(
...     x=st.sampled_from([-1, 5, 9]),
...     min_size=4,
...     max_size=5,
... )
[5, 9, -1, -1]
>>> lists(
...     x=st.sampled_from([-1, 5, 9]),
...     min_size=4,
...     max_size=5,
... )
[5, 9, 5, 9]
>>> lists(
...     x=st.integers(min_value=0, max_value=4),
...     size_bounds=(9, 10),
... )
[0, 2, 4, 3, 3, 3, 3, 2, 1, 4]
>>> lists(
...     x=st.integers(min_value=0, max_value=4),
...     size_bounds=(9, 10),
... )
[1, 0, 1, 2, 1, 4, 1, 3, 1]
>>> lists(
...     x=st.integers(min_value=0, max_value=4),
...     size_bounds=(9, 10),
... )
[1, 0, 1, 2, 1, 4, 1, 3, 1]
>>> lists(
...     x=st.integers(min_value=0, max_value=4),
...     size_bounds=[9, 10],
... )
[1, 3, 0, 2, 0, 0, 1, 4, 2, 3]
>>> lists(
...     x=st.integers(min_value=0, max_value=4),
...     size_bounds=[9, 10],
... )
[0, 0, 0, 0, 0, 0, 0, 0, 0]
>>> lists(
...     x=st.integers(min_value=0, max_value=4),
...     size_bounds=[9, 10],
... )
[1, 2, 4, 1, 1, 1, 4, 3, 2]
>>> lists(
...     x=st.floats(
...         min_value=1,
...         max_value=3,
...         exclude_max=True,
...     ),
...     min_size=5,
...     max_size=5,
... )
[1.1, 1.0, 1.0, 1.0, 1.0]
>>> lists(
...     x=st.floats(
...         min_value=1,
...         max_value=3,
...         exclude_max=True,
...     ),
...     min_size=5,
...     max_size=5,
... )
[2.00001, 2.00001, 1.0, 2.999999999999999, 1.9394938006792373]
>>> lists(
...     x=st.floats(
...         min_value=1,
...         max_value=3,
...         exclude_max=True,
...     ),
...     min_size=5,
...     max_size=5,
... )
[1.0, 2.00001, 1.0, 2.999999999999999, 1.9394938006792373]
ivy_tests.test_ivy.helpers.hypothesis_helpers.array_helpers.mutually_broadcastable_shapes(num_shapes, *, base_shape=(), min_dims=1, max_dims=4, min_side=1, max_side=4)[source]#
ivy_tests.test_ivy.helpers.hypothesis_helpers.array_helpers.prod(seq)[source]#