mat: Add Zero method to reset values of matrices (#819)

* mat: Add Zero method to reset values of matrices
This commit is contained in:
Brendan Tracey
2019-01-27 22:16:06 +00:00
committed by GitHub
parent 38017c6036
commit bcbf6c8e4e
16 changed files with 388 additions and 0 deletions

View File

@@ -230,6 +230,19 @@ func (t *TriDense) Reset() {
t.mat.Data = t.mat.Data[:0]
}
// Zero sets all of the matrix elements to zero.
func (t *TriDense) Zero() {
if t.isUpper() {
for i := 0; i < t.mat.N; i++ {
zero(t.mat.Data[i*t.mat.Stride+i : i*t.mat.Stride+t.mat.N])
}
return
}
for i := 0; i < t.mat.N; i++ {
zero(t.mat.Data[i*t.mat.Stride : i*t.mat.Stride+i+1])
}
}
// IsZero returns whether the receiver is zero-sized. Zero-sized matrices can be the
// receiver for size-restricted operations. TriDense matrices can be zeroed using Reset.
func (t *TriDense) IsZero() bool {