mirror of
https://github.com/gonum/gonum.git
synced 2025-10-09 09:00:38 +08:00

This is an API breaking change. NewDense now panics if len(mat) != r*c, unless mat == nil. When mat is nil a new, correctly sized slice is allocated.
42 lines
736 B
Go
42 lines
736 B
Go
// Copyright ©2013 The gonum Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package mat64
|
|
|
|
import (
|
|
check "launchpad.net/gocheck"
|
|
)
|
|
|
|
func (s *S) TestCholesky(c *check.C) {
|
|
for _, t := range []struct {
|
|
a *Dense
|
|
spd bool
|
|
}{
|
|
{
|
|
a: NewDense(3, 3, []float64{
|
|
4, 1, 1,
|
|
1, 2, 3,
|
|
1, 3, 6,
|
|
}),
|
|
|
|
spd: true,
|
|
},
|
|
} {
|
|
cf := Cholesky(t.a)
|
|
c.Check(cf.SPD, check.Equals, t.spd)
|
|
|
|
lt := &Dense{}
|
|
lt.TCopy(cf.L)
|
|
lc := DenseCopyOf(cf.L)
|
|
|
|
lc.Mul(lc, lt)
|
|
c.Check(lc.EqualsApprox(t.a, 1e-12), check.Equals, true)
|
|
|
|
x := cf.Solve(eye())
|
|
|
|
t.a.Mul(t.a, x)
|
|
c.Check(t.a.EqualsApprox(eye(), 1e-12), check.Equals, true)
|
|
}
|
|
}
|