Fix Covmat to use RawRowView

This commit is contained in:
btracey
2015-01-15 17:25:25 -08:00
parent 2f1e198977
commit bc03fc2360
2 changed files with 4 additions and 4 deletions

View File

@@ -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)
}

View File

@@ -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) }) {