# Path: deeppy/feedforward/convnet_layers.py
# def padding(win_shape, border_mode):
#     if border_mode == 'valid':
#         return (0, 0)
#     elif border_mode == 'same':
#         return (win_shape[0]//2, win_shape[1]//2)
#     elif border_mode == 'full':
#         return (win_shape[0]-1, win_shape[1]-1)
#     else:
#         raise ValueError('invalid mode: "%s"' % border_mode)


import itertools
import numpy as np
import cudarray as ca
import deeppy as dp
from random import shuffle
from deeppy.feedforward.convnet_layers import padding
from test_layers import check_grad, check_params


batch_sizes = [1, 4, 5]
n_channels = [1, 3, 8]
img_shapes = [(1, 6), (6, 1), (7, 7), (8, 8), (9, 5)]


def shuffled(l):
    l = list(l)
    shuffle(l)
    return l


def img_out_shape(img_shape, win_shape, stride, border_mode):
    pad = padding(win_shape, border_mode)
    h = (img_shape[0] + 2*pad[0] - win_shape[0]) // stride[0] + 1
    w = (img_shape[1] + 2*pad[1] - win_shape[1]) // stride[1] + 1
    return h, w


def test_convolution():
    n_filters = [1, 5, 10]
    win_shapes = [(1, 1), (3, 3), (5, 5)]
    strides = [(1, 1), (2, 2), (3, 3)]

# Path: deeppy/feedforward/convnet_layers.py
# def padding(win_shape, border_mode):
#     if border_mode == 'valid':
#         return (0, 0)
#     elif border_mode == 'same':
#         return (win_shape[0]//2, win_shape[1]//2)
#     elif border_mode == 'full':
#         return (win_shape[0]-1, win_shape[1]-1)
#     else:
#         raise ValueError('invalid mode: "%s"' % border_mode)


# Path: test/unit/feedforward/test_convnet_layers.py
import itertools
import numpy as np
import cudarray as ca
import deeppy as dp
from random import shuffle
from deeppy.feedforward.convnet_layers import padding
from test_layers import check_grad, check_params



batch_sizes = [1, 4, 5]
n_channels = [1, 3, 8]
img_shapes = [(1, 6), (6, 1), (7, 7), (8, 8), (9, 5)]


def shuffled(l):
    l = list(l)
    shuffle(l)
    return l


def img_out_shape(img_shape, win_shape, stride, border_mode):
    pad = padding(win_shape, border_mode)
    h = (img_shape[0] + 2*pad[0] - win_shape[0]) // stride[0] + 1
    w = (img_shape[1] + 2*pad[1] - win_shape[1]) // stride[1] + 1
    return h, w


def test_convolution():
    n_filters = [1, 5, 10]
    win_shapes = [(1, 1), (3, 3), (5, 5)]
    strides = [(1, 1), (2, 2), (3, 3)]

    border_modes = ['valid', 'same', 'full']