I would like to clarify the Gradient and Hessian of $$g(x) = \sum_i g_i(x_i) ,$$ where $x = [x_1,\ldots,x_N]^T \in \mathbb{R}^N$.
- Is the gradient of $g(x)$ correct? $$\nabla g(x) = \left[ \nabla g_1(x_1), \ldots, \nabla g_i(x_i), \ldots, \nabla g_N(x_N) \right]^T \ .$$
- Is the Hessian of $g(x)$ correct? $$\mathcal{H}\left( g(x) \right) = {\rm Diag} \left\{ \nabla^2 g_1(x_1), \ldots, \nabla^2 g_i(x_i), \ldots, \nabla^2 g_N(x_N) \right\} \ ,$$ where ${\rm Diag}\{ \cdot \}$ creates the diagonal matrix of the elements.