Skip to content

Commit

Permalink
Merge pull request #4085 from kmaehashi/avoid-np-stack
Browse files Browse the repository at this point in the history
avoid using np.stack which is introduced in NumPy 1.10
  • Loading branch information
niboshi committed Jan 10, 2018
2 parents e8504de + 3b0e47a commit 5b34928
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
9 changes: 2 additions & 7 deletions chainer/functions/connection/convolution_2d.py
Expand Up @@ -217,9 +217,7 @@ def _forward_grouped_convolution(self, x, W, b):
_y = self._forward_gpu_core(_x[g, ], _W[g, ], _bg)
_ys.append(_y)

y = xp.stack(_ys, axis=1) # (N, G, oCg, oH, oW)
_, _, _, oH, oW = y.shape
y = y.reshape(N, oC, oH, oW)
y = xp.concatenate(_ys, axis=1) # (N, oC, oH, oW)
return y

def _forward_cudnn(self, x, W, b, y):
Expand Down Expand Up @@ -386,8 +384,6 @@ def _forward_grouped_convolution(self, x, gy):
# iC, iH, iW: input channels, input height, input width
# oC, oH, oW: output channels, output height, output width
G = self.group
kH = self.kh
kW = self.kw
N, iC, iH, iW = x.shape
_, oC, oH, oW = gy.shape
iCg = int(iC / G)
Expand All @@ -411,8 +407,7 @@ def _forward_grouped_convolution(self, x, gy):
_gW = self._forward_gpu_core(_x[g, ], _gy[g, ])
_gWs.append(_gW)

gW = xp.stack(_gWs) # (G, oCg, iCg, kH, kW)
gW = gW.reshape(oC, iCg, kH, kW)
gW = xp.concatenate(_gWs) # (oC, iCg, kH, kW)
return gW

def _forward_cudnn(self, x, gy):
Expand Down
6 changes: 1 addition & 5 deletions chainer/functions/connection/deconvolution_2d.py
Expand Up @@ -212,9 +212,6 @@ def _forward_grouped_convolution(self, x, W, b):
N, xC, xH, xW = x.shape
xCg = int(xC / G)
_, yCg, kH, kW = W.shape
yC = yCg * G
yH = self.outh
yW = self.outw

xp = cuda.get_array_module(x)

Expand All @@ -233,8 +230,7 @@ def _forward_grouped_convolution(self, x, W, b):
_y = self._forward_gpu_core(_x[g, ], _W[g, ], _bg)
_ys.append(_y)

y = xp.stack(_ys, axis=1) # (N, G, yCg, yH, yW)
y = y.reshape(N, yC, yH, yW)
y = xp.concatenate(_ys, axis=1) # (N, yC, yH, yW)
return y

def _forward_cudnn(self, x, W, b):
Expand Down

0 comments on commit 5b34928

Please sign in to comment.