Skip to content

Commit

Permalink
initialize y and J at LS
Browse files Browse the repository at this point in the history
  • Loading branch information
9il committed Jan 20, 2025
1 parent a66e977 commit 7635b43
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions source/mir/optim/least_squares.d
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,8 @@ The function `g` is the Jacobian of `f`, and should fill a row-major `m x n` mat
Returns: optimization status.
Params:
f = `n -> m` function
g = `m × n` Jacobian (optional)
f = `n -> m` function, the `y` vector is zero initialized before f is called
g = `m × n` Jacobian (optional), the `J` matrix is zero initialized before g is called
tm = thread manager for finite difference jacobian approximation in case of g is null (optional)
settings = Levenberg-Marquardt data structure
m = length (dimension) of `y = f(x)`
Expand All @@ -466,6 +466,7 @@ LeastSquaresResult!T optimizeLeastSquares(alias f, alias g = null, alias tm = nu
{
scope fInst = delegate(Slice!(const(T)*) x, Slice!(T*) y)
{
y[] = 0;
f(x, y);
};
if (false)
Expand All @@ -478,6 +479,7 @@ LeastSquaresResult!T optimizeLeastSquares(alias f, alias g = null, alias tm = nu
{
scope gInst = delegate(Slice!(const(T)*) x, Slice!(T*, 2) J)
{
J[] = 0;
g(x, J);
};
static if (isNullableFunction!(g))
Expand Down Expand Up @@ -902,7 +904,7 @@ LeastSquaresResult!T optimizeLeastSquaresImplGeneric(T)

debug
{
work[] = 0;
work[] = T.nan;
iwork[] = 0;
}

Expand Down

1 comment on commit 7635b43

@aferust
Copy link

@aferust aferust commented on 7635b43 Jan 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.