ScatterNdNonAliasingAdd


tensorflow C++ API

tensorflow::ops::ScatterNdNonAliasingAdd

Applies sparse addition to input using individual values or slices.


Summary

fromupdatesaccording to indicesindices. The updates are non-aliasing:inputis only modified in-place if no other operations will use it. Otherwise, a copy ofinputis made. This operation has a gradient with respect to bothinputandupdates.

inputis aTensorwith rankPandindicesis aTensorof rankQ.

indicesmust be integer tensor, containing indices intoinput. It must be shape[d_0, ..., d_{Q-2}, K]where0 < K <= P.

The innermost dimension ofindices(with lengthK) corresponds to indices into elements (ifK = P) or(P-K)-dimensional slices (ifK < P) along theKth dimension ofinput.

updatesisTensorof rankQ-1+P-Kwith shape:

``` [d_0, ..., d_{Q-2}, input.shape[K], ..., input.shape[P-1]]. ```

For example, say we want to add 4 scattered elements to a rank-1 tensor to 8 elements. In Python, that addition would look like this:

input = tf.constant([1,2,3,4,5,6,7,8])
indices = tf.constant([[4],[3],[1],[7]])
updates = tf.constant([9,10,11,12])
output = tf.scatter_nd_non_aliasing_add(input, indices, updates)
with tf.Session()as sess:
    print(sess.run(output))

The resulting valueoutputwould look like this:

[1, 13, 3, 14, 14, 6, 7, 20]

See tf.scatter_nd for more details about how to make updates to slices.

Arguments:

  • scope: A Scope object
  • input: A Tensor.
  • indices: A Tensor . Must be one of the following types:int32,int64. A tensor of indices into input.
  • updates: A Tensor. Must have the same type as ref. A tensor of updated values to add to input.

Returns:

  • Output: A Tensorwith the same shape as input, containing values of inputupdated with updates.

ScatterNdNonAliasingAdd block

Source link :https://github.com/EXPNUNI/enuSpaceTensorflow/blob/master/enuSpaceTensorflow/tf_array_ops.cpp

Argument:

  • Scope scope : A Scope object (A scope is generated automatically each page. A scope is not connected.)
  • Input input: A Tensor.
  • Input indices: A Tensor . Must be one of the following types:int32,int64. A tensor of indices into input.
  • Input updates: A Tensor. Must have the same type as ref. A tensor of updated values to add to input.

Output:

  • Output output : Output object of ScatterNdNonAliasingAdd class object.

Result:

  • std::vector(Tensor) result_output: A Tensorwith the same shape as input, containing values of inputupdated with updates.

Using Method


※ update의 데이터를 indices에 있는 인덱스 순서대로 input tensor에 있는 값에 더한다.
※ input의 shape는 indices의 shape에서 -1 rank한 값과 update의 shape값을 랭크 별로 더한 shape이다. (ex: indice의 shape는 [2,1]이고, update의 shape가 [2,4,4]라면 -> [2] + [2,4,4] = [4,4,4] )

results matching ""

    No results matching ""