Skip to content
This repository was archived by the owner on Nov 23, 2018. It is now read-only.

Commit e7f0b38

Browse files
committed
Merge pull request #120 from gonum/fixnewton
Fix newton with new Cholesky API
2 parents ab5276d + f878868 commit e7f0b38

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

newton.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ type Newton struct {
5050
ls *LinesearchMethod
5151

5252
hess *mat64.SymDense // Storage for a copy of the Hessian matrix.
53-
chol *mat64.TriDense // Storage for the Cholesky factorization.
53+
chol *mat64.Cholesky // Storage for the Cholesky factorization.
5454
tau float64
5555
}
5656

@@ -79,7 +79,9 @@ func (n *Newton) Iterate(loc *Location, xNext []float64) (EvaluationType, Iterat
7979

8080
func (n *Newton) InitDirection(loc *Location, dir []float64) (stepSize float64) {
8181
dim := len(loc.X)
82-
n.chol = resizeTriDense(n.chol, dim)
82+
if n.chol == nil {
83+
n.chol = &mat64.Cholesky{}
84+
}
8385
n.hess = resizeSymDense(n.hess, dim)
8486
n.tau = 0
8587
return n.NextDirection(loc, dir)
@@ -119,7 +121,7 @@ func (n *Newton) NextDirection(loc *Location, dir []float64) (stepSize float64)
119121
}
120122
}
121123
// Try to apply the Cholesky factorization.
122-
pd := n.chol.Cholesky(n.hess, true)
124+
pd := n.chol.Factorize(n.hess)
123125
if pd {
124126
d := mat64.NewVector(dim, dir)
125127
// Store the solution in d's backing array, dir.

types.go

-7
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,3 @@ func resizeSymDense(m *mat64.SymDense, dim int) *mat64.SymDense {
234234
}
235235
return mat64.NewSymDense(dim, m.RawSymmetric().Data[:dim*dim])
236236
}
237-
238-
func resizeTriDense(m *mat64.TriDense, dim int) *mat64.TriDense {
239-
if m == nil || cap(m.RawTriangular().Data) < dim*dim {
240-
return mat64.NewTriDense(dim, true, nil)
241-
}
242-
return mat64.NewTriDense(dim, true, m.RawTriangular().Data[:dim*dim])
243-
}

0 commit comments

Comments
 (0)