mindspore.ops.Assert
- class mindspore.ops.Assert(summarize=3)[source]
Asserts whether the given condition is True. If input condition is identified to be false, print a list of the tensor in data.
- Parameters
summarize (int, optional) – The number of entries to be printed in each tensor while the given condition is identified to be False. Default: 3.
- Inputs:
condition (Union[Tensor[bool], bool]) - The condition to be identified.
input_data (Union[tuple[Tensor], list[Tensor]]) - The tensors to be printed out when the condition is false.
- Raises
- Supported Platforms:
GPU
CPU
Examples
>>> a = Tensor(np.array([-1, 0, 1, 2, 3]).astype(np.int32)) >>> b = Tensor(np.array([1, 2, 3, 4, 5]).astype(np.float32)) >>> assert1 = ops.Assert(3) >>> assert1(False, [a, b]) For 'Assert' condition is false. input data: [-1 0 1] input data: [1 2 3] Traceback (most recent call last): File "<stdin>", line 1, in <module> File "mindspore/ops/primitive.py", line 294, in __call__ return _run_op(self, self.name, args) File "mindspore/common/api.py", line 99, in wrapper results = fn(*arg, **kwargs) File "mindspore/ops/primitive.py", line 743, in _run_op output = real_run_op(obj, op_name, args) RuntimeError: assert failed