Problem passing gradients into Optim

Is this a duplicate of Improving Performance of a Loop?