Constructing a permutation matrix

You could, of course, use SparseArrays.jl for this.

But representing the linear operator implicitly by the permutation vector is even more efficient. You could wrap it in a matrix-like type with LinearMaps.jl or with a custom AbstractArray type if you wanted to, though you’d need some compelling motivation to go to the trouble.

1 Like