Use PermutationMatrix instead of indices #475
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The sparse Gaussian process implementations used to store a vector of indices which represented a permutation matrix. The reason it did this was that the
PermutationMatrix
isn't directly serializable, so you end up needing to copy the indices when you deserialize one of these models. Storing the matrices this way led to a number of places with homegrown permutation matrix application, you'd see things like:These loops are not easy to interpret. In this case it's computing
lhs = rhs * P.transpose()
, but the transpose is not evident from the code. It's also really easy to introduce a bug in these situations (if therhs
isn't the same shape as howlhs
was allocated you can encounter some really tricky memory handling errors).This PR adds a serialization method for a raw
PermutationMatrix<>
and changes that to be the type stored in sparse GP fits. While perhaps slightly less efficient in the few situations where we now need to copy indices, that should only really matter when the size of the indices is huge, in which case these copy operations will probably be dwarfed by large linear algebra operations.