Gradient of a complex valued matrix function but with real domain Let $f: \mathbb{C}^{N\times M}\rightarrow \mathbb{R}$ and $g: \mathbb{R}^{N\times M}\rightarrow \mathbb{C}^{N \times M}, N\geq M $ and $F = f \circ g$. I am trying to compute the gradient of $F$ w.r.t. $\mathbf{X} \in \mathbb{R}^{N\times M}$, i.e., $\nabla_\mathbf{X} f(g(\mathbf{X}))$ but I am struggling with the chain rule because of the complex domain. What is the dimension of the final gradient matrix?
As an example, I have: $g(\mathbf{X})=e^{i\mathbf{X}}$ and $f(\mathbf{Y})=|| \mathbf{A}-\mathbf{YB}||_F^2$ ($\mathbf{A}$ and $\mathbf{B}$ complex as well).
Thank you in advance.
 A: Let $E=\exp(iX)$ then your example concerns the function
$$\eqalign{
\phi(X)
 &= \|A-EB\|_F^2 \cr
 &= (A-EB)^*:(A-EB) \cr
 &= M^*:M \cr
}$$ where a colon denotes the trace/Frobenius product, i.e.
$\,\,\,A:B={\rm tr}(A^TB)$
and $M=(A-EB)$
Calculate the Wirtinger differential of this function
$$\eqalign{
d\phi &= M^*:dM + M:dM^* = 2\,{\mathcal Re}(M^*:dM)\cr
}$$
Continuing
$$\eqalign{
M^*:dM &= -M^*:dE\,B \cr
 &= -M^*B^T:d\exp(iX) \cr
 &= C:d\exp(iX) \cr
 &= C:d\sum_{k=0}^\infty q_kX^k \cr
 &= C:\sum_{k=1}^\infty q_k\sum_{j=0}^{k-1}X^{j}\,dX\,X^{k-j-1} \cr
 &= \sum_{k=1}^\infty q_k\sum_{j=0}^{k-1}\Big(X^{j}CX^{k-j-1}\Big)^T:dX \cr
 &= G:dX \cr
}$$
where, in addition to the Taylor series for the exponential $({\rm with\,\,} q_k=\frac{i^k}{k!})$, I have introduced the matrices $(C,G)$ to hide some messy expressions.
Now we are in a position to write (recalling that $X$ is real)
$$\eqalign{
d\phi &= 2\,{\mathcal Re}(G:dX) = (G+G^*):dX \cr
\frac{\partial\phi}{\partial X} &= G+G^* \cr\cr
}$$
Update
After writing the above, I noticed that your matrices are rectangular, which means you are applying the exponential function element-wise.
This makes the Taylor series unnecessary and the result much simpler. 
Picking up midway through the previous derivation,
$$\eqalign{
 M^*:dM &= C:(iE\odot dX) = (iE\odot C):dX = H:dX \cr
\frac{\partial\phi}{\partial X} &= H+H^* \cr
}$$
where $\odot$ denotes the elementwise/Hadamard product.
