set_as

Description

Sets the value of a Scalar.

Prototype

set_as(value, src_offset=None)

Parameters

Table 1 Parameter description

Parameter

Input/Output

Description

value

Input

Value to set. Supported data types:

  • An immediate of type int or float
  • A Scalar variable
  • An Expr consisting of a Scalar variable and an immediate
  • A Tensor value. Must be in the following scope:

    Atlas 200/300/500 Inference Product: scope_ubuf

    Atlas Training Series Product: scope_ubuf

src_offset

Input

Reserved and not recommended.

Applicability

Atlas 200/300/500 Inference Product

Atlas Training Series Product

Restrictions

For the Atlas 200/300/500 Inference Product:
  1. Setting a Scalar of type float16 to a Scalar value of type float32 is not supported, and setting a Scalar of type float32 to a Scalar value of type float16 is not supported. Setting a Scalar of type float16 to a Scalar value of type float16 is supported only.
  2. Setting a Scalar of type int/uint to a Scalar value of type float16/float32 is not supported, and setting a Scalar of type float16/float32 to a Scalar value of type int/uint is not supported.
  3. Setting a Scalar of type int/uint to an Expr value is supported only when the Expr's Scalar is of type int or uint and the Expr's immediate is of type int or float.
  4. Setting a Scalar of type float16 or float32 to an Expr value is not supported.

For the Atlas Training Series Product, setting a Scalar of type float16 to an Expr value is not supported.

Returns

None

Example

from tbe import tik
tik_instance = tik.Tik()
# Immediate: int
index_reg = tik_instance.Scalar(dtype = "int32")
index_reg.set_as(10)   

# Immediate: float
index_reg2 = tik_instance.Scalar(dtype = "float16")
index_reg2.set_as(10.2) 

# A Scalar variable
index_reg3 = tik_instance.Scalar(dtype = "float16")
index_reg3.set_as(index_reg2)  

# A Tensor value
data_A = tik_instance.Tensor("float16", (128,), name="data_A", scope=tik.scope_ubuf)
index_reg3.set_as(data_A[0])// tensor value

#An Expr
index_reg4 = tik_instance.Scalar(dtype = "int32")
index_reg4.set_as(index_reg+20)