# Implicit, full-rank Q (Householder QR)

I am interested in capturing both the column span and null space of a N\times K dense matrix X for large N where the values of X depend on some scalar parameter(s) (for example, X contains the scaled-eigenfunctions of a particular kernel with unknown length). The most efficient way I can think to do this is using an implicit Householder decomposition such that Q = I - UT^{-1}U^T, which is the compact UT transform that accumulates the vectors U for efficient multiplication. The decomposition and an equivalent product are implemented in Eigen by the HouseholderQ class, but I’m not sure if/how I could use this object in Stan. From what I can gather, you can only call external C++ code from Stan if the function signatures match what would be produced by a native Stan function. Is this correct? Once I have U, the product is fairly straight-forward to implement, but I’m not very familiar with C++. Would I be better off just implementing it all in Stan?

Hi,
the code for qr_Q in Stan (https://github.com/stan-dev/math/blob/47b0595203bd9df718940baedac19c48d4179af4/stan/math/prim/fun/qr_Q.hpp) actually calls Eigen::HouseholderQR so you might be able to alter this C++ code to use in your project (it should have the correct signature, except for the final , std::ostream *msgs argument.

Otherwise, implementing in Stan should also work, but is likely more work.

Best of luck with your model!