# Path: tensorflow_constrained_optimization/python/rates/helpers.py
# class RateObject(object):
# class UniqueList(RateObject):
# def convert_to_1d_tensor(tensor, name=None):
# def get_num_columns_of_2d_tensor(tensor, name="tensor"):
# def get_num_elements_of_tensor(tensor, name="tensor"):
#   def __init__(self, collection=None, element_type=None):
#   def list(self):
#   def append(self, element):
#   def __eq__(self, other):
#   def __ne__(self, other):
#   def __len__(self):
#   def __iter__(self):
#   def __add__(self, other):
#   def __radd__(self, other):
#   def __getitem__(self, slice_spec):


import abc
import six
import tensorflow as tf
from six.moves import xrange  # pylint: disable=redefined-builtin
from tensorflow_constrained_optimization.python.rates import helpers
    """Evaluates the multiclass softmax loss on the given predictions.

    Given a rank-1 `Tensor` of predictions with shape (n,), where n is the
    number of examples, and a rank-2 `Tensor` of weights with shape (m, 2),
    where m is broadcastable to n, this method will return a `Tensor` of shape
    (n,) where the ith element is:

    ```python
    softmax_loss[i] = sum_j ( weights[i, j] * (
        exp(predictions[i, j]) / sum_k exp(predictions[i, k]) ) )
    ```

    Args:
      predictions: a `Tensor` of shape (n, k), where n is the number of examples
        and k is the number of classes.
      weights: a `Tensor` of shape (m, k), where m is broadcastable to n. This
        `Tensor` is *not* necessarily non-negative.

    Returns:
      A `Tensor` of shape (n,) and dtype=predictions.dtype, containing the
      softmax losses for each example.

    Raises:
      TypeError: if "predictions" is not a floating-point `Tensor`, or "weights"
        is not a `Tensor`.
      ValueError: if "predictions" and "weights" have different numbers of
        columns (i.e. if the number of classes is inconsistent).
    """
    num_classes = helpers.get_num_columns_of_2d_tensor(
        predictions, name="multiclass predictions")

# Path: tensorflow_constrained_optimization/python/rates/helpers.py
# class RateObject(object):
# class UniqueList(RateObject):
# def convert_to_1d_tensor(tensor, name=None):
# def get_num_columns_of_2d_tensor(tensor, name="tensor"):
# def get_num_elements_of_tensor(tensor, name="tensor"):
#   def __init__(self, collection=None, element_type=None):
#   def list(self):
#   def append(self, element):
#   def __eq__(self, other):
#   def __ne__(self, other):
#   def __len__(self):
#   def __iter__(self):
#   def __add__(self, other):
#   def __radd__(self, other):
#   def __getitem__(self, slice_spec):


# Path: tensorflow_constrained_optimization/python/rates/loss.py
import abc
import six
import tensorflow as tf
from six.moves import xrange  # pylint: disable=redefined-builtin
from tensorflow_constrained_optimization.python.rates import helpers

    """Evaluates the multiclass softmax loss on the given predictions.

    Given a rank-1 `Tensor` of predictions with shape (n,), where n is the
    number of examples, and a rank-2 `Tensor` of weights with shape (m, 2),
    where m is broadcastable to n, this method will return a `Tensor` of shape
    (n,) where the ith element is:

    ```python
    softmax_loss[i] = sum_j ( weights[i, j] * (
        exp(predictions[i, j]) / sum_k exp(predictions[i, k]) ) )
    ```

    Args:
      predictions: a `Tensor` of shape (n, k), where n is the number of examples
        and k is the number of classes.
      weights: a `Tensor` of shape (m, k), where m is broadcastable to n. This
        `Tensor` is *not* necessarily non-negative.

    Returns:
      A `Tensor` of shape (n,) and dtype=predictions.dtype, containing the
      softmax losses for each example.

    Raises:
      TypeError: if "predictions" is not a floating-point `Tensor`, or "weights"
        is not a `Tensor`.
      ValueError: if "predictions" and "weights" have different numbers of
        columns (i.e. if the number of classes is inconsistent).
    """
    num_classes = helpers.get_num_columns_of_2d_tensor(
        predictions, name="multiclass predictions")

    weights_num_classes = helpers.get_num_columns_of_2d_tensor(