code: def weighted_mean_absolute_error(
      predictions: jnp.ndarray,
      targets: jnp.ndarray,
      weights: Optional[jnp.ndarray] = None,
  ) -> jnp.ndarray:
      """Weighted mean of weighted_unnormalized_mean_absolute_error.
  
      Args:
        predictions: Output of model in shape [batch, ..., num_features].
        targets: Targets of shape [batch, ..., num_features].
        weights:  None or array of shape [batch] This is the weight to apply to the
          loss  computed for each example in the batch. Can be used to ignore padded
          examples in the batch.
  
      Returns:
        The averaged mean absolute error of all the examples in the given batch as
        a scalar.
      """
      unnormalized_mae = weighted_absolute_error(
          predictions=predictions, targets=targets, weights=weights
      )
  
      if weights is not None:
          # Divide by sum of weights:
          normalization = weights.sum()
      else:
          # Divide by batch size:
          normalization = unnormalized_mae.shape[0]
      return jnp.sum(unnormalized_mae) / (normalization + 1e-8)
  
imports: import functools
  from typing import Optional, Any, Tuple, Union
  import flax.linen
  import jax
  import jax.numpy
  import numpy
label_desc: Use image node_id 20 for calling a global function with example usage: weighted_mean_absolute_error(predictions, targets, weights) and returns: unknown