Skip to content

Commit 7635b43

Browse files
committed
initialize y and J at LS
1 parent a66e977 commit 7635b43

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

source/mir/optim/least_squares.d

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,8 +446,8 @@ The function `g` is the Jacobian of `f`, and should fill a row-major `m x n` mat
446446
447447
Returns: optimization status.
448448
Params:
449-
f = `n -> m` function
450-
g = `m × n` Jacobian (optional)
449+
f = `n -> m` function, the `y` vector is zero initialized before f is called
450+
g = `m × n` Jacobian (optional), the `J` matrix is zero initialized before g is called
451451
tm = thread manager for finite difference jacobian approximation in case of g is null (optional)
452452
settings = Levenberg-Marquardt data structure
453453
m = length (dimension) of `y = f(x)`
@@ -466,6 +466,7 @@ LeastSquaresResult!T optimizeLeastSquares(alias f, alias g = null, alias tm = nu
466466
{
467467
scope fInst = delegate(Slice!(const(T)*) x, Slice!(T*) y)
468468
{
469+
y[] = 0;
469470
f(x, y);
470471
};
471472
if (false)
@@ -478,6 +479,7 @@ LeastSquaresResult!T optimizeLeastSquares(alias f, alias g = null, alias tm = nu
478479
{
479480
scope gInst = delegate(Slice!(const(T)*) x, Slice!(T*, 2) J)
480481
{
482+
J[] = 0;
481483
g(x, J);
482484
};
483485
static if (isNullableFunction!(g))
@@ -902,7 +904,7 @@ LeastSquaresResult!T optimizeLeastSquaresImplGeneric(T)
902904

903905
debug
904906
{
905-
work[] = 0;
907+
work[] = T.nan;
906908
iwork[] = 0;
907909
}
908910

0 commit comments

Comments
 (0)