# Path: deep_verify/src/formulations/semidefinite/gram_calcs.py
# def conv_weighted_gram_matrix(w, d, input_shape, padding, strides,
#                               w_s=None):
# def _conv_projection_slice(w, d, w_s, beta, padding, strides,
#                            abs_fn=tf.abs):
# def conv_weighted_gram_abs_projection(w, d, beta, padding, strides,
#                                       abs_fn=tf.abs,
#                                       block_size=0):
# def _linear_projection_slice(w, d, w_s, beta, abs_fn=tf.abs):
# def linear_weighted_gram_abs_projection(w, d, beta,
#                                         abs_fn=tf.abs,
#                                         block_size=0):


from absl.testing import parameterized
from deep_verify.src.formulations.semidefinite import gram_calcs
from interval_bound_propagation import layer_utils
import sonnet as snt
import tensorflow as tf
      ('SAME', (7, 17), (3, 3), (7, 17), 'SAME', [1, 1]),
      ('SAME_even', (7, 17), (2, 2), (7, 17), 'SAME', [1, 1]),
      ('SAME_strided', (7, 17), (3, 4), (4, 9), 'SAME', [2, 2]),
      ('SAME_blocked', (7, 11), (3, 3), (7, 11), 'SAME', [1, 1],
       tf.float32, 1.e-5, 4),
      ('VALID_32', (7, 11), (3, 3), (5, 9), 'VALID', [1, 1], tf.float32, 1.e-5),
      ('VALID', (7, 17), (3, 3), (5, 15), 'VALID', [1, 1]),
      ('VALID_even', (7, 17), (2, 2), (6, 16), 'VALID', [1, 1]),
      ('VALID_strided', (7, 17), (3, 4), (3, 7), 'VALID', [2, 2]))
  def test_conv2d_weighted_gram(self, input_size, kernel_size, output_size,
                                padding, strides,
                                dtype=tf.float64, atol=1.e-9, block_size=0):
    num_targets = 3
    batch_size = 2
    input_height, input_width = input_size
    kernel_height, kernel_width = kernel_size
    input_channels = 13
    output_height, output_width = output_size
    output_channels = 11

    w = tf.random_normal(dtype=dtype,
                         shape=[kernel_height, kernel_width,
                                input_channels, output_channels])
    d = tf.random_gamma(alpha=1, dtype=dtype,
                        shape=[num_targets, batch_size,
                               output_height, output_width, output_channels])
    beta = tf.random_gamma(alpha=1, dtype=dtype,
                           shape=[num_targets, batch_size,
                                  input_height, input_width, input_channels])


# Path: deep_verify/src/formulations/semidefinite/gram_calcs.py
# def conv_weighted_gram_matrix(w, d, input_shape, padding, strides,
#                               w_s=None):
# def _conv_projection_slice(w, d, w_s, beta, padding, strides,
#                            abs_fn=tf.abs):
# def conv_weighted_gram_abs_projection(w, d, beta, padding, strides,
#                                       abs_fn=tf.abs,
#                                       block_size=0):
# def _linear_projection_slice(w, d, w_s, beta, abs_fn=tf.abs):
# def linear_weighted_gram_abs_projection(w, d, beta,
#                                         abs_fn=tf.abs,
#                                         block_size=0):


# Path: deep_verify/tests/formulations/semidefinite/gram_calcs_test.py
from absl.testing import parameterized
from deep_verify.src.formulations.semidefinite import gram_calcs
from interval_bound_propagation import layer_utils
import sonnet as snt
import tensorflow as tf

      ('SAME', (7, 17), (3, 3), (7, 17), 'SAME', [1, 1]),
      ('SAME_even', (7, 17), (2, 2), (7, 17), 'SAME', [1, 1]),
      ('SAME_strided', (7, 17), (3, 4), (4, 9), 'SAME', [2, 2]),
      ('SAME_blocked', (7, 11), (3, 3), (7, 11), 'SAME', [1, 1],
       tf.float32, 1.e-5, 4),
      ('VALID_32', (7, 11), (3, 3), (5, 9), 'VALID', [1, 1], tf.float32, 1.e-5),
      ('VALID', (7, 17), (3, 3), (5, 15), 'VALID', [1, 1]),
      ('VALID_even', (7, 17), (2, 2), (6, 16), 'VALID', [1, 1]),
      ('VALID_strided', (7, 17), (3, 4), (3, 7), 'VALID', [2, 2]))
  def test_conv2d_weighted_gram(self, input_size, kernel_size, output_size,
                                padding, strides,
                                dtype=tf.float64, atol=1.e-9, block_size=0):
    num_targets = 3
    batch_size = 2
    input_height, input_width = input_size
    kernel_height, kernel_width = kernel_size
    input_channels = 13
    output_height, output_width = output_size
    output_channels = 11

    w = tf.random_normal(dtype=dtype,
                         shape=[kernel_height, kernel_width,
                                input_channels, output_channels])
    d = tf.random_gamma(alpha=1, dtype=dtype,
                        shape=[num_targets, batch_size,
                               output_height, output_width, output_channels])
    beta = tf.random_gamma(alpha=1, dtype=dtype,
                           shape=[num_targets, batch_size,
                                  input_height, input_width, input_channels])


    proj = gram_calcs.conv_weighted_gram_abs_projection(w, d, beta,