Files
gonum/mat64/cholesky_test.go
kortschak b10f3a00f3 Change NewDense signature and behaviour
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.
2014-01-08 09:56:39 +10:30

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