General helpers#
- ivy_tests.test_ivy.helpers.hypothesis_helpers.general_helpers.apply_safety_factor(dtype, *, 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 – the minimum value of the data type.
max_value – the maximum value of the data type.
abs_smallest_val – the absolute smallest representable value of the data type.
large_abs_safety_factor – the safety factor to apply to the maximum value.
small_abs_safety_factor – the safety factor to apply to the minimum value.
safety_factor_scale – 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.embedding_helper()[source]#
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.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)[source]#
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 – boolean; if True, allow negative axes to be drawn
allow_none – boolean; if True, allow None to be drawn
sort_values – boolean; if True, and a tuple of axes is drawn, tuple is sorted in increasing fashion
unique – boolean; if True, and a tuple of axes is drawn, all axes drawn will be unique
min_size – int or hypothesis strategy; if a tuple of axes is drawn, the minimum number of axes drawn
max_size – 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 shape
force_tuple – boolean, if true, all axis will be returned as a tuple. If force_tuple and force_int are true, then an AssertionError is raised
force_int – 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)[source]#
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)[source]#
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)[source]#
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 – if True, allow for the result to be None.
min_num_dims – minimum size of the tuple.
max_num_dims – maximum size of the tuple.
min_dim_size – minimum value of each integer in the tuple.
max_dim_size – 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 –
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)[source]#
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)[source]#
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.x_and_filters(dim=2, transpose=False, depthwise=False)[source]#
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
) – the dimension of the convolution (default:2
)transpose (
bool
) – if True, draw a transpose convolution (default:False
)depthwise – if True, draw a depthwise convolution
- Return type:
SearchStrategy
- Returns:
A strategy that draws a random x and filters for a convolution.