# 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/defaults.py
# DENOMINATOR_LOWER_BOUND_KEY = "denominator_lower_bound"
# GLOBAL_STEP_KEY = "global_step"
# VARIABLE_FN_KEY = "variable_fn"
# DEFAULT_PENALTY_LOSS = loss.HingeLoss()
# DEFAULT_CONSTRAINT_LOSS = loss.ZeroOneLoss()
# 
# Path: tensorflow_constrained_optimization/python/rates/subsettable_context.py
# class _RawContext(helpers.RateObject):
# class SubsettableContext(helpers.RateObject):
#   def __init__(self, penalty_predictions, penalty_labels, penalty_weights,
#                constraint_predictions, constraint_labels, constraint_weights,
#                labels_are_probabilities, num_classes):
#   def __eq__(self, other):
#   def __ne__(self, other):
#   def penalty_predictions(self):
#   def penalty_labels(self):
#   def penalty_weights(self):
#   def constraint_predictions(self):
#   def constraint_labels(self):
#   def constraint_weights(self):
#   def labels_are_probabilities(self):
#   def num_classes(self):
#   def _transform_predictions(self, transformation):
#   def _check_compatibility(self, other):
#   def __init__(self, raw_context, penalty_predicate, constraint_predicate):
#   def is_split(self):
#   def raw_context(self):
#   def penalty_predicate(self):
#   def constraint_predicate(self):
#   def _transform_predictions(self, transformation):
#   def subset(self, penalty_predicate, constraint_predicate=None):
#   def __and__(self, other):
#   def __or__(self, other):
# def _rate_context_helper(predictions, labels, weights, labels_are_probabilities,
#                          num_classes):
# def rate_context(predictions,
#                  labels=None,
#                  weights=1.0,
#                  labels_are_probabilities=False):
# def multiclass_rate_context(num_classes, predictions, labels=None, weights=1.0):
# def _split_rate_context_helper(penalty_predictions, constraint_predictions,
#                                penalty_labels, constraint_labels,
#                                penalty_weights, constraint_weights,
#                                labels_are_probabilities, num_classes):
# def split_rate_context(penalty_predictions,
#                        constraint_predictions,
#                        penalty_labels=None,
#                        constraint_labels=None,
#                        penalty_weights=1.0,
#                        constraint_weights=1.0,
#                        labels_are_probabilities=False):
# def multiclass_split_rate_context(num_classes,
#                                   penalty_predictions,
#                                   constraint_predictions,
#                                   penalty_labels=None,
#                                   constraint_labels=None,
#                                   penalty_weights=1.0,
#                                   constraint_weights=1.0):


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 defaults
from tensorflow_constrained_optimization.python.rates import subsettable_context
    with self.wrapped_session() as session:
      # Make sure that the subset of a subset ANDs the conditions together in
      # condition1.
      expected_penalty_predicate = np.array([0, 0, 1, 0, 1, 0, 0, 0, 0, 0],
                                            dtype=np.float32)
      expected_constraint_predicate = np.array([0, 1, 0, 0, 0, 0, 0, 1, 0, 1],
                                               dtype=np.float32)
      self.assertAllEqual(
          expected_penalty_predicate,
          session.run(context1.penalty_predicate.tensor(structure_memoizer)))
      self.assertAllEqual(
          expected_constraint_predicate,
          session.run(context1.constraint_predicate.tensor(structure_memoizer)))
      # Likewise in condition2.
      expected_penalty_predicate = np.array([0, 0, 0, 0, 1, 0, 1, 0, 0, 0],
                                            dtype=np.float32)
      expected_constraint_predicate = np.array([0, 1, 0, 1, 0, 0, 0, 0, 0, 1],
                                               dtype=np.float32)
      self.assertAllEqual(
          expected_penalty_predicate,
          session.run(context2.penalty_predicate.tensor(structure_memoizer)))
      self.assertAllEqual(
          expected_constraint_predicate,
          session.run(context2.constraint_predicate.tensor(structure_memoizer)))

  def test_and(self):
    """Tests `SubsettableContext`'s logical AND operator."""
    context1, context2 = create_contexts()
    structure_memoizer = {
        defaults.DENOMINATOR_LOWER_BOUND_KEY: 0.0,

# 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/defaults.py
# DENOMINATOR_LOWER_BOUND_KEY = "denominator_lower_bound"
# GLOBAL_STEP_KEY = "global_step"
# VARIABLE_FN_KEY = "variable_fn"
# DEFAULT_PENALTY_LOSS = loss.HingeLoss()
# DEFAULT_CONSTRAINT_LOSS = loss.ZeroOneLoss()
# 
# Path: tensorflow_constrained_optimization/python/rates/subsettable_context.py
# class _RawContext(helpers.RateObject):
# class SubsettableContext(helpers.RateObject):
#   def __init__(self, penalty_predictions, penalty_labels, penalty_weights,
#                constraint_predictions, constraint_labels, constraint_weights,
#                labels_are_probabilities, num_classes):
#   def __eq__(self, other):
#   def __ne__(self, other):
#   def penalty_predictions(self):
#   def penalty_labels(self):
#   def penalty_weights(self):
#   def constraint_predictions(self):
#   def constraint_labels(self):
#   def constraint_weights(self):
#   def labels_are_probabilities(self):
#   def num_classes(self):
#   def _transform_predictions(self, transformation):
#   def _check_compatibility(self, other):
#   def __init__(self, raw_context, penalty_predicate, constraint_predicate):
#   def is_split(self):
#   def raw_context(self):
#   def penalty_predicate(self):
#   def constraint_predicate(self):
#   def _transform_predictions(self, transformation):
#   def subset(self, penalty_predicate, constraint_predicate=None):
#   def __and__(self, other):
#   def __or__(self, other):
# def _rate_context_helper(predictions, labels, weights, labels_are_probabilities,
#                          num_classes):
# def rate_context(predictions,
#                  labels=None,
#                  weights=1.0,
#                  labels_are_probabilities=False):
# def multiclass_rate_context(num_classes, predictions, labels=None, weights=1.0):
# def _split_rate_context_helper(penalty_predictions, constraint_predictions,
#                                penalty_labels, constraint_labels,
#                                penalty_weights, constraint_weights,
#                                labels_are_probabilities, num_classes):
# def split_rate_context(penalty_predictions,
#                        constraint_predictions,
#                        penalty_labels=None,
#                        constraint_labels=None,
#                        penalty_weights=1.0,
#                        constraint_weights=1.0,
#                        labels_are_probabilities=False):
# def multiclass_split_rate_context(num_classes,
#                                   penalty_predictions,
#                                   constraint_predictions,
#                                   penalty_labels=None,
#                                   constraint_labels=None,
#                                   penalty_weights=1.0,
#                                   constraint_weights=1.0):


# Path: tensorflow_constrained_optimization/python/rates/subsettable_context_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 defaults
from tensorflow_constrained_optimization.python.rates import subsettable_context

    with self.wrapped_session() as session:
      # Make sure that the subset of a subset ANDs the conditions together in
      # condition1.
      expected_penalty_predicate = np.array([0, 0, 1, 0, 1, 0, 0, 0, 0, 0],
                                            dtype=np.float32)
      expected_constraint_predicate = np.array([0, 1, 0, 0, 0, 0, 0, 1, 0, 1],
                                               dtype=np.float32)
      self.assertAllEqual(
          expected_penalty_predicate,
          session.run(context1.penalty_predicate.tensor(structure_memoizer)))
      self.assertAllEqual(
          expected_constraint_predicate,
          session.run(context1.constraint_predicate.tensor(structure_memoizer)))
      # Likewise in condition2.
      expected_penalty_predicate = np.array([0, 0, 0, 0, 1, 0, 1, 0, 0, 0],
                                            dtype=np.float32)
      expected_constraint_predicate = np.array([0, 1, 0, 1, 0, 0, 0, 0, 0, 1],
                                               dtype=np.float32)
      self.assertAllEqual(
          expected_penalty_predicate,
          session.run(context2.penalty_predicate.tensor(structure_memoizer)))
      self.assertAllEqual(
          expected_constraint_predicate,
          session.run(context2.constraint_predicate.tensor(structure_memoizer)))

  def test_and(self):
    """Tests `SubsettableContext`'s logical AND operator."""
    context1, context2 = create_contexts()
    structure_memoizer = {
        defaults.DENOMINATOR_LOWER_BOUND_KEY: 0.0,

        defaults.GLOBAL_STEP_KEY: tf.Variable(0, dtype=tf.int32),