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,
  • Arguments of the Scalar and InputScalar types are automatically converted into Exprs. For example, if the argument name is a, it is converted into a!=0.
  • Arguments of the Expr type are automatically converted into Exprs with !=0. For example, if the argument is scalar // 2, it is converted to scalar // 2!=0.
NOTICE:

The Expr supports the following operators:

  • Comparison operators: >, <, !=, ==, >=, <=
  • Arithmetic operators: +, , *, /, //, %
  • Bitwise 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:

  • The following is not supported:

    1 < n < 4

  • The recommended expression is:

    tik.all((1 < n) , (n < 4))

Applicability

Atlas 200/300/500 Inference Product

Atlas Training Series Product

Restrictions

When the input is a Scalar or an Expr, the following data types are not supported:

The Atlas 200/300/500 Inference Product does not support Scalars of type float16 or float32 or Exprs including Scalars of this type.

The Atlas Training Series Product does not support Scalars of type float16 or Exprs including Scalars of this type.

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]