Number helpers#
- ivy_tests.test_ivy.helpers.hypothesis_helpers.number_helpers.floats(*, min_value=None, max_value=None, abs_smallest_val=None, allow_nan=False, allow_inf=False, allow_subnormal=False, exclude_min=True, exclude_max=True, large_abs_safety_factor=1.1, small_abs_safety_factor=1.1, safety_factor_scale='linear', mixed_fn_compos=True)#
Draws an arbitrarily sized list of floats with a safety factor applied to avoid values being generated at the edge of a dtype limit.
- Parameters:
draw – special function that draws data randomly (but is reproducible) from a given data-set (ex. list).
min_value (default:
None
) – minimum value of floats generated.max_value (default:
None
) – maximum value of floats generated.abs_smallest_val (default:
None
) – the absolute smallest representable value of the data type.allow_nan (default:
False
) – if True, allow Nans in the list.allow_inf (default:
False
) – if True, allow inf in the list.allow_subnormal (default:
False
) – if True, allow subnormals 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,
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”.mixed_fn_compos (default:
True
) – boolean if True, the function will generate using the float dtypes of the compositional implementation for mixed partial functions and if False, it will generate using the float dtypes of the primary implementation.
- Return type:
SearchStrategy
- Returns:
ret – A strategy that draws floats.
- ivy_tests.test_ivy.helpers.hypothesis_helpers.number_helpers.ints(*, min_value=None, max_value=None, safety_factor=1.1, safety_factor_scale=None, mixed_fn_compos=True)#
Draws an integer with a safety factor if specified.
- Parameters:
draw – special function that draws data randomly (but is reproducible) from a given data-set (ex. list).
min_value (default:
None
) – minimum value of integers generated.max_value (default:
None
) – maximum value of integers generated.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.
safety_factor_scale (default:
None
) – The operation to use for the safety factor scaling. Can be “linear” or “log”. Default value = “linear”.mixed_fn_compos (default:
True
) – boolean if True, the function will generate using the integer dtypes of the compositional implementation for mixed partial functions and if False, it will generate using the integer dtypes of the primary implementation.
- Return type:
SearchStrategy
- Returns:
ret – A strategy that draws integers.
- ivy_tests.test_ivy.helpers.hypothesis_helpers.number_helpers.number(*, min_value=None, max_value=None, large_abs_safety_factor=1.1, small_abs_safety_factor=1.1, safety_factor_scale='linear', mixed_fn_compos=True)#
Draws integers or floats with a safety factor applied to values.
- Parameters:
draw – special function that draws data randomly (but is reproducible) from a given data-set (ex. list).
min_value (default:
None
) – minimum value of integers generated.max_value (default:
None
) – maximum value of integers generated.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”.mixed_fn_compos (default:
True
) – boolean if True, the function will generate using the numeric dtypes of the compositional implementation for mixed partial functions and if False, it will generate using the numeric dtypes of the primary implementation.
- Return type:
SearchStrategy
- Returns:
ret – A strategy that draws integers or floats.
This should have hopefully given you an overview of the number_helpers submodule, if you have any questions, please feel free to reach out on our discord!