diff --git a/mat64/dense.go b/mat64/dense.go index f4fb60bc..b18e07bc 100644 --- a/mat64/dense.go +++ b/mat64/dense.go @@ -187,6 +187,11 @@ func (m *Dense) Submatrix(a Matrix, i, j, r, c int) { 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) { r, c := a.Dims() m.mat = RawMatrix{ diff --git a/mat64/matrix.go b/mat64/matrix.go index d5e68c7f..5810fd98 100644 --- a/mat64/matrix.go +++ b/mat64/matrix.go @@ -81,6 +81,13 @@ type Cloner interface { 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 // 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.