From 61aa81a28fef7a23002b2c3fd9ed2bc2f5b508c9 Mon Sep 17 00:00:00 2001 From: kortschak Date: Thu, 16 Jan 2014 14:24:45 +1030 Subject: [PATCH] Reduce cost of row operations in QR It is not obvious how to get similar optimisations into the Q'B operation without allocation, so I'm leaving that. --- mat64/qr.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/mat64/qr.go b/mat64/qr.go index bf330ba7..b235015b 100644 --- a/mat64/qr.go +++ b/mat64/qr.go @@ -169,12 +169,14 @@ func (f QRFactor) Solve(b *Dense) (x *Dense) { // Solve R*X = Y; for k := n - 1; k >= 0; k-- { - for j := 0; j < bn; j++ { - b.Set(k, j, b.At(k, j)/rDiag[k]) + row := b.rowView(k) + for j := range row[:bn] { + row[j] /= rDiag[k] } for i := 0; i < k; i++ { - for j := 0; j < bn; j++ { - b.Set(i, j, b.At(i, j)-b.At(k, j)*qr.At(i, k)) + row := b.rowView(i) + for j := range row[:bn] { + row[j] -= b.At(k, j) * qr.At(i, k) } } }