Beispiel #1
0
    def test_convolve_filter_adjoint_full(self):
        mode = 'full'
        devices = [backend.cpu_device]
        if config.cupy_enabled:
            devices.append(backend.Device(0))

        for device in devices:
            xp = device.xp
            with device:
                for dtype in dtypes:
                    with self.subTest(dtype=dtype, device=device):
                        data = xp.ones([1, 3], dtype=dtype)
                        output = xp.ones([1, 5], dtype=dtype)
                        filt_shape = [1, 3]
                        filt = backend.to_device(
                            conv.convolve_filter_adjoint(output,
                                                         data,
                                                         filt_shape,
                                                         mode=mode))
                        npt.assert_allclose(filt, [[3, 3, 3]], atol=1e-5)

                        data = xp.ones([1, 3], dtype=dtype)
                        output = xp.ones([1, 4], dtype=dtype)
                        filt_shape = [1, 2]
                        filt = backend.to_device(
                            conv.convolve_filter_adjoint(output,
                                                         data,
                                                         filt_shape,
                                                         mode=mode))
                        npt.assert_allclose(filt, [[3, 3]], atol=1e-5)

                        data = xp.ones([1, 1, 3], dtype=dtype)
                        output = xp.ones([2, 1, 5], dtype=dtype)
                        filt_shape = [2, 1, 1, 3]
                        filt = backend.to_device(
                            conv.convolve_filter_adjoint(output,
                                                         data,
                                                         filt_shape,
                                                         mode=mode,
                                                         multi_channel=True),
                            backend.cpu_device)
                        npt.assert_allclose(filt,
                                            [[[[3, 3, 3]]], [[[3, 3, 3]]]],
                                            atol=1e-5)

                        data = xp.ones([1, 1, 3], dtype=dtype)
                        output = xp.ones([2, 1, 3], dtype=dtype)
                        filt_shape = [2, 1, 1, 3]
                        strides = [1, 2]
                        filt = backend.to_device(
                            conv.convolve_filter_adjoint(output,
                                                         data,
                                                         filt_shape,
                                                         mode=mode,
                                                         strides=strides,
                                                         multi_channel=True),
                            backend.cpu_device)
                        npt.assert_allclose(filt,
                                            [[[[2, 1, 2]]], [[[2, 1, 2]]]],
                                            atol=1e-5)
Beispiel #2
0
 def _apply(self, input):
     return conv.convolve_filter_adjoint(input,
                                         self.data,
                                         self.oshape,
                                         mode=self.mode,
                                         strides=self.strides,
                                         multi_channel=self.multi_channel)
Beispiel #3
0
 def _apply(self, input):
     device = backend.get_device(input)
     data = backend.to_device(self.data, device)
     with device:
         return conv.convolve_filter_adjoint(
             input, data, self.oshape,
             mode=self.mode, strides=self.strides,
             multi_channel=self.multi_channel)