all

Description

Returns True if all arguments are true; False if one of the arguments is false.

This API is generally used as the conditional statement (cond) of the if_scope and elif_scope statements.

Prototype

all(*args)

Parameters

Parameter

Input/Output

Description

*args

Input

Supports multiple arguments.

It supports the InputScalar, Scalar, Expr, bool, and immediate (int and float) data types, and any, all, and negate functions.

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

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.all(scalar, scalar > 1, a == 0, i)

Returns: ((x != 0) && (x > 1)) && (i != 0))

Example

tik_instance = tik.Tik()
scalar = tik_instance.Scalar("uint32", init_value=0)
scalar2 = tik_instance.Scalar("uint32", init_value=4)
gm_b = tik_instance.Tensor(dtype, shape, name="gm_b", scope=tik.scope_gm)
ub_b = tik_instance.Tensor(dtype, shape, name="ub_b", scope=tik.scope_ubuf)
a = 1
# scalar2! = 0 is a true statement; a > 0 is a true statement as a equals 1; scalar = 0 is a true statement.
# If all arguments passed to tik.all are true, it returns True and runs the if_scope statement.
with tik_instance.if_scope(tik.all(scalar2, a > 0, scalar == 0)):    
    tik_instance.vec_dup(64, ub_b, scalar2, 1, 8)
    tik_instance.data_move(gm_b, ub_b, 0, 1, 8, 0, 0)
tik_instance.BuildCCE(kernel_name="all", inputs=[], outputs=[gm_b])