diff --git a/mat64/dense.go b/mat64/dense.go index 2b1206fe..15661a23 100644 --- a/mat64/dense.go +++ b/mat64/dense.go @@ -201,27 +201,24 @@ func (m *Dense) SetRow(r int, v []float64) int { } // View returns a view on the receiver. -func (m *Dense) View(i, j, r, c int) Blasser { - v := Dense{BlasMatrix{ - Order: m.mat.Order, - Rows: r - i, - Cols: c - j, - Stride: m.mat.Stride, - }} +func (m *Dense) View(i, j, r, c int) { switch m.mat.Order { case blas.RowMajor: - v.mat.Data = m.mat.Data[i*m.mat.Stride+j : (i+r-1)*m.mat.Stride+(j+c)] + m.mat.Data = m.mat.Data[i*m.mat.Stride+j : (i+r-1)*m.mat.Stride+(j+c)] case blas.ColMajor: - v.mat.Data = m.mat.Data[i+j*m.mat.Stride : (i+r)+(j+c-1)*m.mat.Stride] + m.mat.Data = m.mat.Data[i+j*m.mat.Stride : (i+r)+(j+c-1)*m.mat.Stride] default: panic(ErrIllegalOrder) } - return &v + m.mat.Rows = r - i + m.mat.Cols = c - j } func (m *Dense) Submatrix(a Matrix, i, j, r, c int) { // This is probably a bad idea, but for the moment, we do it. - m.Clone(&Dense{m.View(i, j, r, c).BlasMatrix()}) + v := *m + v.View(i, j, r, c) + m.Clone(&Dense{v.BlasMatrix()}) } func (m *Dense) Clone(a Matrix) { diff --git a/mat64/matrix.go b/mat64/matrix.go index 828fb0cb..2b749592 100644 --- a/mat64/matrix.go +++ b/mat64/matrix.go @@ -78,11 +78,11 @@ type Copier interface { // A Viewer can extract a submatrix view of of the receiver, 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. Viewer must not return -// a copy of the submatrix; changes in the elements of the submatrix must be reflected in the -// original and vice versa. +// 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) Blasser + View(i, j, r, c int) } // A Submatrixer can extract a copy of submatrix from a into the receiver, starting at row i,