mirror of
https://github.com/gonum/gonum.git
synced 2025-10-29 09:42:38 +08:00
Fix Covmat to use RawRowView
This commit is contained in:
@@ -37,7 +37,7 @@ func CovarianceMatrix(cov *mat64.Dense, x mat64.Matrix, wts []float64) *mat64.De
|
||||
xt.TCopy(x)
|
||||
// Subtract the mean of each of the columns.
|
||||
for i := 0; i < c; i++ {
|
||||
v := xt.RowView(i)
|
||||
v := xt.RawRowView(i)
|
||||
mean := Mean(v, wts)
|
||||
floats.AddConst(-mean, v)
|
||||
}
|
||||
@@ -53,7 +53,7 @@ func CovarianceMatrix(cov *mat64.Dense, x mat64.Matrix, wts []float64) *mat64.De
|
||||
|
||||
// Weight the rows.
|
||||
for i := 0; i < c; i++ {
|
||||
v := xt.RowView(i)
|
||||
v := xt.RawRowView(i)
|
||||
floats.Mul(v, wts)
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ func TestCovarianceMatrix(t *testing.T) {
|
||||
// and Covariance functions and ensure that the results are identical.
|
||||
for i, test := range []struct {
|
||||
data *mat64.Dense
|
||||
weights mat64.Vec
|
||||
weights []float64
|
||||
ans *mat64.Dense
|
||||
}{
|
||||
{
|
||||
@@ -85,7 +85,7 @@ func TestCovarianceMatrix(t *testing.T) {
|
||||
}
|
||||
|
||||
}
|
||||
if !Panics(func() { CovarianceMatrix(nil, mat64.NewDense(5, 2, nil), mat64.Vec([]float64{})) }) {
|
||||
if !Panics(func() { CovarianceMatrix(nil, mat64.NewDense(5, 2, nil), []float64{}) }) {
|
||||
t.Errorf("CovarianceMatrix did not panic with weight size mismatch")
|
||||
}
|
||||
if !Panics(func() { CovarianceMatrix(mat64.NewDense(1, 1, nil), mat64.NewDense(5, 2, nil), nil) }) {
|
||||
|
||||
Reference in New Issue
Block a user