Repository: chainer/chainer

Issue:
Remove Parameter link
`chainer.links.Parameter` link is deprecated and should be dropped in v2.


Discussion:

Resolving patch:
diff --git a/chainer/functions/__init__.py b/chainer/functions/__init__.py
--- a/chainer/functions/__init__.py
+++ b/chainer/functions/__init__.py
@@ -373,7 +373,6 @@
 from chainer.links.connection.inception import Inception  # NOQA
 from chainer.links.connection.inceptionbn import InceptionBN  # NOQA
 from chainer.links.connection.linear import Linear  # NOQA
-from chainer.links.connection.parameter import Parameter  # NOQA
 
 from chainer.links.loss.hierarchical_softmax import BinaryHierarchicalSoftmax  # NOQA
 from chainer.links.loss.negative_sampling import NegativeSampling  # NOQA
diff --git a/chainer/links/__init__.py b/chainer/links/__init__.py
--- a/chainer/links/__init__.py
+++ b/chainer/links/__init__.py
@@ -18,7 +18,6 @@
 from chainer.links.connection import lstm  # NOQA
 from chainer.links.connection import mlp_convolution_2d  # NOQA
 from chainer.links.connection import n_step_lstm  # NOQA
-from chainer.links.connection import parameter  # NOQA
 from chainer.links.connection import peephole  # NOQA
 from chainer.links.connection import scale  # NOQA
 from chainer.links.connection import zoneoutlstm  # NOQA
@@ -53,7 +52,6 @@
 from chainer.links.connection.lstm import StatelessLSTM  # NOQA
 from chainer.links.connection.mlp_convolution_2d import MLPConvolution2D  # NOQA
 from chainer.links.connection.n_step_lstm import NStepLSTM  # NOQA
-from chainer.links.connection.parameter import Parameter  # NOQA
 from chainer.links.connection.peephole import StatefulPeepholeLSTM  # NOQA
 from chainer.links.connection.scale import Scale  # NOQA
 from chainer.links.connection.zoneoutlstm import StatefulZoneoutLSTM  # NOQA
diff --git a/chainer/links/connection/parameter.py b/chainer/links/connection/parameter.py
deleted file mode 100644
--- a/chainer/links/connection/parameter.py
+++ /dev/null
@@ -1,44 +0,0 @@
-from chainer import cuda
-from chainer.functions.math import identity
-from chainer import link
-
-
-class Parameter(link.Link):
-
-    """Link that just holds a parameter and returns it.
-
-    .. deprecated:: v1.5
-       The parameters are stored as variables as of v1.5. Use them directly
-       instead.
-
-    Args:
-        array: Initial parameter array.
-
-    Attributes:
-        W (~chainer.Variable): Parameter variable.
-
-    """
-
-    def __init__(self, array):
-        super(Parameter, self).__init__()
-        self.add_param('W', array.shape, dtype=array.dtype)
-        self.W.data = array
-        if isinstance(array, cuda.ndarray):
-            self.to_gpu(array)
-
-    def __call__(self, volatile='off'):
-        """Returns the parameter variable.
-
-        Args:
-            volatile (~chainer.Flag): The volatility of the returned variable.
-
-        Returns:
-            ~chainer.Variable: A copy of the parameter variable with given
-            volatility.
-
-        """
-        # The first identity creates a copy of W, and the second identity cuts
-        # the edge if volatility is ON
-        W = identity.identity(self.W)
-        W.volatile = volatile
-        return identity.identity(W)


