Changing the Tensor Content

Description

Sets the content of a Tensor by index.

Prototype

__setitem__(index, value)

Parameters

Table 1 Parameter description

Parameter

Input/Output

Description

index

Input

Tensor index. Must be one of the following data types:

  • An immediate of type int, a Scalar of type int or uint, or an Expr of type int or uint, for example, dataA_UB[100].
  • A Slice. The start, stop, and step parameters are immediates, Scalars, or Exprs. Currently, step can only be set to 1, for example, dataA_UB[100:] or dataA_UB[100:200:1].
  • A tuple of immediates, Scalars, Exprs, or Slices. Has the same number of dimensions as the Tensor. Separate the dimension sizes by commas (,), for example, dataA_UB[0,0,0:100].

value

Input

Value to set. Supported data types:

  • A Scalar.
  • An Expr.
  • A Tensor. Must have only one element. Otherwise, the first element of the Tensor is used.
  • Must be in the following scope:

    Atlas 200/300/500 Inference Product: scope_ubuf

    Atlas Training Series Product: scope_ubuf

Applicability

Atlas 200/300/500 Inference Product

Atlas Training Series Product

Restrictions

1. The destination Tensor must be in the scope_ubuf scope.

2. Only the first element of the destination Tensor is changed.

3. The alignment requirements for slice vary with the scope. start must meet the following requirements:
  • Unified Buffer: 32-byte aligned
  • Global Memory: no alignment requirement

Returns

None

Example

from tbe import tik
tik_instance = tik.Tik()
data_A = tik_instance.Tensor("float16", (128,), name="data_A", scope=tik.scope_ubuf)
scalar_B = tik_instance.Scalar(dtype="float16", name="scalar_B", init_value=2.0)
data_A[0] = scalar_B