# Path: tensorflow_constrained_optimization/python/graph_and_eager_test_case.py
# class _EagerPlaceholder(object):
# class _GraphWrappedSession(object):
# class _EagerWrappedSession(object):
# class GraphAndEagerTestCase(tf.test.TestCase):
#   def __init__(self):
#   def set(self, tensor):
#   def __call__(self):
#   def __init__(self, session):
#   def __enter__(self):
#   def __exit__(self, exc_type, exc_value, traceback):
#   def run(self, tensor, feed_dict=None):
#   def run_ops(self, callback, feed_dict=None):
#   def __init__(self):
#   def __enter__(self):
#   def __exit__(self, exc_type, exc_value, traceback):
#   def run(self, tensor, feed_dict=None):
#   def run_ops(self, callback, feed_dict=None):
#   def wrapped_placeholder(self, dtype, shape=None, name=None):
#   def wrapped_session(self):
# 
# Path: tensorflow_constrained_optimization/python/rates/loss.py
# def _convert_to_binary_classification_predictions(predictions):
#   def is_differentiable(self):
#   def __hash__(self):
#   def __eq__(self, other):
#   def __ne__(self, other):
#   def is_normalized(self):
#   def evaluate_binary_classification(self, predictions, weights):
#   def is_normalized(self):
#   def evaluate_multiclass(self, predictions, weights):
#   def evaluate_binary_classification(self, predictions, weights):
#   def is_differentiable(self):
#   def is_normalized(self):
#   def __hash__(self):
#   def __eq__(self, other):
#   def evaluate_multiclass(self, predictions, weights):
#   def evaluate_binary_classification(self, predictions, weights):
#   def __init__(self, margin=1.0):
#   def margin(self):
#   def is_differentiable(self):
#   def is_normalized(self):
#   def __hash__(self):
#   def __eq__(self, other):
#   def evaluate_multiclass(self, predictions, weights):
#   def evaluate_binary_classification(self, predictions, weights):
#   def is_differentiable(self):
#   def is_normalized(self):
#   def __hash__(self):
#   def __eq__(self, other):
#   def evaluate_multiclass(self, predictions, weights):
#   def evaluate_binary_classification(self, predictions, weights):
#   def is_differentiable(self):
#   def is_normalized(self):
#   def __hash__(self):
#   def __eq__(self, other):
#   def evaluate_multiclass(self, predictions, weights):
#   def evaluate_binary_classification(self, predictions, weights):
# class Loss(helpers.RateObject):
# class BinaryClassificationLoss(Loss):
# class MulticlassLoss(BinaryClassificationLoss):
# class ZeroOneLoss(MulticlassLoss):
# class HingeLoss(MulticlassLoss):
# class SoftmaxLoss(MulticlassLoss):
# class SoftmaxCrossEntropyLoss(MulticlassLoss):


import numpy as np
import tensorflow as tf
from tensorflow_constrained_optimization.python import graph_and_eager_test_case
from tensorflow_constrained_optimization.python.rates import loss
    """Tests the "_convert_to_binary_classification_predictions" function."""
    # A non-Tensor isn't a valid set of binary predictions.
    with self.assertRaises(TypeError):
      _ = loss._convert_to_binary_classification_predictions(
          [1.0, 2.0, 3.0, 4.0])

    # An integer Tensor isn't a valid set of binary predictions.
    tensor = tf.convert_to_tensor([1, 2, 3, 4], dtype=tf.int32)
    with self.assertRaises(TypeError):
      _ = loss._convert_to_binary_classification_predictions(tensor)

    # A rank-2 Tensor isn't a valid set of binary predictions.
    tensor = tf.convert_to_tensor([[1.0, 2.0], [3.0, 4.0]])
    with self.assertRaises(ValueError):
      _ = loss._convert_to_binary_classification_predictions(tensor)

    # A floating-point Tensor of shape (1,4,1) is a valid set of binary
    # predictions (it's floating-point, and only has one "nontrivial"
    # dimension).
    expected_predictions = [1.0, 2.0, 3.0, 4.0]
    tensor = tf.convert_to_tensor([[[1.0], [2.0], [3.0], [4.0]]],
                                  dtype=tf.float32)
    with self.wrapped_session() as session:
      actual_predictions = session.run(
          loss._convert_to_binary_classification_predictions(tensor))
    self.assertAllClose(
        expected_predictions, actual_predictions, rtol=0, atol=1e-6)

  def test_zero_one_loss(self):
    self._binary_loss_helper(binary_zero_one_loss, loss.ZeroOneLoss())

