Support use of -1 in reshape on GPU
When reshaping, numpy allows you to use -1 for one of the dimensions, to indicate that it should be calculated from the other dimensions. Demonstration of its behavior:
>>> nh1. numpy.zeros((6, 5), dtypenumpy.float32)
>>> n.shape = (3, -1)
>>> n.shape
(3, 10)
>>> n.shape = (7, -1)
Traceback (most recent call last):
File '', line 1, in
ValueError: total size of new array must be unchanged
>>> n.reshape((-1, -1))
Traceback (most recent call last):
File '', line 1, in
ValueError: can only specify one unknown dimension
This works in theano on the CPU, but not on the GPU; it throws a !ValueError, since the -1 is interpreted literally. To reproduce:
>>> m = theano.tensor.matrix()
>>> r = m.reshape((3, -1))
>>> fh1. theano.function(inputs[m], outputs=r)
>>> print f(n).shape
- !python
>>> nh1. numpy.zeros((6, 5), dtypenumpy.float32)
>>> n.shape = (3, -1)
>>> n.shape
(3, 10)
>>> n.shape = (7, -1)
Traceback (most recent call last):
File '', line 1, in
ValueError: total size of new array must be unchanged
>>> n.reshape((-1, -1))
Traceback (most recent call last):
File '', line 1, in
ValueError: can only specify one unknown dimension
This works in theano on the CPU, but not on the GPU; it throws a !ValueError, since the -1 is interpreted literally. To reproduce:
- !python
>>> m = theano.tensor.matrix()
>>> r = m.reshape((3, -1))
>>> fh1. theano.function(inputs[m], outputs=r)
>>> print f(n).shape
Leave a comment