import unittest

import numpy

import chainer
from chainer import functions
from chainer import links
from chainer import testing


@testing.parameterize(
    {'use_cudnn': True},
    {'use_cudnn': False},
)
class TestMLPConvolution2D(unittest.TestCase):

    def setUp(self):
        self.mlp = links.MLPConvolution2D(
            3, (96, 96, 96), 11,
            activation=functions.sigmoid,
            use_cudnn=self.use_cudnn)
        self.x = numpy.zeros((10, 3, 20, 20), dtype=numpy.float32)

    def test_init(self):
        self.assertIs(self.mlp.activation, functions.sigmoid)

        self.assertEqual(len(self.mlp), 3)
        for i, conv in enumerate(self.mlp):
            self.assertIsInstance(conv, links.Convolution2D)
            self.assertEqual(conv.use_cudnn, self.use_cudnn)
            if i == 0:
                self.assertEqual(conv.W.data.shape, (96, 3, 11, 11))
            else:
                self.assertEqual(conv.W.data.shape, (96, 96, 1, 1))

    def check_call(self, x_data):
        x = chainer.Variable(x_data)
        actual = self.mlp(x)
        act = functions.sigmoid
        expect = self.mlp[2](act(self.mlp[1](act(self.mlp[0](x)))))
        cuda.cupy.testing.assert_array_equal(expect.data, actual.data)

    def test_call_cpu(self):
        self.check_call(self.x)

    @attr.gpu
    def test_call_gpu(self):
        self.mlp.to_gpu()
        self.check_call(cuda.to_gpu(self.x))


testing.run_module(__name__, __file__)

@@ -10,16 +10,28 @@
 ittest%0A%0A
+import mock%0A
 import n
@@ -51,16 +51,41 @@
 chainer%0A
+from chainer import cuda%0A
 from cha
@@ -160,16 +160,49 @@
 testing%0A
+from chainer.testing import attr%0A
 %0A%0A@testi
@@ -1490,16 +1490,1080 @@
 f.x))%0A%0A%0A
+@testing.parameterize(%0A    %7B'use_cudnn': True%7D,%0A    %7B'use_cudnn': False%7D,%0A)%0A@attr.cudnn%0Aclass TestMLPConvolution2DCudnnCall(unittest.TestCase):%0A%0A    def setUp(self):%0A        self.mlp = links.MLPConvolution2D(%0A            3, (96, 96, 96), 11,%0A            activation=functions.sigmoid,%0A            use_cudnn=self.use_cudnn)%0A        self.mlp.to_gpu()%0A        self.x = cuda.cupy.zeros((10, 3, 20, 20), dtype=numpy.float32)%0A        self.gy = cuda.cupy.zeros((10, 96, 10, 10), dtype=numpy.float32)%0A%0A    def forward(self):%0A        x = chainer.Variable(self.x)%0A        return self.mlp(x)%0A%0A    def test_call_cudnn_forward(self):%0A        with mock.patch('cupy.cudnn.cudnn.convolutionForward') as func:%0A            self.forward()%0A            self.assertEqual(func.called, self.use_cudnn)%0A%0A    def test_call_cudnn_backrward(self):%0A        y = self.forward()%0A        print(y.data.shape)%0A        y.grad = self.gy%0A        with mock.patch('cupy.cudnn.cudnn.convolutionBackwardData_v2') as func:%0A            y.backward()%0A            self.assertEqual(func.called, self.use_cudnn)%0A%0A%0A
 testing.

Add cudnn test