torch_ecg.utils.generalized_intervals_intersection

torch_ecg.utils.generalized_intervals_intersection(generalized_interval: Sequence[Sequence[Real] | list] | list, another_generalized_interval: Sequence[Sequence[Real] | list] | list, drop_degenerate: bool = True) Sequence[Sequence[Real] | list] | list[source]

calculate the intersection of intervals.

Parameters:
  • generalized_interval (GeneralizedInterval) – The 2 GeneralizedInterval to yield intersection.

  • another_generalized_interval (GeneralizedInterval) – The 2 GeneralizedInterval to yield intersection.

  • drop_degenerate (bool, default True) – Whether or not drop the degenerate intervals, i.e. intervals with length 0.

Returns:

The intersection of generalized_interval and another_generalized_interval.

Return type:

GeneralizedInterval

Examples

>>> generalized_intervals_intersection([[1, 2], [3, 7]], [[40,90], [-30, -10]])
[]
>>> generalized_intervals_intersection([[1, 5], [12, 33]], [[4, 9], [-3, 3], [33, 99]])
[[1, 3], [4, 5]]
>>> generalized_intervals_intersection([[1, 5], [12, 33]], [[4, 9], [-3, 3], [33, 99]], drop_degenerate=False)
[[1, 3], [4, 5], [33, 33]]