def contiguous_regions(mask):
in_region = None<EOL>boundaries = []<EOL>for i, val in enumerate(mask):<EOL><INDENT>if in_region is None and val:<EOL><INDENT>in_region = i<EOL><DEDENT>elif in_region is not None and not val:<EOL><INDENT>boundaries.append((in_region, i))<EOL>in_region = None<EOL><DEDENT><DEDENT>if in_region is not None:<EOL><INDENT>boundaries.append((in_region, i+<NUM_LIT:1>))<EOL><DEDENT>return boundaries<EOL>
return a list of (ind0, ind1) such that mask[ind0:ind1].all() is
True and we cover all such regions

TODO: this is a pure python implementation which probably has a much faster numpy impl