pyepri.checks
Generic functions for validity checks
Functions
|
Apply generic assert test to all input keywords arguments excepting to None occurences. |
|
Check whether or not all non None keyword parameters have same array data type. |
|
Check whether or not all non None keyword parameters are instances of the specified type. |
|
Check whether or not all non None keyword parameters have the specified array data type. |
|
Check whether or not all non None keyword parameters have the specified number of array dimensions. |
|
Check whether or not all non None keyword parameters array belongs to the same library (torch, numpy, cupy). |
|
Perform consistency checks for sequence kwargs. |
|
Perform consistency checks for sequence of sequence kwargs. |
|
Compute max length of all sequence elements in kwargs (return None if no element in |
|
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 bebool
.**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 thatkwargs['key'] is not None and test(kwargs['key']) is False
.- Return type:
tuple
Note
The compatibility between the non
None
elements ofkwargs.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 tondim
.
- 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