quemb.molbe.sparse_2el_integral.identify_contiguous_blocks

quemb.molbe.sparse_2el_integral.identify_contiguous_blocks(X)

Identify the indices of contiguous blocks in the sequence X.

A block is defined as a sequence of consecutive integers. Returns a list of tuples, where each tuple contains the start and one-past-the-end indices of a block. This means that the returned tuples can be used in slicing operations.

Parameters:

X (Sequence[TypeVar(_T, int, integer)])

Return type:

list[tuple[int, int]]

Example

>>> X = [1, 2, 3, 5, 6, 7, 9, 10]
>>> blocks = identify_contiguous_blocks(X)
>>> assert blocks  == [(0, 3), (3, 6), (6, 8)]
>>> assert X[blocks[1][0] : blocks[1][1]] == [5, 6, 7]