Change Viewer interface to receiver assignment

This commit is contained in:
kortschak
2013-10-15 14:14:11 +10:30
parent 34da1fe0fb
commit 9184de1c41
2 changed files with 12 additions and 15 deletions

View File

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

View File

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