code: def to_rotation_matrix(q):
      """Constructs a rotation matrix from a quaternion.
  
      Args:
        q: a (*,4) array containing quaternions.
  
      Returns:
        A (*,3,3) array containing rotation matrices.
      """
      x, y, z, w = jnp.split(q, 4, axis=-1)
      s = 1.0 / jnp.sum(q**2, axis=-1)
      return jnp.stack(
          [
              jnp.stack(
                  [
                      1 - 2 * s * (y**2 + z**2),
                      2 * s * (x * y - z * w),
                      2 * s * (x * z + y * w),
                  ],
                  axis=0,
              ),
              jnp.stack(
                  [
                      2 * s * (x * y + z * w),
                      1 - s * 2 * (x**2 + z**2),
                      2 * s * (y * z - x * w),
                  ],
                  axis=0,
              ),
              jnp.stack(
                  [
                      2 * s * (x * z - y * w),
                      2 * s * (y * z + x * w),
                      1 - 2 * s * (x**2 + y**2),
                  ],
                  axis=0,
              ),
          ],
          axis=0,
      )
  
file_path: nerfies/nerfies/quaternion.py
imports: from jax import numpy
  from jax.numpy import linalg
label_desc: Use image node_id 13 for calling a global function with example usage: to_rotation_matrix(q) and returns: jnp