mirror of
https://github.com/gonum/gonum.git
synced 2025-11-03 11:21:14 +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:
@@ -195,3 +195,38 @@ func TestSymBandDiagView(t *testing.T) {
|
||||
testDiagView(t, cas, test)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSymBandDenseZero(t *testing.T) {
|
||||
// Elements that equal 1 should be set to zero, elements that equal -1
|
||||
// should remain unchanged.
|
||||
for _, test := range []*SymBandDense{
|
||||
&SymBandDense{
|
||||
mat: blas64.SymmetricBand{
|
||||
Uplo: blas.Upper,
|
||||
N: 6,
|
||||
K: 2,
|
||||
Stride: 5,
|
||||
Data: []float64{
|
||||
1, 1, 1, -1, -1,
|
||||
1, 1, 1, -1, -1,
|
||||
1, 1, 1, -1, -1,
|
||||
1, 1, 1, -1, -1,
|
||||
1, 1, -1, -1, -1,
|
||||
1, -1, -1, -1, -1,
|
||||
},
|
||||
},
|
||||
},
|
||||
} {
|
||||
dataCopy := make([]float64, len(test.mat.Data))
|
||||
copy(dataCopy, test.mat.Data)
|
||||
test.Zero()
|
||||
for i, v := range test.mat.Data {
|
||||
if dataCopy[i] != -1 && v != 0 {
|
||||
t.Errorf("Matrix not zeroed in bounds")
|
||||
}
|
||||
if dataCopy[i] == -1 && v != -1 {
|
||||
t.Errorf("Matrix zeroed out of bounds")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user