We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Orthogonal initializer dimensions error
Orthogonal Initializer throws an error whenever the first dimension is larger than the second. This could be fixed by transposing the array rather than throwing an error.


e.g. 1. ` dense = L.Linear(64,128, initialW=initializers.Orthogonal())`
![image](https://user-images.githubusercontent.com/7952854/46913383-cd7d3380-cf83-11e8-86c5-4cfe5b6d99c2.png)



e.g. 2 `initializers.generate_array(initializers.Orthogonal(), (20,10), numpy, 'f')`
![image](https://user-images.githubusercontent.com/7952854/46913407-3d8bb980-cf84-11e8-9773-3e3a3c38ac76.png)



System Info:
Chainer: 5.0.0rc1
NumPy: 1.14.2
CuPy:
  CuPy Version          : 5.0.0rc1
  CUDA Root             : /usr/local/cuda
  CUDA Build Version    : 8000
  CUDA Driver Version   : 9020
  CUDA Runtime Version  : 8000
  cuDNN Build Version   : 7102
  cuDNN Version         : 7102
  NCCL Build Version    : 2213


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `chainer/initializers/orthogonal.py`
Content:
```
1 import numpy
2 
3 from chainer import backend
4 from chainer import initializer
5 from chainer import utils
6 
7 
8 # Original code forked from MIT licensed keras project
9 # https://github.com/fchollet/keras/blob/master/keras/initializations.py
10 
11 class Orthogonal(initializer.Initializer):
12     """Initializes array with an orthogonal system.
13 
14     This initializer first makes a matrix of the same shape as the
15     array to be initialized whose elements are drawn independently from
16     standard Gaussian distribution.
17     Next, it applies QR decomposition to (the transpose of) the matrix.
18     To make the decomposition (almost surely) unique, we require the diagonal
19     of the triangular matrix R to be non-negative (see e.g. Edelman & Rao,
20     https://web.eecs.umich.edu/~rajnrao/Acta05rmt.pdf).
21     Then, it initializes the array with the (semi-)orthogonal matrix Q.
22     Finally, the array is multiplied by the constant ``scale``.
23 
24     If the ``ndim`` of the input array is more than 2, we consider the array
25     to be a matrix by concatenating all axes except the first one.
26 
27     The number of vectors consisting of the orthogonal system
28     (i.e. first element of the shape of the array) must be equal to or smaller
29     than the dimension of each vector (i.e. second element of the shape of
30     the array).
31 
32     Attributes:
33         scale (float): A constant to be multiplied by.
34         dtype: Data type specifier.
35 
36     Reference: Saxe et al., https://arxiv.org/abs/1312.6120
37 
38     """
39 
40     def __init__(self, scale=1.1, dtype=None):
41         self.scale = scale
42         super(Orthogonal, self).__init__(dtype)
43 
44     # TODO(Kenta Oono)
45     # How do we treat overcomplete base-system case?
46     def __call__(self, array):
47         if self.dtype is not None:
48             assert array.dtype == self.dtype
49         xp = backend.get_array_module(array)
50         if not array.shape:  # 0-dim case
51             array[...] = self.scale * (2 * numpy.random.randint(2) - 1)
52         elif not array.size:
53             raise ValueError('Array to be initialized must be non-empty.')
54         else:
55             # numpy.prod returns float value when the argument is empty.
56             flat_shape = (len(array), utils.size_of_shape(array.shape[1:]))
57             if flat_shape[0] > flat_shape[1]:
58                 raise ValueError('Cannot make orthogonal system because'
59                                  ' # of vectors ({}) is larger than'
60                                  ' that of dimensions ({})'.format(
61                                      flat_shape[0], flat_shape[1]))
62             a = numpy.random.normal(size=flat_shape)
63             # cupy.linalg.qr requires cusolver in CUDA 8+
64             q, r = numpy.linalg.qr(a.T)
65             q *= numpy.copysign(self.scale, numpy.diag(r))
66             array[...] = xp.asarray(q.T.reshape(array.shape))
67
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/chainer/initializers/orthogonal.py b/chainer/initializers/orthogonal.py
--- a/chainer/initializers/orthogonal.py
+++ b/chainer/initializers/orthogonal.py
@@ -5,6 +5,14 @@
 from chainer import utils
 
 
+_orthogonal_constraints = {  # (assert emb., assert proj.)
+    'auto': (False, False),
+    'projection': (False, True),
+    'embedding': (True, False),
+    'basis': (True, True),
+}
+
+
 # Original code forked from MIT licensed keras project
 # https://github.com/fchollet/keras/blob/master/keras/initializations.py
 
@@ -32,13 +40,24 @@
     Attributes:
         scale (float): A constant to be multiplied by.
         dtype: Data type specifier.
+        mode (str): Assertion on the initialized shape.
+            ``'auto'`` (default), ``'projection'`` (before v7),
+            ``'embedding'``, or ``'basis'``.
 
     Reference: Saxe et al., https://arxiv.org/abs/1312.6120
 
     """
 
-    def __init__(self, scale=1.1, dtype=None):
+    def __init__(self, scale=1.1, dtype=None, mode='auto'):
         self.scale = scale
+        self.mode = mode
+        try:
+            self._checks = _orthogonal_constraints[mode]
+        except KeyError:
+            raise ValueError(
+                'Invalid mode: {}. Choose from {}.'.format(
+                    repr(mode),
+                    ', '.join(repr(m) for m in _orthogonal_constraints)))
         super(Orthogonal, self).__init__(dtype)
 
     # TODO(Kenta Oono)
@@ -53,14 +72,22 @@
             raise ValueError('Array to be initialized must be non-empty.')
         else:
             # numpy.prod returns float value when the argument is empty.
-            flat_shape = (len(array), utils.size_of_shape(array.shape[1:]))
-            if flat_shape[0] > flat_shape[1]:
-                raise ValueError('Cannot make orthogonal system because'
-                                 ' # of vectors ({}) is larger than'
-                                 ' that of dimensions ({})'.format(
-                                     flat_shape[0], flat_shape[1]))
-            a = numpy.random.normal(size=flat_shape)
+            out_dim = len(array)
+            in_dim = utils.size_of_shape(array.shape[1:])
+            if (in_dim > out_dim and self._checks[0]) or (
+                    in_dim < out_dim and self._checks[1]):
+                raise ValueError(
+                    'Cannot make orthogonal {}.'
+                    'shape = {}, interpreted as '
+                    '{}-dim input and {}-dim output.'.format(
+                        self.mode, array.shape, in_dim, out_dim))
+            transpose = in_dim > out_dim
+            a = numpy.random.normal(size=(out_dim, in_dim))
+            if transpose:
+                a = a.T
             # cupy.linalg.qr requires cusolver in CUDA 8+
-            q, r = numpy.linalg.qr(a.T)
+            q, r = numpy.linalg.qr(a)
             q *= numpy.copysign(self.scale, numpy.diag(r))
-            array[...] = xp.asarray(q.T.reshape(array.shape))
+            if transpose:
+                q = q.T
+            array[...] = xp.asarray(q.reshape(array.shape))

{"golden_diff": "diff --git a/chainer/initializers/orthogonal.py b/chainer/initializers/orthogonal.py\n--- a/chainer/initializers/orthogonal.py\n+++ b/chainer/initializers/orthogonal.py\n@@ -5,6 +5,14 @@\n from chainer import utils\n \n \n+_orthogonal_constraints = {  # (assert emb., assert proj.)\n+    'auto': (False, False),\n+    'projection': (False, True),\n+    'embedding': (True, False),\n+    'basis': (True, True),\n+}\n+\n+\n # Original code forked from MIT licensed keras project\n # https://github.com/fchollet/keras/blob/master/keras/initializations.py\n \n@@ -32,13 +40,24 @@\n     Attributes:\n         scale (float): A constant to be multiplied by.\n         dtype: Data type specifier.\n+        mode (str): Assertion on the initialized shape.\n+            ``'auto'`` (default), ``'projection'`` (before v7),\n+            ``'embedding'``, or ``'basis'``.\n \n     Reference: Saxe et al., https://arxiv.org/abs/1312.6120\n \n     \"\"\"\n \n-    def __init__(self, scale=1.1, dtype=None):\n+    def __init__(self, scale=1.1, dtype=None, mode='auto'):\n         self.scale = scale\n+        self.mode = mode\n+        try:\n+            self._checks = _orthogonal_constraints[mode]\n+        except KeyError:\n+            raise ValueError(\n+                'Invalid mode: {}. Choose from {}.'.format(\n+                    repr(mode),\n+                    ', '.join(repr(m) for m in _orthogonal_constraints)))\n         super(Orthogonal, self).__init__(dtype)\n \n     # TODO(Kenta Oono)\n@@ -53,14 +72,22 @@\n             raise ValueError('Array to be initialized must be non-empty.')\n         else:\n             # numpy.prod returns float value when the argument is empty.\n-            flat_shape = (len(array), utils.size_of_shape(array.shape[1:]))\n-            if flat_shape[0] > flat_shape[1]:\n-                raise ValueError('Cannot make orthogonal system because'\n-                                 ' # of vectors ({}) is larger than'\n-                                 ' that of dimensions ({})'.format(\n-                                     flat_shape[0], flat_shape[1]))\n-            a = numpy.random.normal(size=flat_shape)\n+            out_dim = len(array)\n+            in_dim = utils.size_of_shape(array.shape[1:])\n+            if (in_dim > out_dim and self._checks[0]) or (\n+                    in_dim < out_dim and self._checks[1]):\n+                raise ValueError(\n+                    'Cannot make orthogonal {}.'\n+                    'shape = {}, interpreted as '\n+                    '{}-dim input and {}-dim output.'.format(\n+                        self.mode, array.shape, in_dim, out_dim))\n+            transpose = in_dim > out_dim\n+            a = numpy.random.normal(size=(out_dim, in_dim))\n+            if transpose:\n+                a = a.T\n             # cupy.linalg.qr requires cusolver in CUDA 8+\n-            q, r = numpy.linalg.qr(a.T)\n+            q, r = numpy.linalg.qr(a)\n             q *= numpy.copysign(self.scale, numpy.diag(r))\n-            array[...] = xp.asarray(q.T.reshape(array.shape))\n+            if transpose:\n+                q = q.T\n+            array[...] = xp.asarray(q.reshape(array.shape))\n", "issue": "Orthogonal initializer dimensions error\nOrthogonal Initializer throws an error whenever the first dimension is larger than the second. This could be fixed by transposing the array rather than throwing an error.\r\n\r\n\r\ne.g. 1. ` dense = L.Linear(64,128, initialW=initializers.Orthogonal())`\r\n![image](https://user-images.githubusercontent.com/7952854/46913383-cd7d3380-cf83-11e8-86c5-4cfe5b6d99c2.png)\r\n\r\n\r\n\r\ne.g. 2 `initializers.generate_array(initializers.Orthogonal(), (20,10), numpy, 'f')`\r\n![image](https://user-images.githubusercontent.com/7952854/46913407-3d8bb980-cf84-11e8-9773-3e3a3c38ac76.png)\r\n\r\n\r\n\r\nSystem Info:\r\nChainer: 5.0.0rc1\r\nNumPy: 1.14.2\r\nCuPy:\r\n  CuPy Version          : 5.0.0rc1\r\n  CUDA Root             : /usr/local/cuda\r\n  CUDA Build Version    : 8000\r\n  CUDA Driver Version   : 9020\r\n  CUDA Runtime Version  : 8000\r\n  cuDNN Build Version   : 7102\r\n  cuDNN Version         : 7102\r\n  NCCL Build Version    : 2213\r\n\n", "before_files": [{"content": "import numpy\n\nfrom chainer import backend\nfrom chainer import initializer\nfrom chainer import utils\n\n\n# Original code forked from MIT licensed keras project\n# https://github.com/fchollet/keras/blob/master/keras/initializations.py\n\nclass Orthogonal(initializer.Initializer):\n    \"\"\"Initializes array with an orthogonal system.\n\n    This initializer first makes a matrix of the same shape as the\n    array to be initialized whose elements are drawn independently from\n    standard Gaussian distribution.\n    Next, it applies QR decomposition to (the transpose of) the matrix.\n    To make the decomposition (almost surely) unique, we require the diagonal\n    of the triangular matrix R to be non-negative (see e.g. Edelman & Rao,\n    https://web.eecs.umich.edu/~rajnrao/Acta05rmt.pdf).\n    Then, it initializes the array with the (semi-)orthogonal matrix Q.\n    Finally, the array is multiplied by the constant ``scale``.\n\n    If the ``ndim`` of the input array is more than 2, we consider the array\n    to be a matrix by concatenating all axes except the first one.\n\n    The number of vectors consisting of the orthogonal system\n    (i.e. first element of the shape of the array) must be equal to or smaller\n    than the dimension of each vector (i.e. second element of the shape of\n    the array).\n\n    Attributes:\n        scale (float): A constant to be multiplied by.\n        dtype: Data type specifier.\n\n    Reference: Saxe et al., https://arxiv.org/abs/1312.6120\n\n    \"\"\"\n\n    def __init__(self, scale=1.1, dtype=None):\n        self.scale = scale\n        super(Orthogonal, self).__init__(dtype)\n\n    # TODO(Kenta Oono)\n    # How do we treat overcomplete base-system case?\n    def __call__(self, array):\n        if self.dtype is not None:\n            assert array.dtype == self.dtype\n        xp = backend.get_array_module(array)\n        if not array.shape:  # 0-dim case\n            array[...] = self.scale * (2 * numpy.random.randint(2) - 1)\n        elif not array.size:\n            raise ValueError('Array to be initialized must be non-empty.')\n        else:\n            # numpy.prod returns float value when the argument is empty.\n            flat_shape = (len(array), utils.size_of_shape(array.shape[1:]))\n            if flat_shape[0] > flat_shape[1]:\n                raise ValueError('Cannot make orthogonal system because'\n                                 ' # of vectors ({}) is larger than'\n                                 ' that of dimensions ({})'.format(\n                                     flat_shape[0], flat_shape[1]))\n            a = numpy.random.normal(size=flat_shape)\n            # cupy.linalg.qr requires cusolver in CUDA 8+\n            q, r = numpy.linalg.qr(a.T)\n            q *= numpy.copysign(self.scale, numpy.diag(r))\n            array[...] = xp.asarray(q.T.reshape(array.shape))\n", "path": "chainer/initializers/orthogonal.py"}], "after_files": [{"content": "import numpy\n\nfrom chainer import backend\nfrom chainer import initializer\nfrom chainer import utils\n\n\n_orthogonal_constraints = {  # (assert emb., assert proj.)\n    'auto': (False, False),\n    'projection': (False, True),\n    'embedding': (True, False),\n    'basis': (True, True),\n}\n\n\n# Original code forked from MIT licensed keras project\n# https://github.com/fchollet/keras/blob/master/keras/initializations.py\n\nclass Orthogonal(initializer.Initializer):\n    \"\"\"Initializes array with an orthogonal system.\n\n    This initializer first makes a matrix of the same shape as the\n    array to be initialized whose elements are drawn independently from\n    standard Gaussian distribution.\n    Next, it applies QR decomposition to (the transpose of) the matrix.\n    To make the decomposition (almost surely) unique, we require the diagonal\n    of the triangular matrix R to be non-negative (see e.g. Edelman & Rao,\n    https://web.eecs.umich.edu/~rajnrao/Acta05rmt.pdf).\n    Then, it initializes the array with the (semi-)orthogonal matrix Q.\n    Finally, the array is multiplied by the constant ``scale``.\n\n    If the ``ndim`` of the input array is more than 2, we consider the array\n    to be a matrix by concatenating all axes except the first one.\n\n    The number of vectors consisting of the orthogonal system\n    (i.e. first element of the shape of the array) must be equal to or smaller\n    than the dimension of each vector (i.e. second element of the shape of\n    the array).\n\n    Attributes:\n        scale (float): A constant to be multiplied by.\n        dtype: Data type specifier.\n        mode (str): Assertion on the initialized shape.\n            ``'auto'`` (default), ``'projection'`` (before v7),\n            ``'embedding'``, or ``'basis'``.\n\n    Reference: Saxe et al., https://arxiv.org/abs/1312.6120\n\n    \"\"\"\n\n    def __init__(self, scale=1.1, dtype=None, mode='auto'):\n        self.scale = scale\n        self.mode = mode\n        try:\n            self._checks = _orthogonal_constraints[mode]\n        except KeyError:\n            raise ValueError(\n                'Invalid mode: {}. Choose from {}.'.format(\n                    repr(mode),\n                    ', '.join(repr(m) for m in _orthogonal_constraints)))\n        super(Orthogonal, self).__init__(dtype)\n\n    # TODO(Kenta Oono)\n    # How do we treat overcomplete base-system case?\n    def __call__(self, array):\n        if self.dtype is not None:\n            assert array.dtype == self.dtype\n        xp = backend.get_array_module(array)\n        if not array.shape:  # 0-dim case\n            array[...] = self.scale * (2 * numpy.random.randint(2) - 1)\n        elif not array.size:\n            raise ValueError('Array to be initialized must be non-empty.')\n        else:\n            # numpy.prod returns float value when the argument is empty.\n            out_dim = len(array)\n            in_dim = utils.size_of_shape(array.shape[1:])\n            if (in_dim > out_dim and self._checks[0]) or (\n                    in_dim < out_dim and self._checks[1]):\n                raise ValueError(\n                    'Cannot make orthogonal {}.'\n                    'shape = {}, interpreted as '\n                    '{}-dim input and {}-dim output.'.format(\n                        self.mode, array.shape, in_dim, out_dim))\n            transpose = in_dim > out_dim\n            a = numpy.random.normal(size=(out_dim, in_dim))\n            if transpose:\n                a = a.T\n            # cupy.linalg.qr requires cusolver in CUDA 8+\n            q, r = numpy.linalg.qr(a)\n            q *= numpy.copysign(self.scale, numpy.diag(r))\n            if transpose:\n                q = q.T\n            array[...] = xp.asarray(q.reshape(array.shape))\n", "path": "chainer/initializers/orthogonal.py"}]}