func qr(a *matrix.DenseMatrix) (q, r *matrix.DenseMatrix) { m := a.Rows() n := a.Cols() q = matrix.Eye(m) last := n - 1 if m == n { last-- } for i := 0; i <= last; i++ { // (copy is only for compatibility with an older version of gomatrix) b := a.GetMatrix(i, i, m-i, n-i).Copy() x := b.GetColVector(0) h := matrix.Eye(m) h.SetMatrix(i, i, householder(x)) q, _ = q.TimesDense(h) a, _ = h.TimesDense(a) } return q, a }