import tensorflow as tf

    tgt_posi_dif = tf.where(geq, tgt_dif, -tgt_dif)
    pred_posi_dif = tf.where(geq, pred_dif, -pred_dif)
    loss = tf.maximum(0., tgt_posi_dif - pred_posi_dif)

    cstr_pct = tf.math.count_nonzero(loss, dtype=tf.float32) / tf.cast(tf.reduce_prod(tf.shape(loss)), tf.float32)
    final_loss = tf.reduce_mean(loss)
    return final_loss, cstr_pct

def contra_traj_lossV7(pred, tgt, horizon=12, temp=100):
    horizon_pred, horizon_tgt = horizon_sumV1(pred, horizon), horizon_sumV1(tgt, horizon)
