import tensorflow as tf

  """
  assertions = []
  assertions.append(
      tf.Assert(
          tf.reduce_all(tf.less(tf.abs(tf.reduce_sum(tf.square(predictions), [1]) - 1), 1e-4)),
          ['The l2 norm of each prediction quaternion vector should be 1.']))
  assertions.append(
      tf.Assert(
          tf.reduce_all(tf.less(tf.abs(tf.reduce_sum(tf.square(labels), [1]) - 1), 1e-4)),
          ['The l2 norm of each label quaternion vector should be 1.']))
  with tf.name_scope(name):
    with tf.control_dependencies(assertions):
      product = tf.multiply(predictions, labels)
    internal_dot_products = tf.reduce_sum(product, [1])
    logcost = tf.log(1e-4 + 1 - tf.abs(internal_dot_products))
  return logcost


def log_quaternion_loss(predictions, labels, batch_size, name='log_quaternion_loss'):
  """A helper function to compute the mean error between batches of
  quaternions.

  The caller is expected to add the loss to the graph.

  Args:
    predictions: A Tensor of size [batch_size, 4].
