Permuting the rows of a matrix based on given a given permutation