code: def from_quaternion(
      quaternion: type_alias.TensorLike,
      name: str = "rotation_matrix_3d_from_quaternion",
  ) -> tf.Tensor:
      """Convert a quaternion to a rotation matrix.
  
      Note:
        In the following, A1 to An are optional batch dimensions.
  
      Args:
        quaternion: A tensor of shape `[A1, ..., An, 4]`, where the last dimension
          represents a normalized quaternion.
        name: A name for this op that defaults to
          "rotation_matrix_3d_from_quaternion".
  
      Returns:
        A tensor of shape `[A1, ..., An, 3, 3]`, where the last two dimensions
        represent a 3d rotation matrix.
  
      Raises:
        ValueError: If the shape of `quaternion` is not supported.
      """
      with tf.name_scope(name):
          quaternion = tf.convert_to_tensor(value=quaternion)
  
          shape.check_static(
              tensor=quaternion,
              tensor_name="quaternion",
              has_dim_equals=(-1, 4),
          )
          quaternion = asserts.assert_normalized(quaternion)
  
          x, y, z, w = tf.unstack(quaternion, axis=-1)
          tx = 2.0 * x
          ty = 2.0 * y
          tz = 2.0 * z
          twx = tx * w
          twy = ty * w
          twz = tz * w
          txx = tx * x
          txy = ty * x
          txz = tz * x
          tyy = ty * y
          tyz = tz * y
          tzz = tz * z
          matrix = tf.stack(
              (
                  1.0 - (tyy + tzz),
                  txy - twz,
                  txz + twy,
                  txy + twz,
                  1.0 - (txx + tzz),
                  tyz - twx,
                  txz - twy,
                  tyz + twx,
                  1.0 - (txx + tyy),
              ),
              axis=-1,
          )  # pyformat: disable
          output_shape = tf.concat(
              (tf.shape(input=quaternion)[:-1], (3, 3)), axis=-1
          )
          return tf.reshape(matrix, shape=output_shape)
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from absl import flags
  from six.moves import range
  import tensorflow
  from tensorflow_graphics.geometry.transformation import rotation_matrix_common
  from tensorflow_graphics.util import asserts
  from tensorflow_graphics.util import export_api
  from tensorflow_graphics.util import shape
  from tensorflow_graphics.util import tfg_flags
  from tensorflow_graphics.util import type_alias
label_desc: Use image node_id 6 for calling a global function with example usage: from_quaternion(quaternion, name) and returns: tf