fixed an error with the jacobian

to use a different version of sparse_merge_duplicates that doesn't
mirror the indices.

Also, pre-allocated arrays for the jacobian and hessian outside of the
callbacks.