set_as
Description
Sets the value of a Scalar.
Prototype
set_as(value, src_offset=None)
Parameters
Parameter |
Input/Output |
Description |
|---|---|---|
value |
Input |
Value to set. Supported data types: |
src_offset |
Input |
Reserved and not recommended. |
Applicability
Restrictions
For the Atlas 200/300/500 Inference Product :
- 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.
- 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.
- 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.
- Setting a Scalar of type float16 or float32 to an Expr value is not supported.
For the
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)
Parent topic: Scalar Management