Quantcast
Channel: First steps - JuliaLang
Viewing all articles
Browse latest Browse all 2795

Create a 2D array from a 1D array with reference

$
0
0

Hi
I am trying to use FiniteDiff package to compute a gradient of a function with an N-vector as input and a scalar as output. I need to write the gradient (an N-vector) to a pre-allocated vector (supplied by an optimization solver).

However, the FiniteDiff.finite_difference_jacobian! function will only write to a pre-allocated 1xN 2D array as the Jacobian matrix. How can I wrap the supplied 1D gradient vector by the optimization solver in a 1xN array to trick the finite_difference_jacobian! function into thinking it is getting a reference to a pre-allocated Jacobian matrix of the correct size, without new allocation and copying?

5 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 2795

Trending Articles