# 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):


import abc
import collections
import six
import sonnet as snt
import tensorflow as tf
from deep_verify.src import common
from interval_bound_propagation import layer_utils
    self._w = module.w
    self._b = module.b if module.has_bias else None

  def forward_prop(self, x, apply_bias=False, w_fn=None):
    w = w_fn(self._w) if w_fn is not None else self._w
    y = tf.tensordot(x, tf.cast(w, x.dtype), axes=1)
    if apply_bias and self._b is not None:
      y += tf.cast(self._b, x.dtype)
    return y

  def backward_prop(self, y, w_fn=None):
    w = w_fn(self._w) if w_fn is not None else self._w
    return tf.tensordot(y, tf.transpose(tf.cast(w, y.dtype)), axes=1)

  def backward_prop_bias(self, y):
    if self._b is not None:
      return tf.tensordot(y, tf.cast(self._b, y.dtype), axes=1)
    else:
      return tf.zeros(tf.shape(y)[:2], dtype=y.dtype)

  def flatten(self):
    return self._w, self._b

  def custom_op(self, op, *args, **kwargs):
    return op.visit_linear(self, self._w, self._b, *args, **kwargs)

  def get_objective_weights(self, labels, target_strategy=None):
    """Elides the objective with this (final) linear layer."""
    assert self._b is not None, 'Last layer must have a bias.'
    if target_strategy is None:

# 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/layers/layers.py
import abc
import collections
import six
import sonnet as snt
import tensorflow as tf
from deep_verify.src import common
from interval_bound_propagation import layer_utils

    self._w = module.w
    self._b = module.b if module.has_bias else None

  def forward_prop(self, x, apply_bias=False, w_fn=None):
    w = w_fn(self._w) if w_fn is not None else self._w
    y = tf.tensordot(x, tf.cast(w, x.dtype), axes=1)
    if apply_bias and self._b is not None:
      y += tf.cast(self._b, x.dtype)
    return y

  def backward_prop(self, y, w_fn=None):
    w = w_fn(self._w) if w_fn is not None else self._w
    return tf.tensordot(y, tf.transpose(tf.cast(w, y.dtype)), axes=1)

  def backward_prop_bias(self, y):
    if self._b is not None:
      return tf.tensordot(y, tf.cast(self._b, y.dtype), axes=1)
    else:
      return tf.zeros(tf.shape(y)[:2], dtype=y.dtype)

  def flatten(self):
    return self._w, self._b

  def custom_op(self, op, *args, **kwargs):
    return op.visit_linear(self, self._w, self._b, *args, **kwargs)

  def get_objective_weights(self, labels, target_strategy=None):
    """Elides the objective with this (final) linear layer."""
    assert self._b is not None, 'Last layer must have a bias.'
    if target_strategy is None:

      w, b = common.targeted_objective(self._w, self._b, labels)