mirror of
https://github.com/gonum/gonum.git
synced 2025-10-09 17:10:16 +08:00
Add Reset method
Reset allows reuse of used matrices, a use that would otherwise be blocked by dim checking for many operations.
This commit is contained in:
@@ -187,6 +187,11 @@ func (m *Dense) Submatrix(a Matrix, i, j, r, c int) {
|
|||||||
m.Clone(m)
|
m.Clone(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *Dense) Reset() {
|
||||||
|
m.mat.Rows, m.mat.Cols = 0, 0
|
||||||
|
m.mat.Data = m.mat.Data[:0]
|
||||||
|
}
|
||||||
|
|
||||||
func (m *Dense) Clone(a Matrix) {
|
func (m *Dense) Clone(a Matrix) {
|
||||||
r, c := a.Dims()
|
r, c := a.Dims()
|
||||||
m.mat = RawMatrix{
|
m.mat = RawMatrix{
|
||||||
|
@@ -81,6 +81,13 @@ type Cloner interface {
|
|||||||
Clone(a Matrix)
|
Clone(a Matrix)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A Reset can zero the dimensions of the matrix so that it can be reused as
|
||||||
|
// the receiver of a dimensionally restricted operation. This is commonly used
|
||||||
|
// when the matrix is being used a a workspace or temporary matrix.
|
||||||
|
type Reseter interface {
|
||||||
|
Reset()
|
||||||
|
}
|
||||||
|
|
||||||
// A Copier can make a copy of elements of a into the receiver. The copy operation fills the
|
// A Copier can make a copy of elements of a into the receiver. The copy operation fills the
|
||||||
// submatrix in m with the values from the submatrix of a with the dimensions equal to the
|
// submatrix in m with the values from the submatrix of a with the dimensions equal to the
|
||||||
// minumum of two matrices. The number of row and columns copied it returned.
|
// minumum of two matrices. The number of row and columns copied it returned.
|
||||||
|
Reference in New Issue
Block a user