Jacobian of Matrix-vector product

101 Views Asked by At

I would like to compute the Jacobian matrix of the following product $$ g(x) = \text{diag}\left(A^T f(x) \right) B^T f(x), $$ where $\text{diag}(v)$ denotes the diagonal matrix formed by placing $v$ on its main diagonal. Matrices $A,B$ are both $m \times \ell$ and do not depend on $x$. The function $f : \mathbb{R}^n \rightarrow \mathbb{R}^{m}$ maps $x$ to $[x^T \quad 1\; \cdots \; 1]$. This computation should be fairly simple by product rule and chain rule, but for some reason I cannot figure out how to deal with the $\text{diag}$ operation. Any hints would be appreciated!