forked from mindspore-Ecosystem/mindspore
!14738 Change Tensor zero dimension check code to make it faster.
From: @liangzhibo Reviewed-by: @ginfung,@zh_qh Signed-off-by: @zh_qh
This commit is contained in:
commit
13d9ad0f2a
|
@ -92,9 +92,13 @@ class Tensor(Tensor_):
|
|||
if isinstance(shape, numbers.Number):
|
||||
shape = (shape,)
|
||||
|
||||
if input_data is not None and isinstance(input_data, (tuple, list, np.ndarray)) \
|
||||
and np.array(input_data).ndim > 1 and np.array(input_data).size == 0:
|
||||
raise ValueError("input_data can not contain zero dimension.")
|
||||
if input_data is not None:
|
||||
if isinstance(input_data, np.ndarray) and input_data.ndim > 1 and input_data.size == 0:
|
||||
raise ValueError("input_data can not contain zero dimension.")
|
||||
if isinstance(input_data, (tuple, list)) and np.array(input_data).ndim > 1 \
|
||||
and np.array(input_data).size == 0:
|
||||
raise ValueError("input_data can not contain zero dimension.")
|
||||
|
||||
if shape is not None and not (hasattr(init, "__enable_zero_dim__") and init.__enable_zero_dim__):
|
||||
if 0 in shape:
|
||||
raise ValueError("Shape can not contain zero value.")
|
||||
|
|
Loading…
Reference in New Issue