torch_ecg.utils.generalized_intervals_union

torch_ecg.utils.generalized_intervals_union(interval_list: List[Sequence[Sequence[Real] | list] | list] | Tuple[Sequence[Sequence[Real] | list] | list], join_book_endeds: bool = True) Sequence[Sequence[Real] | list] | list[source]

Calculate the union of a list (or tuple) of GeneralizedInterval.

Parameters:
  • interval_list (list or tuple) – A list (or tuple) of GeneralizedInterval.

  • join_book_endeds (bool, default True) – Whether join the book-ended intervals into one (e.g. [[1,2],[2,3]] into [1,3]) or not

Returns:

The union of interval_list.

Return type:

GeneralizedInterval

Examples

>>> generalized_intervals_union(([[1, 2], [3, 7]], [[40,90], [-30, -10]]))
[[-30, -10], [1, 2], [3, 7], [40, 90]]
>>> generalized_intervals_union(([[1, 2], [3, 7]], [[4,9], [-3, 1]]))
[[-3, 2], [3, 9]]
>>> generalized_intervals_union(([[1, 2], [3, 7]], [[4,9], [-3, 1]]), join_book_endeds=False)
[[-3, 1], [1, 2], [3, 9]]