mirror of
https://github.com/gonum/gonum.git
synced 2025-10-24 15:43:07 +08:00
improve performance and decrease memory use
This commit is contained in:
@@ -21,12 +21,16 @@ func CovarianceMatrix(x mat64.Matrix) *mat64.Dense {
|
|||||||
b.Scale(1/float64(r), b)
|
b.Scale(1/float64(r), b)
|
||||||
|
|
||||||
// todo: avoid unneeded memory expansion here.
|
// todo: avoid unneeded memory expansion here.
|
||||||
mu := new(mat64.Dense)
|
mu := b.RowView(0)
|
||||||
mu.Mul(ones(r, 1), b)
|
|
||||||
|
|
||||||
// this could also be done with a clone & row viewer
|
// this could also be done with a clone & row viewer
|
||||||
xc := mat64.DenseCopyOf(x)
|
xc := mat64.DenseCopyOf(x)
|
||||||
xc.Sub(xc, mu)
|
for i := 0; i < r; i++ {
|
||||||
|
rv := xc.RowView(i)
|
||||||
|
for j, mean := range(mu) {
|
||||||
|
rv[j] -= mean
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// todo: avoid matrix copy
|
// todo: avoid matrix copy
|
||||||
xt := new(mat64.Dense)
|
xt := new(mat64.Dense)
|
||||||
|
|||||||
Reference in New Issue
Block a user