@@ -171,7 +171,8 @@ function finite_difference_jacobian(
171171 end
172172 vecx = _vec (x)
173173 vecx1 = _vec (x1)
174- J = jac_prototype isa Nothing ? (sparsity isa Nothing ? false .* vecfx.* vecx' : zeros (eltype (x),size (sparsity))) : zero (jac_prototype)
174+ J = jac_prototype isa Nothing ? (sparsity isa Nothing ? Array {eltype(x),2} (undef, length (vecfx), 0 ) : zeros (eltype (x),size (sparsity))) : zero (jac_prototype)
175+ @show J
175176 nrows, ncols = size (J)
176177
177178 if ! (sparsity isa Nothing)
@@ -189,7 +190,11 @@ function finite_difference_jacobian(
189190 _x1 = reshape (_vecx1,size (x))
190191 vecfx1 = _vec (f (_x1))
191192 dx = (vecfx1- vecfx)/ epsilon
192- J = J + _make_Ji (J, eltype (x), dx, color_i, nrows, ncols)
193+ if jac_prototype isa Nothing
194+ J = hcat (J, dx)
195+ else
196+ J = J + _make_Ji (J, eltype (x), dx, color_i, nrows, ncols)
197+ end
193198 else
194199 tmp = norm (vecx .* (colorvec .== color_i))
195200 epsilon = compute_epsilon (Val{:forward }, sqrt (tmp), relstep, absstep, dir)
@@ -214,7 +219,11 @@ function finite_difference_jacobian(
214219 vecfx1 = _vec (f (_x1))
215220 vecfx = _vec (f (_x))
216221 dx = (vecfx1- vecfx)/ (2 epsilon)
217- J = J + _make_Ji (J, eltype (x), dx, color_i, nrows, ncols)
222+ if jac_prototype isa Nothing
223+ J = hcat (J, dx)
224+ else
225+ J = J + _make_Ji (J, eltype (x), dx, color_i, nrows, ncols)
226+ end
218227 else
219228 tmp = norm (vecx1 .* (colorvec .== color_i))
220229 epsilon = compute_epsilon (Val{:forward }, sqrt (tmp), relstep, absstep, dir)
@@ -238,7 +247,11 @@ function finite_difference_jacobian(
238247 _x = reshape (_vecx,size (x))
239248 vecfx = _vec (f (_x))
240249 dx = imag (vecfx)/ epsilon
241- J = J + _make_Ji (J, eltype (x), dx, color_i, nrows, ncols)
250+ if jac_prototype isa Nothing
251+ J = hcat (J, dx)
252+ else
253+ J = J + _make_Ji (J, eltype (x), dx, color_i, nrows, ncols)
254+ end
242255 else
243256 _vecx = @. vecx + im * epsilon * (colorvec == color_i)
244257 _x = reshape (_vecx,size (x))
0 commit comments