Q:

How do I define a gradient for a custom op working on complex tensors in tensorflow?

If you have a tensor of complex numbers, tensorflow already has an op to get the magnitudes of those complex numbers (tf.abs). Now I want to add a function that calculates the angle of each number. This function is easy to implement using numpy and the gradient is known.  
When it comes to adding custom tensorflow ops based on numpy, this seems to be the way to go. However here the input are complex numbers. So my question is, is it possible to use the same approach but work with complex numbers? Just directly copying the approach used in tf.abs is not possible, since it uses c++.

A:

Looks like tf.arg will exist soon: https://github.com/tensorflow/tensorflow/pull/10643.  If you want something before then, I'd recommend
def arg(z):
  return tf.atan2(tf.imag(z), tf.real(z))

