Array helpers#
- ivy_tests.test_ivy.helpers.hypothesis_helpers.array_helpers.array_and_broadcastable_shape(dtype)#
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'))#
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 (default:
shared(ints(min_value=1, max_value=4), key='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_helpers_dtype_info_helper(backend, kind_dtype, dtype)[source]#
- ivy_tests.test_ivy.helpers.hypothesis_helpers.array_helpers.array_indices_axis(*, array_dtypes, indices_dtypes=get_dtypes(), 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', 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)#
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 (default:
get_dtypes()
) – list of data type to draw the indices dtype from.abs_smallest_val (default:
None
) – 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 (default:
None
) – minimum value of elements in the array.max_value (default:
None
) – maximum value of elements in the array.large_abs_safety_factor (default:
1.1
) –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 (default:
1.1
) –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 (default:
'linear'
) – The operation to use for the safety factor scaling. Can be “linear” or “log”. Default value = “linear”.disable_random_axis (default:
False
) – axis is randomly generated with hypothesis if False. If True, axis is set to 0 if axis_zero is True, -1 otherwise.axis_zero (default:
False
) – If True, axis is set to zero if disable_random_axis is True.allow_inf (default:
False
) – inf values are allowed to be generated in the values array when True.min_num_dims (default:
1
) – The minimum number of dimensions the arrays can have.max_num_dims (default:
5
) – The maximum number of dimensions the arrays can have.min_dim_size (default:
1
) – The minimum size of the dimensions of the arrays.max_dim_size (default:
10
) – The maximum size of the dimensions of the arrays.indices_same_dims (default:
False
) – Set x and indices dimensions to be the samevalid_bounds (default:
True
) – 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_indices_put_along_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, values=None, values_dtypes=get_dtypes())#
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 (default:
get_dtypes()
) – list of data type to draw the indices dtype from.disable_random_axis (default:
False
) – axis is randomly generated with hypothesis if False. If True, axis is set to 0 if axis_zero is True, -1 otherwise.axis_zero (default:
False
) – If True, axis is set to zero if disable_random_axis is True.allow_inf (default:
False
) – inf values are allowed to be generated in the values array when True.min_num_dims (default:
1
) – The minimum number of dimensions the arrays can have.max_num_dims (default:
5
) – The maximum number of dimensions the arrays can have.min_dim_size (default:
1
) – The minimum size of the dimensions of the arrays.max_dim_size (default:
10
) – The maximum size of the dimensions of the arrays.indices_same_dims (default:
False
) – Set x and indices dimensions to be the samevalid_bounds (default:
True
) – If False, the strategy may produce out-of-bounds indices.values (default:
None
) – Custom values array to use instead of randomly generated values.values_dtypes (Union[None, List[str]]) – A list of dtypes for the values parameter. The function will use the dtypes returned by ‘get_dtypes(“valid”)’.
- 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])) (['bool', 'int64'], array([False, False, False, True, False, False, False, False]), array([0, 0, 2, 4, 0, 0, 0, 1])) (['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)) (['bool', 'uint64'], array([False]), array([0], dtype=uint64)) (['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) (['uint8', 'int64'], array([1], dtype=uint8), array([0]), -1, 0) (['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')#
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 (default:
None
) – 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 (default:
None
) – minimum value of elements in the list.max_value (default:
None
) – maximum value of elements in the list.allow_nan (default:
False
) – if True, allow Nans in the list.allow_subnormal (default:
False
) – if True, allow subnormals in the list.allow_inf (default:
False
) – if True, allow inf in the list.exclude_min (default:
True
) – if True, exclude the minimum limit.exclude_max (default:
True
) – if True, exclude the maximum limit.large_abs_safety_factor (default:
1.1
) –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 (default:
1.1
) –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 (default:
'linear'
) – 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)#
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 (default:
get_dtypes(kind='float')
) – if dtype is None, data type is drawn from this list randomly.allow_none (default:
False
) – if True, one of the dimensions can be Nonemin_num_dims (default:
1
) – The minimum number of dimensions the arrays can have.max_num_dims (default:
5
) – The maximum number of dimensions the arrays can have.min_dim_size (default:
1
) – The minimum size of the dimensions of the arrays.max_dim_size (default:
10
) – The maximum size of the dimensions of the arrays.num (default:
2
) – The number of arrays to be generatedreturn_dtype (default:
False
) – If True, return a tuple of the form (dtype, arrays, axes) instead of (arrays, axes)force_int_axis (default:
False
) – 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, mixed_fn_compos=True, data_format='channel_last', return_data_format=False)#
- Return type:
SearchStrategy
- ivy_tests.test_ivy.helpers.hypothesis_helpers.array_helpers.cond_data_gen_helper()#
- Return type:
SearchStrategy
- ivy_tests.test_ivy.helpers.hypothesis_helpers.array_helpers.create_concatenable_arrays_dtypes(min_num_dims, max_num_dims, min_num_arrays, max_num_arrays, concat_dim, dtypes, common_shape=None)#
Draws a random number of arrays with concatenable or stackable dimensions. Arrays have same number of dimensions, but their shape can differ along a specified dimension (concat_dim). If concat_dim is None, arrays have the same shape. Dtypes of arrays can differ.
- Parameters:
min_num_dims – minimum number of dimensions
max_num_dims – maximum number of dimensions
min_num_arrays – minimum number of arrays
max_num_arrays – maximum number of arrays
concat_dim – dimension along which the shape of arrays can differ, if None all the arrays will have the same shape
dtypes – list of dtypes from which array dtypes will be draws, each array can have different dtype
given_common_shape – if not None, specifies the shape of the arrays (dimension concat_dim can still be modified)
- Return type:
SearchStrategy
- ivy_tests.test_ivy.helpers.hypothesis_helpers.array_helpers.create_nested_input(dimensions, leaf_values)#
- Return type:
SearchStrategy
- 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, shape_key='shape')#
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 (default:
get_dtypes()
) – if dtype is None, data types are drawn from this list randomly.num_arrays (default:
1
) – Number of arrays to be drawn.abs_smallest_val (default:
None
) – 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 (default:
None
) – minimum value of elements in each array.max_value (default:
None
) – maximum value of elements in each array.large_abs_safety_factor (default:
1.1
) –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 (default:
1.1
) –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 (default:
'linear'
) – The operation to use for the safety factor scaling. Can be “linear” or “log”. Default value = “linear”.allow_inf (default:
False
) – if True, allow inf in the arrays.allow_nan (default:
False
) – if True, allow Nans in the arrays.exclude_min (default:
False
) – if True, exclude the minimum limit.exclude_max (default:
False
) – if True, exclude the maximum limit.min_num_dims (default:
0
) – minimum size of the shape tuple.max_num_dims (default:
5
) – maximum size of the shape tuple.min_dim_size (default:
1
) – minimum value of each integer in the shape tuple.max_dim_size (default:
10
) – maximum value of each integer in the shape tuple.shape (default:
None
) – shape of the arrays in the list.shared_dtype (default:
False
) – if True, if dtype is None, a single shared dtype is drawn for all arrays.ret_shape (default:
False
) – if True, the shape of the arrays is also returned.dtype (default:
None
) – A list of data types for the given arrays.array_api_dtypes (default:
False
) – 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_query(*, available_dtypes, min_num_dims=1, max_num_dims=3, min_dim_size=0, max_dim_size=10, allow_mask=True, allow_neg_step=True)#
- Return type:
SearchStrategy
- ivy_tests.test_ivy.helpers.hypothesis_helpers.array_helpers.dtype_array_query_val(*, available_dtypes, min_num_dims=1, max_num_dims=3, min_dim_size=0, max_dim_size=10, allow_mask=True, allow_neg_step=True)#
- 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)#
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 (default:
1
) – Number of arrays to be drawn.abs_smallest_val (default:
None
) – 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 (default:
None
) – minimum value of elements in the array.max_value (default:
None
) – maximum value of elements in the array.large_abs_safety_factor (default:
1.1
) –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 (default:
1.1
) –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 (default:
'linear'
) – The operation to use when calculating the maximum value of the list. Can be “linear” or “log”. Default value = “linear”.allow_inf (default:
False
) – if True, allow inf in the array.allow_nan (default:
False
) – if True, allow Nans in the arrays.exclude_min (default:
False
) – if True, exclude the minimum limit.exclude_max (default:
False
) – if True, exclude the maximum limit.min_num_dims (default:
0
) – minimum size of the shape tuple.max_num_dims (default:
5
) – maximum size of the shape tuple.min_dim_size (default:
1
) – minimum value of each integer in the shape tuple.max_dim_size (default:
10
) – maximum value of each integer in the shape tuple.valid_axis (default:
False
) – if True, a valid axis will be drawn from the array dimensions.allow_neg_axes (default:
True
) – if True, returned axes may include negative axes.min_axes_size (default:
1
) – minimum size of the axis tuple.max_axes_size (default:
None
) – maximum size of the axis tuple.force_tuple_axis (default:
False
) – if true, all axis will be returned as a tuple.force_int_axis (default:
False
) – if true, the returned axis will be an int.shape (default:
None
) – shape of the array. if None, a random shape is drawn.shared_dtype (default:
False
) – if True, if dtype is None, a single shared dtype is drawn for all arrays.min_axis (default:
None
) – if shape is None, axis is drawn from the range [min_axis, max_axis].max_axis (default:
None
) – if shape is None, axis is drawn from the range [min_axis, max_axis].ret_shape (default:
False
) – 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)], 0)
>>> dtype_values_axis() (['complex128'], [array(1.62222885e+156-2.68281172e-257j)], -1)
>>> dtype_values_axis() (['float64'], [array(-1.40129846e-45)], 3)
>>> 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.einsum_helper()#
- Return type:
SearchStrategy
- ivy_tests.test_ivy.helpers.hypothesis_helpers.array_helpers.get_first_solve_batch_matrix(choose_adjoint=False)#
Generate non-singular left hand side of equation system possibly with a single batch dimension at the beginning. Use get_second_solve_batch_matrix to get the right hand side.
- Parameters:
choose_adjoint (default:
False
) – if True, randomly generates boolean value for adjoint output, otherwise this output is False- Return type:
SearchStrategy
- Returns:
- dtype
Data type of the array
- matrix
Generated array
- adjoint
boolean value specifying whether the system should be solved for adjoint of array
- ivy_tests.test_ivy.helpers.hypothesis_helpers.array_helpers.get_first_solve_matrix(adjoint=True)#
- Return type:
SearchStrategy
- ivy_tests.test_ivy.helpers.hypothesis_helpers.array_helpers.get_second_solve_batch_matrix(allow_simplified=True, choose_side=False)#
Generate right hand side of equation system. Possible with a batch dimension and possibly with several columns of values. Use get_first_solve_batch_matrix to generate the left hand side.
- Parameters:
allow_simplified (default:
True
) – if True, a 1D vector with correct length can be returned as the right hand sidechoose_side (default:
False
) – Randomly choose if the system to be solved is AX=B or XA=B, where X is the unknown solution
- Return type:
SearchStrategy
- Returns:
dtype – Data type of the generated array
matrix – Generated array
left – If True, the system is AX=B, otherwise it is XA=B
- ivy_tests.test_ivy.helpers.hypothesis_helpers.array_helpers.get_second_solve_matrix()#
- Return type:
SearchStrategy
- 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)#
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 (default:
None
) – minimum size of the list.max_size (default:
None
) – max size of the list.size_bounds (default:
None
) – 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]#
This should have hopefully given you an overview of the array_helpers submodule, if you have any questions, please feel free to reach out on our discord!