Skip to content

Commit

Permalink
Harmonise View signature with the rest of the API
Browse files Browse the repository at this point in the history
  • Loading branch information
kortschak committed Jan 20, 2014
1 parent 5a12150 commit 1a85fec
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 19 deletions.
16 changes: 8 additions & 8 deletions mat64/dense.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,17 @@ 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
}

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) {
Expand Down Expand Up @@ -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)
}

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

Expand Down
11 changes: 5 additions & 6 deletions mat64/lq.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions mat64/lq_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions mat64/matrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion mat64/qr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 1a85fec

Please sign in to comment.