Skip to content

Commit

Permalink
Merge pull request #3652 from nouiz/err_msg
Browse files Browse the repository at this point in the history
Better error message.
  • Loading branch information
lamblin committed Nov 24, 2015
2 parents 40eb1b3 + e698035 commit 27c008d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion doc/install.txt
Expand Up @@ -484,7 +484,7 @@ Using the GPU

The first thing you'll need for Theano to use your GPU is Nvidia's
GPU-programming toolchain. You should install at least the CUDA driver and the CUDA Toolkit, as
`described here <http://www.nvidia.com/object/cuda_get.html>`_. The CUDA
`described here <https://developer.nvidia.com/cuda-toolkit>`_. The CUDA
Toolkit installs a folder on your computer with subfolders *bin*, *lib*,
*include*, and some more too. (Sanity check: The *bin* subfolder should contain an *nvcc*
program which is the compiler for GPU code.) This folder is called the *cuda
Expand Down
8 changes: 7 additions & 1 deletion theano/tensor/basic.py
Expand Up @@ -4230,7 +4230,8 @@ def get_vector_length(v):
"""
v = as_tensor_variable(v)
if v.ndim != 1:
raise TypeError('argument must be symbolic vector')
raise TypeError("argument must be symbolic vector, got '%s'" %
v)
if v.type.broadcastable[0]:
return 1
if isinstance(v, gof.Constant) and v.type.ndim == 1:
Expand Down Expand Up @@ -4479,6 +4480,11 @@ def c_code(self, node, name, inputs, outputs, sub):

def reshape(x, newshape, ndim=None, name=None):
if ndim is None:
newshape = as_tensor_variable(newshape)
if newshape.ndim != 1:
raise TypeError(
"New shape in reshape must be a vector or a list/tuple of"
" scalar. Got %s after conversion to a vector." % newshape)
try:
ndim = get_vector_length(newshape)
except ValueError:
Expand Down
8 changes: 8 additions & 0 deletions theano/tensor/raw_random.py
Expand Up @@ -379,10 +379,18 @@ def _infer_ndim_bcast(ndim, shape, *args):
ndim = template.ndim
else:
v_shape = tensor.as_tensor_variable(shape)
if v_shape.ndim != 1:
raise TypeError(
"shape must be a vector or list of scalar, got '%s'" % v_shape)

if ndim is None:
ndim = tensor.get_vector_length(v_shape)
bcast = [False] * ndim

if v_shape.ndim != 1:
raise TypeError("shape must be a vector or list of scalar, got '%s'" %
v_shape)

if (not (v_shape.dtype.startswith('int') or
v_shape.dtype.startswith('uint'))):
raise TypeError('shape must be an integer vector or list',
Expand Down

0 comments on commit 27c008d

Please sign in to comment.