pyepri.checks

Generic functions for validity checks

Functions

_check_(test, **kwargs)

Apply generic assert test to all input keywords arguments excepting to None occurences.

_check_same_dtype_(**kwargs)

Check whether or not all non None keyword parameters have same array data type.

_check_type_(t, **kwargs)

Check whether or not all non None keyword parameters are instances of the specified type.

_check_dtype_(dtype, **kwargs)

Check whether or not all non None keyword parameters have the specified array data type.

_check_ndim_(ndim, **kwargs)

Check whether or not all non None keyword parameters have the specified number of array dimensions.

_check_backend_(backend, **kwargs)

Check whether or not all non None keyword parameters array belongs to the same library (torch, numpy, cupy).

_check_seq_([t, dtype, n, ndim])

Perform consistency checks for sequence kwargs.

_check_seq_of_seq_([t, dtype, len0, len1, len2, ndim, ...])

Perform consistency checks for sequence of sequence kwargs.

_max_len_(**kwargs)

Compute max length of all sequence elements in kwargs (return None if no element in kwargs is a sequence).

_backend_inference_(**kwargs)

Return a backend inferred from a sequence of array_like inputs.

Module Contents

pyepri.checks._check_(test, **kwargs)[source]

Apply generic assert test to all input keywords arguments excepting to None occurences.

Parameters:
  • test (<class 'function'>) – generic test that will be applied to all non None values in kwargs, return type must be bool.

  • **kwargs (keywords arguments) –

    Input keyword arguments to be tested.

    Each keyword value must be either None or an array_like (this will not be tested).

Returns:

ko – A tuple containing the elements key in kwargs.keys() such that kwargs['key'] is not None and test(kwargs['key']) is False.

Return type:

tuple

Note

The compatibility between the non None elements of kwargs.values() and the provided test function is not verified by this function.

pyepri.checks._check_same_dtype_(**kwargs)[source]

Check whether or not all non None keyword parameters have same array data type.

Parameters:

**kwargs (keyword arguments) –

Input keyword arguments to be tested.

Each keyword value must be either None or an array_like (this will not be tested).

Returns:

no_error_flag – True if the test is successful (otherwise an exception is raised).

Return type:

bool

pyepri.checks._check_type_(t, **kwargs)[source]

Check whether or not all non None keyword parameters are instances of the specified type.

Parameters:
  • t (<class 'type'>) – The specified array data type

  • **kwargs (keyword arguments) – Input keyword arguments to be tested.

Returns:

no_error_flag – True if the test is successful (otherwise an exception is raised).

Return type:

bool

pyepri.checks._check_dtype_(dtype, **kwargs)[source]

Check whether or not all non None keyword parameters have the specified array data type.

Parameters:
  • dtype (<class 'type'> or <class 'torch.type'>) – The specified array data type

  • **kwargs (keyword arguments) –

    Input keyword arguments to be tested.

    Each keyword value must be either None or an array_like (this will not be tested).

Returns:

no_error_flag – True if the test is successful (otherwise an exception is raised).

Return type:

bool

pyepri.checks._check_ndim_(ndim, **kwargs)[source]

Check whether or not all non None keyword parameters have the specified number of array dimensions.

Parameters:
  • ndim (int) – The specified number of array dimensions.

  • **kwargs (keyword arguments) –

    Input keyword arguments to be tested.

    Each keyword value must be either None or an array_like (this will not be tested).

Returns:

no_error_flag – True if the test is successful (otherwise an exception is raised).

Return type:

bool

pyepri.checks._check_backend_(backend, **kwargs)[source]

Check whether or not all non None keyword parameters array belongs to the same library (torch, numpy, cupy).

Parameters:
  • backend (<class 'pyepri.backends.Backend'>) – A numpy, cupy or torch backend instance.

  • **kwargs (keyword arguments) –

    Input keyword arguments to be tested.

    Each keyword value must be either None or an array_like (this will not be tested).

Returns:

no_error_flag – True if the test is successful (otherwise an exception is raised).

Return type:

bool

pyepri.checks._check_seq_(t=None, dtype=None, n=None, ndim=None, **kwargs)[source]

Perform consistency checks for sequence kwargs.

Parameters:
  • t (<class 'type'>, optional) – if given, check that each non None item in kwargs is a sequence of elements with type t.

  • dtype (<class 'type'> or <class 'torch.type'>, optional) – if given, check that each non None item in kwargs is a sequence of array_like with datatype dtype.

  • n (int, optional) – if given, check that each non None item in kwargs is a sequence with length n.

  • ndim (int, optional) – if given, each non None item in kwargs is assumed to be an array_like and we check that those array_like elements have a number of dimensions equal to ndim.

Returns:

no_error_flag – True if the test is successful (otherwise an exception is raised).

Return type:

bool

pyepri.checks._check_seq_of_seq_(t=None, dtype=None, len0=None, len1=None, len2=None, ndim=None, tlen0=None, **kwargs)[source]

Perform consistency checks for sequence of sequence kwargs.

Parameters:
  • t (<class 'type'>, optional) – if given, check that each non None item in kwargs is a sequence of sequence(s) of elements with type t.

  • dtype (<class 'type'> or <class 'torch.type'>, optional) – if given, check that each non None item in kwargs is a sequence of sequence(s) of array_like with datatype dtype.

  • len0 (int, optional) – if given, check that each non None item in kwargs has length len0.

  • len1 (int, optional) – if given, check that each non None item in kwargs is a sequence made of sequence(s) with length len1.

  • len2 (int, optional) – if given, check that each non None leaf in kwargs has length len2.

  • tlen0 (sequence of int, optional) – if given, check that each non None item in kwargs has length in tlen0.

  • ndim (int, optional) – if given, check that each non None leaf in kwargs has a number of dimensions equal to ndim.

Returns:

no_error_flag – True if the test is successful (otherwise an exception is raised).

Return type:

bool

pyepri.checks._max_len_(**kwargs)[source]

Compute max length of all sequence elements in kwargs (return None if no element in kwargs is a sequence).

pyepri.checks._backend_inference_(**kwargs)[source]

Return a backend inferred from a sequence of array_like inputs.