LookupError: No gradient defined for operation 'inference/sample/FloorMod' (op type: FloorMod)

I’m trying to implement a model which has a transformation inside: Cartesian coordinates to spherical coordinates.

So, once I have the Cartesian coordinates (for instance a multivariate Gaussian distribution in 3D), I transform them to spherical coordinates doing the following (I need degrees between 0 and 360):

xn = MultivariateNormalTriL(mu,sigma, sample_shape=N)

xsq = xn*xn
r = tf.sqrt(tf.reduce_sum(xsq, 1, keep_dims=True))
l = tf.reshape(tf.mod(tf.atan2(xn[:,1], xn[:,0])*180.0/np.pi+360.0, 360.0), [N,1])
b = tf.reshape(tf.mod(tf.atan2(xn[:,2],tf.sqrt(xsq[:,0]+xsq[:,1]))*180.0/np.pi+360.0, 360.0), [N,1])

But when I try to do inference I have problems with tf.mod() function.

Any help will be welcome!

>>> inference3.initialize(n_iter=n_iter, n_print=n_print, n_samples=n_samples)
Traceback (most recent call last):
  File "/home/angel/anaconda2/envs/tensorflow/lib/python3.6/site-packages/tensorflow/python/ops/gradients_impl.py", line 512, in gradients
    grad_fn = ops.get_gradient_function(op)
  File "/home/angel/anaconda2/envs/tensorflow/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1836, in get_gradient_function
    return _gradient_registry.lookup(op_type)
  File "/home/angel/anaconda2/envs/tensorflow/lib/python3.6/site-packages/tensorflow/python/framework/registry.py", line 93, in lookup
    "%s registry has no entry for: %s" % (self._name, name))
LookupError: gradient registry has no entry for: FloorMod

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/angel/anaconda2/envs/tensorflow/lib/python3.6/site-packages/edward-1.3.4-py3.6.egg/edward/inferences/klqp.py", line 77, in initialize
  File "/home/angel/anaconda2/envs/tensorflow/lib/python3.6/site-packages/edward-1.3.4-py3.6.egg/edward/inferences/variational_inference.py", line 68, in initialize
  File "/home/angel/anaconda2/envs/tensorflow/lib/python3.6/site-packages/edward-1.3.4-py3.6.egg/edward/inferences/klqp.py", line 116, in build_loss_and_gradients
  File "/home/angel/anaconda2/envs/tensorflow/lib/python3.6/site-packages/edward-1.3.4-py3.6.egg/edward/inferences/klqp.py", line 412, in build_reparam_loss_and_gradients
  File "/home/angel/anaconda2/envs/tensorflow/lib/python3.6/site-packages/tensorflow/python/ops/gradients_impl.py", line 516, in gradients
    (op.name, op.type))
LookupError: No gradient defined for operation 'inference/sample/FloorMod' (op type: FloorMod)

A solution to this problem could be:

xn = MultivariateNormalTriL(mu,sigma, sample_shape=N)

xsq = xn*xn
r = tf.sqrt(tf.reduce_sum(xsq, 1, keep_dims=True))
cond = tf.greater(xn[:,1], tf.constant(0.0))
l = tf.reshape(tf.where(cond, tf.atan2(xn[:,1], xn[:,0])*180.0/np.pi, tf.atan2(xn[:,1], xn[:,0])*180.0/np.pi+360.0),[N,1])
b = tf.reshape(tf.atan2(xn[:,2],tf.sqrt(xsq[:,0]+xsq[:,1]))*180.0/np.pi, [N,1])