From 3973f1424e3992cf7985cdeb42508426d753fef9 Mon Sep 17 00:00:00 2001 From: buxue Date: Sun, 27 Dec 2020 19:13:28 +0800 Subject: [PATCH] fix error in len of tensor in pynative mode --- mindspore/common/tensor.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mindspore/common/tensor.py b/mindspore/common/tensor.py index 0906f12967..2977063d77 100644 --- a/mindspore/common/tensor.py +++ b/mindspore/common/tensor.py @@ -197,9 +197,10 @@ class Tensor(Tensor_): def __len__(self): out = tensor_operator_registry.get('shape')(self) - if not out: - return 1 - return out[0] + if out: + return out[0] + raise TypeError("Not support len of a 0-D tensor") + def __mod__(self, other): return tensor_operator_registry.get('__mod__')(self, other)