# Path: deep_verify/src/common.py
# def with_explicit_update(volatile_value):
#   def materialise(value):
# def targeted_objective(final_w, final_b, labels):
# def concave_max_binsearch(fn, lb, ub, num_iter=20):
# def _prod(lst):
# def convolution(x, kernel, padding, strides):
# def conv_transpose(y, kernel, result_shape, padding, strides):
# def avgpool_transpose(y, result_shape, kernel_shape, strides):
# def conv_broadcast(x, kernel_shape, padding, strides):
# def conv2d_broadcast(x, kernel_height, kernel_width, padding, strides):
# def conv1d_broadcast(x, kernel_length, padding, stride):
# def conv_reduce_sum(x, result_shape, padding, strides):
# def conv2d_reduce_sum(x, input_height, input_width, padding, strides):
# def conv1d_reduce_sum(x, input_length, padding, stride):
# 
# Path: deep_verify/src/formulations/standard/standard_layer_calcs.py
# def _reduce_softmax(v, axis, inverse_temperature=None):
# def _conj(nl, mu, lam, nominal, lb, ub, parameters=None,
#           inverse_temperature=None):
#     def siginv(y):
# def max_linear(coefficients, lb, ub, axis=None, keepdims=False,
#                inverse_temperature=None):
# def linear_dual_objective(lam_in, activation_coeffs, dual_obj_bias, lb, ub,
#                           inverse_temperature=None):
# def _prod(lst):
# def maxpool_layer_dual_objective(kernel_shape, strides, with_relu,
#                                  mu_in, lam_out, lb, ub, nominal=None):
#   def fn(y):
# def activation_layer_dual_objective(nl, mu_in, lam_out, lb, ub, nominal=None,
#                                     parameters=None, inverse_temperature=None):


from absl.testing import parameterized
from deep_verify.src import common
from deep_verify.src.formulations.standard import standard_layer_calcs
from interval_bound_propagation import layer_utils
import numpy as np
import sonnet as snt
import tensorflow as tf
                                  ('float64', tf.float64, 1.e-8))
  def test_conv2d_layer_dual_objective(self, dtype, tol):
    num_classes = 5
    batch_size = 53
    input_height = 17
    input_width = 7
    kernel_height = 3
    kernel_width = 4
    input_channels = 3
    output_channels = 2
    padding = 'VALID'
    strides = (2, 1)

    # Output dimensions, based on convolution settings.
    output_height = 8
    output_width = 4

    w = tf.random_normal(dtype=dtype, shape=(
        kernel_height, kernel_width, input_channels, output_channels))
    b = tf.random_normal(dtype=dtype, shape=(output_channels,))
    lam_in = tf.random_normal(dtype=dtype, shape=(
        num_classes, batch_size, input_height, input_width, input_channels))
    mu_out = tf.random_normal(dtype=dtype, shape=(
        num_classes, batch_size, output_height, output_width, output_channels))
    lb = tf.random_normal(dtype=dtype, shape=(
        batch_size, input_height, input_width, input_channels))
    ub = tf.random_normal(dtype=dtype, shape=(
        batch_size, input_height, input_width, input_channels))
    lb, ub = tf.minimum(lb, ub), tf.maximum(lb, ub)


# Path: deep_verify/src/common.py
# def with_explicit_update(volatile_value):
#   def materialise(value):
# def targeted_objective(final_w, final_b, labels):
# def concave_max_binsearch(fn, lb, ub, num_iter=20):
# def _prod(lst):
# def convolution(x, kernel, padding, strides):
# def conv_transpose(y, kernel, result_shape, padding, strides):
# def avgpool_transpose(y, result_shape, kernel_shape, strides):
# def conv_broadcast(x, kernel_shape, padding, strides):
# def conv2d_broadcast(x, kernel_height, kernel_width, padding, strides):
# def conv1d_broadcast(x, kernel_length, padding, stride):
# def conv_reduce_sum(x, result_shape, padding, strides):
# def conv2d_reduce_sum(x, input_height, input_width, padding, strides):
# def conv1d_reduce_sum(x, input_length, padding, stride):
# 
# Path: deep_verify/src/formulations/standard/standard_layer_calcs.py
# def _reduce_softmax(v, axis, inverse_temperature=None):
# def _conj(nl, mu, lam, nominal, lb, ub, parameters=None,
#           inverse_temperature=None):
#     def siginv(y):
# def max_linear(coefficients, lb, ub, axis=None, keepdims=False,
#                inverse_temperature=None):
# def linear_dual_objective(lam_in, activation_coeffs, dual_obj_bias, lb, ub,
#                           inverse_temperature=None):
# def _prod(lst):
# def maxpool_layer_dual_objective(kernel_shape, strides, with_relu,
#                                  mu_in, lam_out, lb, ub, nominal=None):
#   def fn(y):
# def activation_layer_dual_objective(nl, mu_in, lam_out, lb, ub, nominal=None,
#                                     parameters=None, inverse_temperature=None):


# Path: deep_verify/tests/formulations/standard/standard_layer_calcs_test.py
from absl.testing import parameterized
from deep_verify.src import common
from deep_verify.src.formulations.standard import standard_layer_calcs
from interval_bound_propagation import layer_utils
import numpy as np
import sonnet as snt
import tensorflow as tf

                                  ('float64', tf.float64, 1.e-8))
  def test_conv2d_layer_dual_objective(self, dtype, tol):
    num_classes = 5
    batch_size = 53
    input_height = 17
    input_width = 7
    kernel_height = 3
    kernel_width = 4
    input_channels = 3
    output_channels = 2
    padding = 'VALID'
    strides = (2, 1)

    # Output dimensions, based on convolution settings.
    output_height = 8
    output_width = 4

    w = tf.random_normal(dtype=dtype, shape=(
        kernel_height, kernel_width, input_channels, output_channels))
    b = tf.random_normal(dtype=dtype, shape=(output_channels,))
    lam_in = tf.random_normal(dtype=dtype, shape=(
        num_classes, batch_size, input_height, input_width, input_channels))
    mu_out = tf.random_normal(dtype=dtype, shape=(
        num_classes, batch_size, output_height, output_width, output_channels))
    lb = tf.random_normal(dtype=dtype, shape=(
        batch_size, input_height, input_width, input_channels))
    ub = tf.random_normal(dtype=dtype, shape=(
        batch_size, input_height, input_width, input_channels))
    lb, ub = tf.minimum(lb, ub), tf.maximum(lb, ub)


    activation_coeffs = -common.conv_transpose(mu_out, w,