[impl] count_neighbor_matrix as intermediate