提交 ffd02ba4 authored 作者: Pascal Lamblin's avatar Pascal Lamblin

In filter, be more consistent about checks that are done.

上级 b4d6e339
...@@ -472,15 +472,13 @@ class TensorType(Type): ...@@ -472,15 +472,13 @@ class TensorType(Type):
if (type(data) is numpy.ndarray) and (data.dtype is self.numpy_dtype): if (type(data) is numpy.ndarray) and (data.dtype is self.numpy_dtype):
pass # fall through to ndim check pass # fall through to ndim check
elif strict: elif strict:
# this is its own subcase that doesn't fall through to anything # If any of the two conditions above was not met,
if not isinstance(data, numpy.ndarray): # we raise a meaningful TypeError.
if not (type(data) is numpy.ndarray):
raise TypeError("%s expected a ndarray object." % self, data, type(data)) raise TypeError("%s expected a ndarray object." % self, data, type(data))
if not str(data.dtype) == self.dtype: if not (data.dtype is self.numpy_dtype):
raise TypeError("%s expected a ndarray object with dtype = %s (got %s)." % (self, self.dtype, data.dtype)) raise TypeError("%s expected a ndarray object with dtype = %s (got %s)." % (self, self.numpy_dtype, data.dtype))
if not data.ndim == self.ndim: assert False, "This point in the program should never be reached."
raise TypeError("%s expected a ndarray object with %s dimensions (got %s)." % (self, self.ndim, data.ndim))
return data
else: else:
if allow_downcast: if allow_downcast:
# Convert to self.dtype, regardless of the type of data # Convert to self.dtype, regardless of the type of data
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论