範圍 (Range)

範圍 - 11 (Range - 11)

版本 (Version)

  • 名稱: Range (GitHub)

  • 網域: main

  • since_version: 11

  • 函數: True

  • 支援等級: SupportType.COMMON

  • 形狀推斷: True

此版本的運算子自版本 11 開始提供。(This version of the operator has been available since version 11.)

摘要 (Summary)

產生一個張量,其中包含從 start 開始,以 delta 為增量延伸至 limit (不包含) 的數字序列。(Generate a tensor containing a sequence of numbers that begin at start and extends by increments of delta up to limit (exclusive).)

範圍輸出的元素數量計算如下 (The number of elements in the output of range is computed as below)

number_of_elements = max( ceil( (limit - start) / delta ) , 0 )

下方顯示決定輸出內容的偽代碼 (The pseudocode determining the contents of the output is shown below)

for(int i=0; i<number_of_elements; ++i) {
  output[i] =  start + (i * delta);
}

範例 1 (Example 1)

Inputs: start = 3, limit = 9, delta = 3
Output: [3, 6]

範例 2 (Example 2)

Inputs: start = 10, limit = 4, delta = -2
Output: [10, 8, 6]

函數主體 (Function Body)

此運算子的函數定義。(The function definition for this operator.)

<
  domain: "",
  opset_import: ["" : 11]
>
Range (start, limit, delta) => (output)
{
   sub_result = Sub (limit, start)
   sub_result_casted = Cast <to: int = 1> (sub_result)
   delta_casted = Cast <to: int = 1> (delta)
   div_result = Div (sub_result_casted, delta_casted)
   ceil_result = Ceil (div_result)
   ceil_result_relu = Relu (ceil_result)
   ceil_result_relu_int = Cast <to: int = 7> (ceil_result_relu)
   ceil_result_relu_bool = Cast <to: int = 9> (ceil_result_relu)
   variadic_output, output = Loop (ceil_result_relu_int, ceil_result_relu_bool, start) <body: graph = loop_body_attribute (int64 i, bool cond,  prev) => ( cond_out,  current,  range) {
      cond_out = Identity (cond)
      current = Add (prev, delta)
      range = Identity (prev)
   }>
}

輸入 (Inputs)

  • start (異質) - T

    純量。輸出值範圍的第一個條目。(Scalar. First entry for the range of output values.)

  • limit (異質) - T

    純量。輸出值範圍的獨佔上限。(Scalar. Exclusive upper limit for the range of output values.)

  • delta (異質) - T

    純量。要遞增的值。(Scalar. Value to step by.)

輸出 (Outputs)

  • output (異質) - T

    與輸入類型相同的 1 維張量,包含產生的值範圍。(A 1-D tensor with same type as the inputs containing generated range of values.)

類型約束 (Type Constraints)

  • T 在 ( tensor(double), tensor(float), tensor(int16), tensor(int32), tensor(int64) )

    將輸入類型限制為常見的數字類型張量。(Constrain input types to common numeric type tensors.)