From 1a85feca5c09667f2fe5c50853f0976e06c490c8 Mon Sep 17 00:00:00 2001 From: kortschak Date: Mon, 20 Jan 2014 20:45:18 +1030 Subject: [PATCH] Harmonise View signature with the rest of the API --- mat64/dense.go | 16 ++++++++-------- mat64/lq.go | 11 +++++------ mat64/lq_test.go | 4 ++-- mat64/matrix.go | 4 ++-- mat64/qr.go | 2 +- 5 files changed, 18 insertions(+), 19 deletions(-) diff --git a/mat64/dense.go b/mat64/dense.go index 0d20eee5..f4fb60bc 100644 --- a/mat64/dense.go +++ b/mat64/dense.go @@ -174,7 +174,8 @@ func (m *Dense) rowView(r int) []float64 { } // View returns a view on the receiver. -func (m *Dense) View(i, j, r, c int) { +func (m *Dense) View(a Matrix, i, j, r, c int) { + *m = *a.(*Dense) m.mat.Data = m.mat.Data[i*m.mat.Stride+j : (i+r-1)*m.mat.Stride+(j+c)] m.mat.Rows = r m.mat.Cols = c @@ -182,9 +183,8 @@ func (m *Dense) View(i, j, r, c int) { func (m *Dense) Submatrix(a Matrix, i, j, r, c int) { // This is probably a bad idea, but for the moment, we do it. - v := *m - v.View(i, j, r, c) - m.Clone(&Dense{v.RawMatrix()}) + m.View(a, i, j, r, c) + m.Clone(m) } func (m *Dense) Clone(a Matrix) { @@ -883,8 +883,8 @@ func (m *Dense) Stack(a, b Matrix) { } m.Copy(a) - w := *m - w.View(ar, 0, br, bc) + var w Dense + w.View(m, ar, 0, br, bc) w.Copy(b) } @@ -908,8 +908,8 @@ func (m *Dense) Augment(a, b Matrix) { } m.Copy(a) - w := *m - w.View(0, ac, br, bc) + var w Dense + w.View(m, 0, ac, br, bc) w.Copy(b) } diff --git a/mat64/lq.go b/mat64/lq.go index 8d051c1d..a1fcd9ce 100644 --- a/mat64/lq.go +++ b/mat64/lq.go @@ -53,8 +53,7 @@ func LQ(a *Dense) LQFactor { // Apply transformation to remaining columns. if k < m-1 { - *a = lq - a.View(k+1, k, m-k-1, n-k) + a.View(&lq, k+1, k, m-k-1, n-k) projs = projs[0 : m-k-1] projs.Mul(a, &hh) @@ -109,10 +108,10 @@ func (f LQFactor) applyQTo(x *Dense, trans bool) { if trans { for k := nh - 1; k >= 0; k-- { - sub := *x hh := f.LQ.RowView(k)[k:] - sub.View(k, 0, m-k, n) + var sub Dense + sub.View(x, k, 0, m-k, n) blasEngine.Dgemv( blas.ColMajor, blas.NoTrans, @@ -128,10 +127,10 @@ func (f LQFactor) applyQTo(x *Dense, trans bool) { } } else { for k := 0; k < nh; k++ { - sub := *x hh := f.LQ.RowView(k)[k:] - sub.View(k, 0, m-k, n) + var sub Dense + sub.View(x, k, 0, m-k, n) blasEngine.Dgemv( blas.ColMajor, blas.NoTrans, diff --git a/mat64/lq_test.go b/mat64/lq_test.go index 5ea113c9..1d7cc812 100644 --- a/mat64/lq_test.go +++ b/mat64/lq_test.go @@ -84,8 +84,8 @@ func (s *S) TestLQD(c *check.C) { l := lq.L() lt := NewDense(rows, cols, nil) - ltview := *lt - ltview.View(0, 0, cols, cols) + var ltview Dense + ltview.View(lt, 0, 0, cols, cols) ltview.TCopy(l) lq.applyQTo(lt, true) diff --git a/mat64/matrix.go b/mat64/matrix.go index 71f102db..d5e68c7f 100644 --- a/mat64/matrix.go +++ b/mat64/matrix.go @@ -88,13 +88,13 @@ type Copier interface { Copy(a Matrix) (r, c int) } -// A Viewer can extract a submatrix view of of the receiver, starting at row i, column j +// A Viewer can extract a submatrix view of the Matrix parameter, starting at row i, column j // and extending r rows and c columns. If i or j are out of range, or r or c extend beyond // the bounds of the matrix View will panic with ErrIndexOutOfRange. View must retain the // receiver's reference to the original matrix such that changes in the elements of the // submatrix are reflected in the original and vice versa. type Viewer interface { - View(i, j, r, c int) + View(a Matrix, i, j, r, c int) } // A Submatrixer can extract a copy of submatrix from a into the receiver, starting at row i, diff --git a/mat64/qr.go b/mat64/qr.go index b235015b..2d1c6277 100644 --- a/mat64/qr.go +++ b/mat64/qr.go @@ -182,7 +182,7 @@ func (f QRFactor) Solve(b *Dense) (x *Dense) { } x = b - x.View(0, 0, n, bn) + x.View(b, 0, 0, n, bn) return x }