fn chunk_index<T: Idx>(elem: T) -> usize