code: def l2_loss(
      predictions: Array, targets: Optional[Array] = None
  ) -> Array:
      """Caculates the L2 loss of predictions wrt targets.
  
      If targets are not provided this function acts as an L2-regularizer for preds.
  
      Note: the 0.5 term is standard in "Pattern Recognition and Machine Learning"
      by Bishop, but not "The Elements of Statistical Learning" by Tibshirani.
  
      Args:
        predictions: a vector of arbitrary shape.
        targets: a vector of shape compatible with predictions.
  
      Returns:
        a vector of same shape of `predictions`.
      """
      if targets is None:
          targets = jnp.zeros_like(predictions)
      chex.assert_type([predictions, targets], float)
      return 0.5 * (predictions - targets) ** 2
  
file_path: rlax/rlax/_src/losses.py
imports: import functools
  from typing import Optional, Union
  import chex
  import jax
  import jax.numpy
  from rlax._src import general_value_functions
  from rlax._src import value_learning
label_desc: Use image node_id 1 for calling a global function with example usage: l2_loss(predictions, targets) and returns: unknown