mirror of
https://github.com/gonum/gonum.git
synced 2025-10-06 23:52:47 +08:00
mat: Add Zero method to reset values of matrices (#819)
* mat: Add Zero method to reset values of matrices
This commit is contained in:
@@ -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 {
|
||||
|
Reference in New Issue
Block a user