# Path: tensorflow_constrained_optimization/python/graph_and_eager_test_case.py
# class _EagerPlaceholder(object):
# class _GraphWrappedSession(object):
# class _EagerWrappedSession(object):
# class GraphAndEagerTestCase(tf.test.TestCase):
#   def __init__(self):
#   def set(self, tensor):
#   def __call__(self):
#   def __init__(self, session):
#   def __enter__(self):
#   def __exit__(self, exc_type, exc_value, traceback):
#   def run(self, tensor, feed_dict=None):
#   def run_ops(self, callback, feed_dict=None):
#   def __init__(self):
#   def __enter__(self):
#   def __exit__(self, exc_type, exc_value, traceback):
#   def run(self, tensor, feed_dict=None):
#   def run_ops(self, callback, feed_dict=None):
#   def wrapped_placeholder(self, dtype, shape=None, name=None):
#   def wrapped_session(self):
# 
# Path: tensorflow_constrained_optimization/python/rates/loss.py
# def _convert_to_binary_classification_predictions(predictions):
#   def is_differentiable(self):
#   def __hash__(self):
#   def __eq__(self, other):
#   def __ne__(self, other):
#   def is_normalized(self):
#   def evaluate_binary_classification(self, predictions, weights):
#   def is_normalized(self):
#   def evaluate_multiclass(self, predictions, weights):
#   def evaluate_binary_classification(self, predictions, weights):
#   def is_differentiable(self):
#   def is_normalized(self):
#   def __hash__(self):
#   def __eq__(self, other):
#   def evaluate_multiclass(self, predictions, weights):
#   def evaluate_binary_classification(self, predictions, weights):
#   def __init__(self, margin=1.0):
#   def margin(self):
#   def is_differentiable(self):
#   def is_normalized(self):
#   def __hash__(self):
#   def __eq__(self, other):
#   def evaluate_multiclass(self, predictions, weights):
#   def evaluate_binary_classification(self, predictions, weights):
#   def is_differentiable(self):
#   def is_normalized(self):
#   def __hash__(self):
#   def __eq__(self, other):
#   def evaluate_multiclass(self, predictions, weights):
#   def evaluate_binary_classification(self, predictions, weights):
#   def is_differentiable(self):
#   def is_normalized(self):
#   def __hash__(self):
#   def __eq__(self, other):
#   def evaluate_multiclass(self, predictions, weights):
#   def evaluate_binary_classification(self, predictions, weights):
# class Loss(helpers.RateObject):
# class BinaryClassificationLoss(Loss):
# class MulticlassLoss(BinaryClassificationLoss):
# class ZeroOneLoss(MulticlassLoss):
# class HingeLoss(MulticlassLoss):
# class SoftmaxLoss(MulticlassLoss):
# class SoftmaxCrossEntropyLoss(MulticlassLoss):


# Path: tensorflow_constrained_optimization/python/rates/loss_test.py
import numpy as np
import tensorflow as tf
from tensorflow_constrained_optimization.python import graph_and_eager_test_case
from tensorflow_constrained_optimization.python.rates import loss

    """Tests the "_convert_to_binary_classification_predictions" function."""
    # A non-Tensor isn't a valid set of binary predictions.
    with self.assertRaises(TypeError):
      _ = loss._convert_to_binary_classification_predictions(
          [1.0, 2.0, 3.0, 4.0])

    # An integer Tensor isn't a valid set of binary predictions.
    tensor = tf.convert_to_tensor([1, 2, 3, 4], dtype=tf.int32)
    with self.assertRaises(TypeError):
      _ = loss._convert_to_binary_classification_predictions(tensor)

    # A rank-2 Tensor isn't a valid set of binary predictions.
    tensor = tf.convert_to_tensor([[1.0, 2.0], [3.0, 4.0]])
    with self.assertRaises(ValueError):
      _ = loss._convert_to_binary_classification_predictions(tensor)

    # A floating-point Tensor of shape (1,4,1) is a valid set of binary
    # predictions (it's floating-point, and only has one "nontrivial"
    # dimension).
    expected_predictions = [1.0, 2.0, 3.0, 4.0]
    tensor = tf.convert_to_tensor([[[1.0], [2.0], [3.0], [4.0]]],
                                  dtype=tf.float32)
    with self.wrapped_session() as session:
      actual_predictions = session.run(
          loss._convert_to_binary_classification_predictions(tensor))
    self.assertAllClose(
        expected_predictions, actual_predictions, rtol=0, atol=1e-6)

  def test_zero_one_loss(self):
    self._binary_loss_helper(binary_zero_one_loss, loss.ZeroOneLoss())

    self._multiclass_loss_helper(multiclass_zero_one_loss, loss.ZeroOneLoss())