General helpers#
- exception ivy_tests.test_ivy.helpers.hypothesis_helpers.general_helpers.BroadcastError[source]#
Bases:
ValueError
Shapes do not broadcast with each other.
- ivy_tests.test_ivy.helpers.hypothesis_helpers.general_helpers.apply_safety_factor(dtype, *, backend, min_value=None, max_value=None, abs_smallest_val=None, small_abs_safety_factor=1.1, large_abs_safety_factor=1.1, safety_factor_scale='linear')[source]#
Apply safety factor scaling to numeric data type.
- Parameters:
dtype – the data type to apply safety factor scaling to.
min_value (default:
None
) – the minimum value of the data type.max_value (default:
None
) – the maximum value of the data type.abs_smallest_val (default:
None
) – the absolute smallest representable value of the data type.large_abs_safety_factor (default:
1.1
) – the safety factor to apply to the maximum value.small_abs_safety_factor (default:
1.1
) – the safety factor to apply to the minimum value.safety_factor_scale (default:
'linear'
) – the scale to apply the safety factor to, either ‘linear’ or ‘log’.
- Returns:
A tuple of the minimum value, maximum value and absolute smallest representable
- ivy_tests.test_ivy.helpers.hypothesis_helpers.general_helpers.dims_and_offset(shape, ensure_dim_unique=False)#
- Return type:
SearchStrategy
- ivy_tests.test_ivy.helpers.hypothesis_helpers.general_helpers.embedding_helper(mixed_fn_compos=True)#
Obtain weights for embeddings, the corresponding indices, the padding indices.
- Parameters:
draw – special function that draws data randomly (but is reproducible) from a given data-set (ex. list).
- Return type:
SearchStrategy
- Returns:
A strategy for generating a tuple
- ivy_tests.test_ivy.helpers.hypothesis_helpers.general_helpers.general_helpers_dtype_info_helper(backend, kind_dtype, dtype)[source]#
- ivy_tests.test_ivy.helpers.hypothesis_helpers.general_helpers.get_axis(*, shape, allow_neg=True, allow_none=False, sort_values=True, unique=True, min_size=1, max_size=None, force_tuple=False, force_int=False)#
Draws one or more axis for the given shape.
- Parameters:
draw – special function that draws data randomly (but is reproducible) from a given data-set (ex. list).
shape – shape of the array as a tuple, or a hypothesis strategy from which the shape will be drawn
allow_neg (default:
True
) – boolean; if True, allow negative axes to be drawnallow_none (default:
False
) – boolean; if True, allow None to be drawnsort_values (default:
True
) – boolean; if True, and a tuple of axes is drawn, tuple is sorted in increasing fashionunique (default:
True
) – boolean; if True, and a tuple of axes is drawn, all axes drawn will be uniquemin_size (default:
1
) – int or hypothesis strategy; if a tuple of axes is drawn, the minimum number of axes drawnmax_size (default:
None
) – int or hypothesis strategy; if a tuple of axes is drawn, the maximum number of axes drawn. If None and unique is True, then it is set to the number of axes in the shapeforce_tuple (default:
False
) – boolean, if true, all axis will be returned as a tuple. If force_tuple and force_int are true, then an AssertionError is raisedforce_int (default:
False
) – boolean, if true, all axis will be returned as an int. If force_tuple and force_int are true, then an AssertionError is raised
- Return type:
SearchStrategy
- Returns:
A strategy that draws an axis or axes.
- ivy_tests.test_ivy.helpers.hypothesis_helpers.general_helpers.get_bounds(*, dtype)#
Draws two numbers; low and high, for a given data type such that low < high.
- Parameters:
draw – special function that draws data randomly (but is reproducible) from a given data-set (ex. list).
dtype – data type.
- Return type:
SearchStrategy
- Returns:
A strategy that draws a list of two numbers.
- ivy_tests.test_ivy.helpers.hypothesis_helpers.general_helpers.get_mean_std(*, dtype)#
Draws two integers representing the mean and standard deviation for 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.
- Return type:
SearchStrategy
- Returns:
A strategy that can be used in the @given hypothesis decorator.
- ivy_tests.test_ivy.helpers.hypothesis_helpers.general_helpers.get_shape(*, allow_none=False, min_num_dims=0, max_num_dims=5, min_dim_size=1, max_dim_size=10)#
Draws a tuple of integers drawn randomly from [min_dim_size, max_dim_size] of size drawn from min_num_dims to max_num_dims. Useful for randomly drawing the shape of an array.
- Parameters:
draw – special function that draws data randomly (but is reproducible) from a given data-set (ex. list).
allow_none (default:
False
) – if True, allow for the result to be None.min_num_dims (default:
0
) – minimum size of the tuple.max_num_dims (default:
5
) – maximum size of the tuple.min_dim_size (default:
1
) – minimum value of each integer in the tuple.max_dim_size (default:
10
) – maximum value of each integer in the tuple.
- Return type:
SearchStrategy
- Returns:
A strategy that draws a tuple.
- ivy_tests.test_ivy.helpers.hypothesis_helpers.general_helpers.matrix_is_stable(x, cond_limit=30)[source]#
Check if a matrix is numerically stable or not.
Used to avoid numerical instabilities in further computationally heavy calculations.
- Parameters:
x – The original matrix whose condition number is to be determined.
cond_limit (default:
30
) –The greater the condition number, the more ill-conditioned the matrix will be, the more it will be prone to numerical instabilities.
There is no rule of thumb for what the exact condition number should be to consider a matrix ill-conditioned(prone to numerical errors). But, if the condition number is “1”, the matrix is perfectly said to be a well-conditioned matrix which will not be prone to any type of numerical instabilities in further calculations, but that would probably be a very simple matrix.
The cond_limit should start with “30”, gradually decreasing it according to our use, lower cond_limit would result in more numerically stable matrices but more simple matrices.
The limit should always be in the range “1-30”, greater the number greater the computational instability. Should not increase 30, it leads to strong multi-collinearity which leads to singularity.
- Returns:
ret – If True, the matrix is suitable for further numerical computations.
- ivy_tests.test_ivy.helpers.hypothesis_helpers.general_helpers.reshape_shapes(*, shape)#
Draws a random shape with the same number of elements as the given shape.
- Parameters:
draw – special function that draws data randomly (but is reproducible) from a given data-set (ex. list).
shape – list/strategy/tuple of integers representing an array shape.
- Return type:
SearchStrategy
- Returns:
A strategy that draws a tuple.
- ivy_tests.test_ivy.helpers.hypothesis_helpers.general_helpers.subsets(*, elements)#
Draws a subset of elements from the given elements.
- Parameters:
draw – special function that draws data randomly (but is reproducible) from a given data-set (ex. list).
elements – set of elements to be drawn from.
- Return type:
SearchStrategy
- Returns:
A strategy that draws a subset of elements.
- ivy_tests.test_ivy.helpers.hypothesis_helpers.general_helpers.two_broadcastable_shapes()#
- Return type:
SearchStrategy
- ivy_tests.test_ivy.helpers.hypothesis_helpers.general_helpers.x_and_filters(dim=2, transpose=False, depthwise=False, mixed_fn_compos=True)#
Draws a random x and filters for a convolution.
- Parameters:
draw – special function that draws data randomly (but is reproducible) from a given data-set (ex. list).
dim (
int
, default:2
) – the dimension of the convolutiontranspose (
bool
, default:False
) – if True, draw a transpose convolutiondepthwise (default:
False
) – if True, draw a depthwise convolution
- Return type:
SearchStrategy
- Returns:
A strategy that draws a random x and filters for a convolution.
This should have hopefully given you an overview of the general_helpers submodule, if you have any questions, please feel free to reach out on our discord!