diff/fd: fix build

This commit is contained in:
kortschak
2017-07-31 10:57:20 +09:30
committed by Dan Kortschak
parent f99e3efb09
commit cd23ab5b82
2 changed files with 6 additions and 6 deletions

View File

@@ -63,7 +63,7 @@ func TestHessian(t *testing.T) {
2, 5, -3, 2, 5, -3,
1, -3, 6, 1, -3, 6,
}), }),
b: mat.NewVector(3, []float64{3, -2, -1}), b: mat.NewVecDense(3, []float64{3, -2, -1}),
c: 5, c: 5,
}, },
x: []float64{-1.6, -3, 2}, x: []float64{-1.6, -3, 2},

View File

@@ -57,20 +57,20 @@ func (l LinearFunc) Hess(dst mat.MutableSymmetric, x []float64) {
// QuadFunc is a quadratic function returning 0.5*x'*a*x + b*x + c. // QuadFunc is a quadratic function returning 0.5*x'*a*x + b*x + c.
type QuadFunc struct { type QuadFunc struct {
a *mat.SymDense a *mat.SymDense
b *mat.Vector b *mat.VecDense
c float64 c float64
} }
func (q QuadFunc) Func(x []float64) float64 { func (q QuadFunc) Func(x []float64) float64 {
v := mat.NewVector(len(x), x) v := mat.NewVecDense(len(x), x)
var tmp mat.Vector var tmp mat.VecDense
tmp.MulVec(q.a, v) tmp.MulVec(q.a, v)
return 0.5*mat.Dot(&tmp, v) + mat.Dot(q.b, v) + q.c return 0.5*mat.Dot(&tmp, v) + mat.Dot(q.b, v) + q.c
} }
func (q QuadFunc) Grad(grad, x []float64) { func (q QuadFunc) Grad(grad, x []float64) {
var tmp mat.Vector var tmp mat.VecDense
v := mat.NewVector(len(x), x) v := mat.NewVecDense(len(x), x)
tmp.MulVec(q.a, v) tmp.MulVec(q.a, v)
for i := range grad { for i := range grad {
grad[i] = tmp.At(i, 0) + q.b.At(i, 0) grad[i] = tmp.At(i, 0) + q.b.At(i, 0)