4ac4dca40d8a123e90f2cf2d4a81d07d70a0b45d,onnx_tf/handlers/backend/scatter_elements.py,ScatterElements,version_11,#Any#Any#,11
Before Change
updates = kwargs["tensor_dict"][node.inputs[2]]
// Calculate shape of the tensorflow version of indices tensor.
sparsified_dense_idx_shape = updates.get_shape().as_list()
// Move on to convert ONNX indices to tensorflow indices in 2 steps:
//
// Step 1:
After Change
// check are there any indices are out of bounds
result = cls.chk_idx_out_of_bounds_along_axis(data, axis, indices)
msg = "ScatterElements indices are out of bounds, please double check the indices and retry."
with tf.control_dependencies(
[tf.compat.v1.assert_equal(result, True, message=msg)]):
// process negative indices
indices = cls.process_neg_idx_along_axis(data, axis, indices)
// Calculate shape of the tensorflow version of indices tensor.
sparsified_dense_idx_shape = tf_shape(updates)
// Move on to convert ONNX indices to tensorflow indices in 2 steps:
//
// Step 1:
// What would the index tensors look like if updates are all
// dense? In other words, produce a coordinate tensor for updates:
//
// coordinate[i, j, k ...] = [i, j, k ...]
// where the shape of "coordinate" tensor is same as that of updates.
//
// Step 2:
// But the coordinate tensor needs some correction because coord
// vector at position axis is wrong (since we assumed update is dense,
// but it is not at the axis specified).
// So we update coordinate vector tensor elements at psotion=axis with
// the sparse coordinate indices.
idx_tensors_per_axis = tf.meshgrid(
*list(
map(lambda x: tf.range(x, dtype=tf.dtypes.int64),
sparsified_dense_idx_shape)),
indexing="ij")
idx_tensors_per_axis[axis] = indices
dim_expanded_idx_tensors_per_axis = list(
map(lambda x: tf.expand_dims(x, axis=-1), idx_tensors_per_axis))
coordinate = tf.concat(dim_expanded_idx_tensors_per_axis, axis=-1)
// Now the coordinate tensor is in the shape
// [updates.shape, updates.rank]
// we need it to flattened into the shape:
// [product(updates.shape), updates.rank]
indices = tf.reshape(coordinate, [-1, tf.rank(data)])
updates = tf.reshape(updates, [-1])
return [tf.tensor_scatter_nd_update(data, indices, updates)]
In pattern: SUPERPATTERN
Frequency: 3
Non-data size: 5
Instances Project Name: onnx/onnx-tensorflow
Commit Name: 4ac4dca40d8a123e90f2cf2d4a81d07d70a0b45d
Time: 2020-01-10
Author: wtsang@us.ibm.com
File Name: onnx_tf/handlers/backend/scatter_elements.py
Class Name: ScatterElements
Method Name: version_11
Project Name: onnx/onnx-tensorflow
Commit Name: 6dad4c27ab4ffa96e0b699b8d5925fbe2a1f9d38
Time: 2020-10-22
Author: pluradj@us.ibm.com
File Name: onnx_tf/handlers/backend/upsample.py
Class Name: Upsample
Method Name: version_7
Project Name: asyml/texar
Commit Name: da37438735fd4b845bb0874562bd071865c480bb
Time: 2018-03-17
Author: zhitinghu@gmail.com
File Name: texar/modules/encoders/rnn_encoders.py
Class Name: RNNEncoderBase
Method Name: __init__