mat: rewrite cholesky extractions as To rather than From
MODIFY
mat/cholesky_example_test.go
mat/cholesky_example_test.go
@@ -43,7 +43,7 @@ func ExampleCholesky() {
// Extract the factorization and check that it equals the original matrix.
var t mat.TriDense
- t.LFromCholesky(&chol)
+ chol.LTo(&t)
var test mat.Dense
test.Mul(&t, t.T())
fmt.Println()
@@ -93,7 +93,7 @@ func ExampleCholesky_SymRankOne() {
a.SymRankOne(a, 1, x)
var au mat.SymDense
- au.FromCholesky(&chol)
+ chol.To(&au)
// Print the matrix that was updated directly.
fmt.Printf("\nA' = %0.4v\n", mat.Formatted(a, mat.Prefix(" ")))

MODIFY
mat/cholesky_test.go
mat/cholesky_test.go
@@ -54,7 +54,7 @@ func TestCholesky(t *testing.T) {
t.Errorf("Condition number mismatch: Want %v, got %v", test.cond, chol.cond)
}
var U TriDense
- U.UFromCholesky(chol)
+ chol.UTo(&U)
aCopy := DenseCopyOf(test.a)
var a Dense
a.Mul(U.TTri(), &U)
@@ -63,7 +63,7 @@ func TestCholesky(t *testing.T) {
}
var L TriDense
- L.LFromCholesky(chol)
+ chol.LTo(&L)
a.Mul(&L, L.TTri())
if !EqualApprox(&a, aCopy, 1e-14) {
t.Error("unexpected Cholesky factor product")
@@ -221,7 +221,7 @@ func TestCholeskySolveVec(t *testing.T) {
}
}
-func TestFromCholesky(t *testing.T) {
+func TestCholeskyTo(t *testing.T) {
for _, test := range []*SymDense{
NewSymDense(3, []float64{
53, 59, 37,
@@ -235,7 +235,7 @@ func TestFromCholesky(t *testing.T) {
t.Fatal("unexpected Cholesky factorization failure: not positive definite")
}
var s SymDense
- s.FromCholesky(&chol)
+ chol.To(&s)
if !EqualApprox(&s, test, 1e-12) {
t.Errorf("Cholesky reconstruction not equal to original matrix.\nWant:\n% v\nGot:\n% v\n", Formatted(test), Formatted(&s))
@@ -341,7 +341,7 @@ func TestCholeskySymRankOne(t *testing.T) {
a.SymRankOne(&a, alpha, x)
var achol SymDense
- achol.FromCholesky(&chol)
+ chol.To(&achol)
if !EqualApprox(&achol, &a, 1e-13) {
t.Errorf("n=%v, alpha=%v: mismatch between updated matrix and from Cholesky:\nupdated:\n%v\nfrom Cholesky:\n%v",
n, alpha, Formatted(&a), Formatted(&achol))
@@ -416,7 +416,7 @@ func TestCholeskySymRankOne(t *testing.T) {
a.SymRankOne(a, test.alpha, x)
var achol SymDense
- achol.FromCholesky(&chol)
+ chol.To(&achol)
if !EqualApprox(&achol, a, 1e-13) {
t.Errorf("Case %v: mismatch between updated matrix and from Cholesky:\nupdated:\n%v\nfrom Cholesky:\n%v",
i, Formatted(a), Formatted(&achol))

MODIFY
stat/distmat/wishart.go
stat/distmat/wishart.go
@@ -54,7 +54,7 @@ func NewWishart(v mat.Symmetric, nu float64, src *rand.Rand) (*Wishart, bool) {
}
var u mat.TriDense
- u.UFromCholesky(&chol)
+ chol.UTo(&u)
w := &Wishart{
nu: nu,
@@ -128,7 +128,7 @@ func (w *Wishart) logProbSymChol(cholX *mat.Cholesky) float64 {
// Compute tr(V^-1 * X), using the fact that X = U^T * U.
var u mat.TriDense
- u.UFromCholesky(cholX)
+ cholX.UTo(&u)
var vinvx mat.Dense
err := vinvx.SolveCholesky(&w.cholv, u.T())
@@ -151,7 +151,7 @@ func (w *Wishart) RandSym(x *mat.SymDense) *mat.SymDense {
}
var c mat.Cholesky
w.RandChol(&c)
- x.FromCholesky(&c)
+ c.To(x)
return x
}
@@ -204,6 +204,6 @@ func (w *Wishart) RandChol(c *mat.Cholesky) *mat.Cholesky {
func (w *Wishart) setV() {
w.once.Do(func() {
w.v = mat.NewSymDense(w.dim, nil)
- w.v.FromCholesky(&w.cholv)
+ w.cholv.To(w.v)
})
}

MODIFY
stat/distmv/normal.go
stat/distmv/normal.go
@@ -59,7 +59,7 @@ func NewNormal(mu []float64, sigma mat.Symmetric, src *rand.Rand) (*Normal, bool
}
n.sigma = *mat.NewSymDense(dim, nil)
n.sigma.CopySym(sigma)
- n.lower.LFromCholesky(&n.chol)
+ n.chol.LTo(&n.lower)
n.logSqrtDet = 0.5 * n.chol.LogDet()
return n, true
}
@@ -79,7 +79,7 @@ func NewNormalChol(mu []float64, chol *mat.Cholesky, src *rand.Rand) *Normal {
}
n.chol.Clone(chol)
copy(n.mu, mu)
- n.lower.LFromCholesky(chol)
+ chol.LTo(&n.lower)
n.logSqrtDet = 0.5 * n.chol.LogDet()
return n
}

MODIFY
stat/distmv/normal_test.go
stat/distmv/normal_test.go
@@ -241,7 +241,7 @@ func TestConditionNormal(t *testing.T) {
}
var sigma mat.SymDense
- sigma.FromCholesky(&newNormal.chol)
+ newNormal.chol.To(&sigma)
if !mat.EqualApprox(test.newSigma, &sigma, 1e-12) {
t.Errorf("Updated sigma mismatch\n.Want:\n% v\nGot:\n% v\n", test.newSigma, sigma)
}
@@ -279,7 +279,7 @@ func TestConditionNormal(t *testing.T) {
t.Fatalf("Bad test, update failed")
}
var newSigma mat.SymDense
- newSigma.FromCholesky(&newNormal.chol)
+ newNormal.chol.To(&newSigma)
trueMean := test.mu[0] + rho*(std[0]/std[1])*(test.value-test.mu[1])
if math.Abs(trueMean-newNormal.mu[0]) > 1e-14 {
t.Errorf("Mean mismatch. Want %v, got %v", trueMean, newNormal.mu[0])
@@ -376,7 +376,7 @@ func TestConditionNormal(t *testing.T) {
}
}
var sigma mat.SymDense
- sigma.FromCholesky(&newNormal.chol)
+ newNormal.chol.To(&sigma)
if !mat.EqualApprox(&sigma, subEstCov, 1e-1) {
t.Errorf("Covariance mismatch. Want:\n%0.8v\nGot:\n%0.8v\n", subEstCov, sigma)
}

MODIFY
stat/distmv/studentst.go
stat/distmv/studentst.go
@@ -71,7 +71,7 @@ func NewStudentsT(mu []float64, sigma mat.Symmetric, nu float64, src *rand.Rand)
}
s.sigma = *mat.NewSymDense(dim, nil)
s.sigma.CopySym(sigma)
- s.lower.LFromCholesky(&s.chol)
+ s.chol.LTo(&s.lower)
s.logSqrtDet = 0.5 * s.chol.LogDet()
return s, true
}

mat: rewrite cholesky extractions as To rather than From