Harmonise View signature with the rest of the API

This commit is contained in:
kortschak
2014-01-20 20:45:18 +10:30
parent 5a12150bde
commit 1a85feca5c
5 changed files with 18 additions and 19 deletions

View File

@@ -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)
}

View File

@@ -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,

View File

@@ -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)

View File

@@ -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,

View File

@@ -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
}