Test patch:
diff --git a/tests/chainer_tests/links_tests/connection_tests/test_parameter.py b/tests/chainer_tests/links_tests/connection_tests/test_parameter.py
deleted file mode 100644
--- a/tests/chainer_tests/links_tests/connection_tests/test_parameter.py
+++ /dev/null
@@ -1,131 +0,0 @@
-import unittest
-
-import numpy
-
-from chainer import cuda
-from chainer import links
-from chainer import testing
-from chainer.testing import attr
-
-
-class TestParameter(unittest.TestCase):
-
-    def setUp(self):
-        self.W = numpy.random.uniform(-1, 1, (4, 3)).astype(numpy.float32)
-        self.gW = numpy.random.uniform(-1, 1,
-                                       self.W.shape).astype(numpy.float32)
-        self.link = links.Parameter(self.W)
-        self.link.zerograds()
-
-    def tearDown(self):
-        del self.link
-
-    def to_gpu(self):
-        self.link.to_gpu()
-
-    def check_forward(self, volatile):
-        y = self.link(volatile)
-        self.assertEqual(y.data.dtype, numpy.float32)
-        self.assertTrue((self.W == cuda.to_cpu(y.data)).all())
-
-    def test_forward_cpu(self):
-        self.check_forward(False)
-
-    def test_forward_cpu_volatile(self):
-        self.check_forward(True)
-
-    @attr.gpu
-    def test_forward_gpu(self):
-        self.to_gpu()
-        self.check_forward(False)
-
-    @attr.gpu
-    def test_forward_gpu_volatile(self):
-        self.to_gpu()
-        self.check_forward(True)
-
-    def check_backward(self, y_grad, volatile):
-        y = self.link(volatile)
-        y.grad = y_grad
-        y.backward()
-        if volatile:
-            self.assertTrue(
-                (cuda.to_cpu(self.link.W.grad) ==
-                 numpy.zeros(y_grad.shape, dtype=y_grad.dtype)).all())
-        else:
-            self.assertTrue(
-                (cuda.to_cpu(self.link.W.grad) == cuda.to_cpu(y_grad)).all())
-
-    def test_backward_cpu(self):
-        self.check_backward(self.gW, False)
-
-    def test_backward_cpu_volatile(self):
-        self.check_backward(self.gW, True)
-
-    @attr.gpu
-    def test_backward_gpu(self):
-        self.to_gpu()
-        self.check_backward(cuda.to_gpu(self.gW), False)
-
-    @attr.gpu
-    def test_backward_gpu_volatile(self):
-        self.to_gpu()
-        self.check_backward(cuda.to_gpu(self.gW), True)
-
-
-class TestVolatile(unittest.TestCase):
-
-    def setUp(self):
-        self.W = numpy.random.uniform(-1, 1, (4, 3)).astype(numpy.float32)
-        self.link = links.Parameter(self.W)
-
-    def tearDown(self):
-        del self.link
-
-    def check_volatile(self, volatile):
-        y = self.link(volatile=volatile)
-        self.assertEqual(y.volatile, volatile)
-
-    def test_volatile_cpu_volatile(self):
-        self.check_volatile(True)
-
-    def test_volatile_cpu_not_volatile(self):
-        self.check_volatile(False)
-
-    @attr.gpu
-    def test_volatile_gpu_volatile(self):
-        self.link.to_gpu()
-        self.check_volatile(True)
-
-    @attr.gpu
-    def test_volatile_gpu_not_volatile(self):
-        self.link.to_gpu()
-        self.check_volatile(False)
-
-
-class TestInit(unittest.TestCase):
-
-    def setUp(self):
-        self.W = numpy.random.uniform(-1, 1, (2, 3)).astype(numpy.float32)
-        self.p = links.Parameter(self.W)
-
-    def check(self, p, xp):
-        self.assertIsInstance(p.W.data, xp.ndarray)
-        self.assertIsInstance(p.W.grad, xp.ndarray)
-
-    def test_cpu(self):
-        self.check(self.p, numpy)
-
-    @attr.gpu
-    def test_gpu_initialize_by_numpy_ndarray(self):
-        self.p.to_gpu()
-        self.check(self.p, cuda.cupy)
-
-    @attr.gpu
-    def test_gpu_initialize_by_cupy_ndarray(self):
-        W = cuda.to_gpu(self.W)
-        p = links.Parameter(W)
-        self.check(p, cuda.cupy)
-
-
-testing.run_module(__name__, __file__)