torch_ecg.utils.validate_interval

torch_ecg.utils.validate_interval(interval: Sequence[Real] | list | Sequence[Sequence[Real] | list], join_book_endeds: bool = True) Tuple[bool, Sequence[Real] | list | Sequence[Sequence[Real] | list]][source]

Check whether interval is an Interval or a GeneralizedInterval.

If true, return True, and validated (of the form [a, b] with a <= b) interval, return False, [] otherwise.

NOTE: if interval is empty, return False, [].

Parameters:
  • interval (Interval or GeneralizedInterval) – The interval to be validated.

  • join_book_endeds (bool, default True) – If True, two book-ended intervals will be joined into one.

Returns:

2-tuple consisting of

  • bool: indicating whether interval is a valid interval

  • an interval (can be empty)

Return type:

tuple

Examples

>>> validate_interval([1, 2, 3])
(False, [])
>>> validate_interval([2, 1])
(True, [1, 2])
>>> validate_interval([[1, 4], [4, 8]])
(True, [[1, 8]])
>>> validate_interval([[1, 4], [4, 8]], join_book_endeds=False)
(True, [[1, 4], [4, 8]])
>>> validate_interval([])
(False, [])