mirror of
https://github.com/gonum/gonum.git
synced 2025-10-23 15:13:31 +08:00
Change Viewer interface to receiver assignment
This commit is contained in:
@@ -201,27 +201,24 @@ func (m *Dense) SetRow(r int, v []float64) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// View returns a view on the receiver.
|
// View returns a view on the receiver.
|
||||||
func (m *Dense) View(i, j, r, c int) Blasser {
|
func (m *Dense) View(i, j, r, c int) {
|
||||||
v := Dense{BlasMatrix{
|
|
||||||
Order: m.mat.Order,
|
|
||||||
Rows: r - i,
|
|
||||||
Cols: c - j,
|
|
||||||
Stride: m.mat.Stride,
|
|
||||||
}}
|
|
||||||
switch m.mat.Order {
|
switch m.mat.Order {
|
||||||
case blas.RowMajor:
|
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:
|
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:
|
default:
|
||||||
panic(ErrIllegalOrder)
|
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) {
|
func (m *Dense) Submatrix(a Matrix, i, j, r, c int) {
|
||||||
// This is probably a bad idea, but for the moment, we do it.
|
// 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) {
|
func (m *Dense) Clone(a Matrix) {
|
||||||
|
@@ -78,11 +78,11 @@ type Copier interface {
|
|||||||
|
|
||||||
// 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 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
|
// 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
|
// the bounds of the matrix View will panic with ErrIndexOutOfRange. View must retain the
|
||||||
// a copy of the submatrix; changes in the elements of the submatrix must be reflected in the
|
// receiver's reference to the original matrix such that changes in the elements of the
|
||||||
// original and vice versa.
|
// submatrix are reflected in the original and vice versa.
|
||||||
type Viewer interface {
|
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,
|
// A Submatrixer can extract a copy of submatrix from a into the receiver, starting at row i,
|
||||||
|
Reference in New Issue
Block a user