kaleidicassociates / lubeck

High level linear algebra library for Dlang
http://lubeck.libmir.org/
Boost Software License 1.0
66 stars 14 forks source link

Add crossprod, tcrossprod, and quadraticForm functionality #53

Open jmh530 opened 1 year ago

jmh530 commented 1 year ago

This adds some additional functionality for matrix multiplication.

First, it adds crossprod and tcrossprod, 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 of mtimes, the main reason to use them is because they have specializations for BLAS functions where they are appropriate. Where I include calls to mtimes 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) where a is one-dimensional and b is two-dimensional, use mtimes in that case).

Second, it adds quadraticForm and quadraticFormSymmetric, which implement the call to a' * b * a where b 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 to mtimes and mtimesSymmetric without an attempt to avoid allocations.

jmh530 commented 11 months ago

@9il This is able to be reviewed when you have time.