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

Commit 0c9c657

Browse files
committed
optimize: make chol field concrete type
It is always used, so allocate it with the Newton struct.
1 parent e7f0b38 commit 0c9c657

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

newton.go

+2-5
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.Cholesky // Storage for the Cholesky factorization.
53+
chol mat64.Cholesky // Storage for the Cholesky factorization.
5454
tau float64
5555
}
5656

@@ -79,9 +79,6 @@ 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-
if n.chol == nil {
83-
n.chol = &mat64.Cholesky{}
84-
}
8582
n.hess = resizeSymDense(n.hess, dim)
8683
n.tau = 0
8784
return n.NextDirection(loc, dir)
@@ -125,7 +122,7 @@ func (n *Newton) NextDirection(loc *Location, dir []float64) (stepSize float64)
125122
if pd {
126123
d := mat64.NewVector(dim, dir)
127124
// Store the solution in d's backing array, dir.
128-
d.SolveCholeskyVec(n.chol, mat64.NewVector(dim, loc.Gradient))
125+
d.SolveCholeskyVec(&n.chol, mat64.NewVector(dim, loc.Gradient))
129126
floats.Scale(-1, dir)
130127
return 1
131128
}

0 commit comments

Comments
 (0)