# Weighted QR Implementation

Say I want a QR decomposition of matrix $$A$$, where orthogonality of $$Q$$ is with respect to a generic non-degenerate positive-definite bilinear form $$\phi$$ (in my case, $$\phi$$ is "defined" by a finite-element mass matrix). This seems like a standard thing one might want to do, so is there a Python implementation out there somewhere (that say, uses Modified Gram-Schmidt with pivoting, or uses Householder Reflections)? My matrix $$A$$ is tall, thin, and dense.

Since the bilinear form is positive definite, you can use a Cholesky decomposition to write $$M = W^T W$$, where $$\phi(x,y) = x^T M y$$. Then compute the QR decomposition of a $$W$$-weighted $$A$$, i.e., $$U R = W A$$, and define $$Q = W^{-1}U$$. You obtain, $$Q^T M Q = U^T W^{-T}W^T W W^{-1} U = I$$, and $$Q R = W^{-1}U R = A$$.