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

@@ -139,6 +139,51 @@ func TestTriAtSet(t *testing.T) {
}
}
func TestTriDenseZero(t *testing.T) {
// Elements that equal 1 should be set to zero, elements that equal -1
// should remain unchanged.
for _, test := range []*TriDense{
&TriDense{
mat: blas64.Triangular{
Uplo: blas.Upper,
N: 4,
Stride: 5,
Data: []float64{
1, 1, 1, 1, -1,
-1, 1, 1, 1, -1,
-1, -1, 1, 1, -1,
-1, -1, -1, 1, -1,
},
},
},
&TriDense{
mat: blas64.Triangular{
Uplo: blas.Lower,
N: 4,
Stride: 5,
Data: []float64{
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")
}
}
}
}
func TestTriDiagView(t *testing.T) {
for cas, test := range []*TriDense{
NewTriDense(1, Upper, []float64{1}),