Dtype helpers#

ivy_tests.test_ivy.helpers.hypothesis_helpers.dtype_helpers.array_dtypes(*, num_arrays=shared(ints(min_value=1, max_value=4), key='num_arrays'), available_dtypes=get_dtypes(), shared_dtype=False, array_api_dtypes=False)#

Draws a list of data types.

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

  • num_arrays (default: shared(ints(min_value=1, max_value=4), key='num_arrays')) – number of data types to be drawn.

  • available_dtypes (default: get_dtypes()) – universe of available data types.

  • shared_dtype (default: False) – if True, all data types in the list are same.

  • array_api_dtypes (default: False) – if True, use data types that can be promoted with the array_api_promotion table.

Return type:

SearchStrategy

Returns:

A strategy that draws a list of data types.

Examples

>>> array_dtypes(
...     available_dtypes=get_dtypes("numeric"),
...     shared_dtype=True,
... )
['float64']
>>> array_dtypes(
...     available_dtypes=get_dtypes("numeric"),
...     shared_dtype=True,
... )
['int8', 'int8']
>>> array_dtypes(
...     available_dtypes=get_dtypes("numeric"),
...     shared_dtype=True,
... )
['int32', 'int32', 'int32', 'int32']
>>> array_dtypes(
...     num_arrays=5,
...     available_dtypes=get_dtypes("valid"),
...     shared_dtype=False,
... )
['int8', 'float64', 'complex64', 'int8', 'bool']
>>> array_dtypes(
...     num_arrays=5,
...     available_dtypes=get_dtypes("valid"),
...     shared_dtype=False,
... )
['bool', 'complex64', 'bool', 'complex64', 'bool']
>>> array_dtypes(
...     num_arrays=5,
...     available_dtypes=get_dtypes("valid"),
...     shared_dtype=False,
... )
['float64', 'int8', 'float64', 'int8', 'float64']
ivy_tests.test_ivy.helpers.hypothesis_helpers.dtype_helpers.cast_filter(d, dtype, x)[source]#
ivy_tests.test_ivy.helpers.hypothesis_helpers.dtype_helpers.cast_filter_helper(d, dtype, x, current_backend)[source]#
ivy_tests.test_ivy.helpers.hypothesis_helpers.dtype_helpers.get_castable_dtype(available_dtypes, dtype, x=None)#

Draws castable dtypes for the given dtype based on the current backend.

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

  • available_dtypes – Castable data types are drawn from this list randomly.

  • dtype (str) – Data type from which to cast.

  • x (Optional[list], default: None) – Optional list of values to cast.

Return type:

SearchStrategy

Returns:

ret – A tuple of inputs and castable dtype.

ivy_tests.test_ivy.helpers.hypothesis_helpers.dtype_helpers.get_dtypes(kind='valid', index=0, mixed_fn_compos=True, full=True, none=False, key=None, prune_function=True)#

Draws a valid dtypes for the test function. For frontend tests, it draws the data types from the intersection between backend framework data types and frontend framework dtypes, otherwise, draws it from backend framework data types.

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

  • kind (default: 'valid') – Supported types are integer, float, valid, numeric, signed_integer, complex, real_and_complex, float_and_complex, bool, and unsigned

  • index (default: 0) – list indexing in case a test needs to be skipped for a particular dtype(s)

  • mixed_fn_compos (default: True) – boolean if True, the function will return the dtypes of the compositional implementation for mixed partial functions and if False, it will return the dtypes of the primary implementation.

  • full (default: True) – returns the complete list of valid types

  • none (default: False) – allow none in the list of valid types

  • key (default: None) – if provided, a shared value will be drawn from the strategy and passed to the function as the keyword argument with the given name.

  • prune_function (default: True) – if True, the function will prune the data types to only include the ones that are supported by the current function. If False, the function will return all the data types supported by the current backend.

Return type:

SearchStrategy

Returns:

ret – A strategy that draws dtype strings

Examples

>>> get_dtypes()
['float16',
    'uint8',
    'complex128',
    'bool',
    'uint32',
    'float64',
    'int8',
    'int16',
    'complex64',
    'float32',
    'int32',
    'uint16',
    'int64',
    'uint64']
>>> get_dtypes(kind='valid', full=False)
['int16']
>>> get_dtypes(kind='valid', full=False)
['uint16']
>>> get_dtypes(kind='numeric', full=False)
['complex64']
>>> get_dtypes(kind='float', full=False, key="leaky_relu")
['float16']
>>> get_dtypes(kind='float', full=False, key="searchsorted")
['bfloat16']
>>> get_dtypes(kind='float', full=False, key="dtype")
['float32']
>>> get_dtypes("numeric", prune_function=False)
['int16']
>>> get_dtypes("valid", prune_function=False)
['uint32']
>>> get_dtypes("valid", prune_function=False)
['complex128']
>>> get_dtypes("valid", prune_function=False)
['bool']
>>> get_dtypes("valid", prune_function=False)
['float16']