Add crossprod, tcrossprod, and quadraticForm functionality #53
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.
This adds some additional functionality for matrix multiplication.
First, it adds
crossprod
andtcrossprod
, which are very similar to R's versions of these functions (https://stat.ethz.ch/R-manual/R-devel/library/base/html/crossprod.html). While there are some cases where this mimics the behavior ofmtimes
, the main reason to use them is because they have specializations for BLAS functions where they are appropriate. Where I include calls tomtimes
it is mainly so that the functions can be used somewhat seamlessly (Note: I left off versions of these functions where the calls are mixed, so for instance,crossprod(a, b)
wherea
is one-dimensional andb
is two-dimensional, usemtimes
in that case).Second, it adds
quadraticForm
andquadraticFormSymmetric
, which implement the call toa' * b * a
whereb
is a general matrix or a symmetric matrix, respectively. This calculation can show up all over the place and can be useful to make it into a function to avoid repeating oneself. I implemented these functions somewhat naively with calls tomtimes
andmtimesSymmetric
without an attempt to avoid allocations.