{"action":"opened","issue":{"url":"https://api.github.com/repos/pfnet/chainer/issues/138","labels_url":"https://api.github.com/repos/pfnet/chainer/issues/138/labels{/name}","comments_url":"https://api.github.com/repos/pfnet/chainer/issues/138/comments","events_url":"https://api.github.com/repos/pfnet/chainer/issues/138/events","html_url":"https://github.com/pfnet/chainer/issues/138","id":93164449,"number":138,"title":"numpy.pad cannot take negative pad_width","user":{"login":"mitmul","id":666535,"avatar_url":"https://avatars.githubusercontent.com/u/666535?v=3","gravatar_id":"","url":"https://api.github.com/users/mitmul","html_url":"https://github.com/mitmul","followers_url":"https://api.github.com/users/mitmul/followers","following_url":"https://api.github.com/users/mitmul/following{/other_user}","gists_url":"https://api.github.com/users/mitmul/gists{/gist_id}","starred_url":"https://api.github.com/users/mitmul/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mitmul/subscriptions","organizations_url":"https://api.github.com/users/mitmul/orgs","repos_url":"https://api.github.com/users/mitmul/repos","events_url":"https://api.github.com/users/mitmul/events{/privacy}","received_events_url":"https://api.github.com/users/mitmul/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-07-06T01:13:47Z","updated_at":"2015-07-06T01:13:47Z","closed_at":null,"body":"I'm trying to implement Spatial Pyramid Pooling function for Chainer by reference to the implementation in Caffe, then I run into a problem. On GPU both with cudnn and without cudnn, negative padding size is allowed to perform im2col. However, on CPU, because numpy.pad cannot take negative pad_width, im2col_cpu cannot be performed with negative padding size.\r\n\r\nTest code:\r\n```\r\nimport numpy\r\nfrom chainer import Variable, cuda\r\nimport chainer.functions as F\r\n\r\ncuda.init()\r\n\r\nx = numpy.arange(2 * 3 * 4 * 3, dtype=numpy.float32).reshape(2, 3, 4, 3)\r\nnumpy.random.shuffle(x)\r\nx = 2 * x / x.size - 1\r\n\r\npad = (-1, 0)  # has negative value\r\n\r\nxv = Variable(cuda.to_gpu(x.astype(numpy.float32)))\r\ny = F.max_pooling_2d(xv, 3, stride=2, pad=pad)\r\nprint('on gpu:', y.data.shape)\r\n\r\nxv = Variable(x)\r\ny = F.max_pooling_2d(xv, 3, stride=2, pad=pad)\r\nprint('on cpu:', y.data.shape)\r\n```\r\n\r\nResults:\r\n```\r\non gpu: (2, 3, 1, 1)\r\nTraceback (most recent call last):\r\n  File \"tests/test_negative_pad.py\", line 18, in <module>\r\n    y = F.max_pooling_2d(xv, 3, stride=2, pad=pad)\r\n  File \"build/bdist.linux-x86_64/egg/chainer/functions/pooling_2d.py\", line 227, in max_pooling_2d\r\n  File \"build/bdist.linux-x86_64/egg/chainer/function.py\", line 166, in __call__\r\n  File \"build/bdist.linux-x86_64/egg/chainer/function.py\", line 254, in forward\r\n  File \"build/bdist.linux-x86_64/egg/chainer/functions/pooling_2d.py\", line 84, in forward_cpu\r\n  File \"build/bdist.linux-x86_64/egg/chainer/utils/conv.py\", line 21, in im2col_cpu\r\n  File \"/home/ubuntu/anaconda/lib/python2.7/site-packages/numpy/lib/arraypad.py\", line 1292, in pad\r\n    pad_width = _validate_lengths(narray, pad_width)\r\n  File \"/home/ubuntu/anaconda/lib/python2.7/site-packages/numpy/lib/arraypad.py\", line 1085, in _validate_lengths\r\n    raise ValueError(fmt % (number_elements,))\r\nValueError: ((0, 0), (0, 0), (-1, 0), (0, 1)) cannot contain negative values.\r\n```\r\n\r\nWill this behaviour never be fixed? I think it's better that the difference between behaviours on GPU and on CPU is as small as possible."}}