code: def cartesian_to_spherical_coordinates(
      point_cartesian: TensorLike,
      eps: Float = None,
      name: str = "cartesian_to_spherical_coordinates",
  ) -> tf.Tensor:
      """Function to transform Cartesian coordinates to spherical coordinates.
  
      This function assumes a right handed coordinate system with `z` pointing up.
      When `x` and `y` are both `0`, the function outputs `0` for `phi`. Note that
      the function is not smooth when `x = y = 0`.
  
      Note:
        In the following, A1 to An are optional batch dimensions.
  
      Args:
        point_cartesian: A tensor of shape `[A1, ..., An, 3]`. In the last
          dimension, the data follows the `x`, `y`, `z` order.
        eps: A small `float`, to be added to the denominator. If left as `None`, its
          value is automatically selected using `point_cartesian.dtype`.
        name: A name for this op. Defaults to "cartesian_to_spherical_coordinates".
  
      Returns:
        A tensor of shape `[A1, ..., An, 3]`. The last dimensions contains
        (`r`,`theta`,`phi`), where `r` is the sphere radius, `theta` is the polar
        angle and `phi` is the azimuthal angle. Returns `NaN` gradient if x = y = 0.
      """
      with tf.name_scope(name):
          point_cartesian = tf.convert_to_tensor(value=point_cartesian)
  
          shape.check_static(
              tensor=point_cartesian,
              tensor_name="point_cartesian",
              has_dim_equals=(-1, 3),
          )
  
          x, y, z = tf.unstack(point_cartesian, axis=-1)
          radius = tf.norm(tensor=point_cartesian, axis=-1)
          theta = tf.acos(
              tf.clip_by_value(
                  safe_ops.safe_unsigned_div(z, radius, eps), -1.0, 1.0
              )
          )
          phi = tf.atan2(y, x)
          return tf.stack((radius, theta, phi), axis=-1)
  
file_path: graphics/tensorflow_graphics/math/math_helpers.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import numpy
  import tensorflow
  from tensorflow_graphics.util import asserts
  from tensorflow_graphics.util import export_api
  from tensorflow_graphics.util import safe_ops
  from tensorflow_graphics.util import shape
  from tensorflow_graphics.util.type_alias import Float
  from tensorflow_graphics.util.type_alias import TensorLike
label_desc: Use image node_id 1 for calling a global function with example usage: cartesian_to_spherical_coordinates(point_cartesian, eps, name) and returns: tf