negate
Description
Returns True if the argument is false; False otherwise.
This API is generally used as the conditional statement (cond) of the if_scope and elif_scope statements.
Prototype
negate(cond)
Parameters
Parameter |
Input/Output |
Description |
|---|---|---|
cond |
Input |
Supports one argument of type InputScalar, immediate (int and float), Expr, Scalar, and bool. Specifically,
NOTICE:
The Expr supports the following operators:
You can use supported operators to form a complex expression. However, the comparison operators cannot be used together. For example, if you want to express n > 1 and n < 4: |
Applicability
Restrictions
When the input is a Scalar or an Expr, the following data types are not supported:
The
The
Returns
A TIK Expr.
For example: tik.negate(scalar & > 1)
Returns: (scalar<=1)
Example
# If negate's argument is true, False is returned with the if_scope statement skipped.
tik_instance = tik.Tik()
data_A= tik_instance.Tensor(shape=(128,), name="data_A", scope=tik.scope_gm, dtype="int32")
data_A_ub = tik_instance.Tensor(shape=(128,), name="data_A_ub", scope=tik.scope_ubuf, dtype="int32")
bool_B = True
tik_instance.vec_dup(64, data_A_ub, 1, 1, 8)
with tik_instance.if_scope(tik.negate(bool_B)):
tik_instance.data_move(data_A, data_A_ub, 0, 1, 128 // 16, 0, 0)
tik_instance.BuildCCE(kernel_name, inputs=[], outputs=[data_A], config={"save_temp_cce_file": True})
# If negate's argument false, True is returned with the if_scope statement executed.
tik_instance = tik.Tik()
data_A= tik_instance.Tensor(shape=(128,), name="data_A", scope=tik.scope_gm, dtype="int32")
data_A_ub = tik_instance.Tensor(shape=(128,), name="data_A_ub", scope=tik.scope_ubuf, dtype="int32")
bool_B = False
tik_instance.vec_dup(64, data_A_ub, 1, 1, 8)
with tik_instance.if_scope(tik.negate(bool_B)):
tik_instance.data_move(data_A, data_A_ub, 0, 1, 128 // 16, 0, 0)
tik_instance.BuildCCE(kernel_name, inputs=[], outputs=[data_A], config={"save_temp_cce_file": True})
The returned results are as follows:
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]