Repository: chainer/chainer

Issue:
VariableNode.shape is None although Parameter.initialize is called.
The following code returns `None` with the latest version of Chainer. (3.0.0b1, 034c4c596)

```py
a = chainer.Parameter()
a.initialize((1, 1))
print(a.node.shape) # returns None
```

It causes an internal error by running the following code.

```py
import chainer
from chainer import computational_graph as c

def main():
    a = chainer.Parameter()
    b = chainer.Parameter()
    a.initialize((1, 1))
    b.initialize((1, 1))
    vs = a + b
    g = c.build_computational_graph(vs)
    g.dump()

if __name__ == '__main__':
    main()
```

```
Traceback (most recent call last):
  File "poc.py", line 16, in <module>
    main()
  File "poc.py", line 12, in main
    g.dump()
  File "/home/igarashi/.pyenv/versions/3.6.1/lib/python3.6/site-packages/chainer-3.0.0b1-py3.6.egg/chainer/computational_graph.py", line 164, in dump
    return self._to_dot()
  File "/home/igarashi/.pyenv/versions/3.6.1/lib/python3.6/site-packages/chainer-3.0.0b1-py3.6.egg/chainer/computational_graph.py", line 120, in _to_dot
    node, self.variable_style, self.show_name).label
  File "/home/igarashi/.pyenv/versions/3.6.1/lib/python3.6/site-packages/chainer-3.0.0b1-py3.6.egg/chainer/computational_graph.py", line 29, in __init__
    self.attribute = {'label': node.label}
  File "/home/igarashi/.pyenv/versions/3.6.1/lib/python3.6/site-packages/chainer-3.0.0b1-py3.6.egg/chainer/variable.py", line 280, in label
    return '(%s), %s' % (', '.join(map(str, self.shape)),
TypeError: 'NoneType' object is not iterable

If you suspect this is an IPython bug, please report it at:
    https://github.com/ipython/ipython/issues
or send an email to the mailing list at ipython-dev@python.org

You can print a more detailed traceback right now with "%tb", or use "%debug"
to interactively debug it.

Extra-detailed tracebacks for bug-reporting purposes can be enabled via:
    %config Application.verbose_crash=True
```



Discussion:

Resolving patch:
diff --git a/chainer/variable.py b/chainer/variable.py
--- a/chainer/variable.py
+++ b/chainer/variable.py
@@ -1189,7 +1189,7 @@ def initialize(self, shape):
             grad = None if ginit is None else initializers.generate_array(
                 ginit, shape, xp)
 
-        self._data[0] = data
+        self.data = data
         self.grad = grad
 
     def update(self):


Test patch:
diff --git a/tests/chainer_tests/test_variable.py b/tests/chainer_tests/test_variable.py
--- a/tests/chainer_tests/test_variable.py
+++ b/tests/chainer_tests/test_variable.py
@@ -757,6 +757,13 @@ def test_initialize_dtype(self):
         self.assertEqual(x.data.dtype, np.float64)
         self.assertEqual(x.grad.dtype, np.float64)
 
+    def test_initialize_node(self):
+        initializer = initializers.Zero(np.float64)
+        x = chainer.Parameter(initializer=initializer)
+        x.initialize((2, 3))
+        self.assertEqual(x.node.shape, (2, 3))
+        self.assertEqual(x.node.dtype, np.float64)
+
     @attr.gpu
     def test_initialize_to_gpu(self):
         x = chainer.Parameter(initializer=initializers.Constant(self.a))