MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / gather_nd

Function gather_nd

tensorflow/python/ops/ragged/ragged_gather_ops.py:127–265  ·  view source on GitHub ↗

Gather slices from `params` using `n`-dimensional indices. This operation is similar to `gather`, but it uses the innermost dimension of `indices` to define a slice into `params`. In particular, if: * `indices` has shape `[A1...AN, I]` * `params` has shape `[B1...BM]` Then: * `resul

(params, indices, batch_dims=0, name=None)

Source from the content-addressed store, hash-verified

125# ragged.gather_nd
126#===============================================================================
127def gather_nd(params, indices, batch_dims=0, name=None):
128 """Gather slices from `params` using `n`-dimensional indices.
129
130 This operation is similar to `gather`, but it uses the innermost dimension
131 of `indices` to define a slice into `params`. In particular, if:
132
133 * `indices` has shape `[A1...AN, I]`
134 * `params` has shape `[B1...BM]`
135
136 Then:
137
138 * `result` has shape `[A1...AN, B_{I+1}...BM]`.
139 * `result[a1...aN] = params[indices[a1...aN, :]]`
140
141 Args:
142 params: A potentially ragged tensor with shape `[A1...AN, I]`.
143 indices: A potentially ragged tensor with shape `[B1...BM]`.
144 batch_dims: Must be zero.
145 name: A name for the operation (optional).
146
147 Returns:
148 A potentially ragged tensor with shape `[A1...AN, B_{I+1}...BM]`.
149
150 #### Examples:
151 ```python
152 >>> params = tf.compat.v1.ragged.constant_value(
153 ... [ [ ['000', '001'], ['010' ] ],
154 ... [ ['100' ], ['110', '111', '112'], ['120'] ],
155 ... [ [ ], ['210' ] ] ])
156
157 >>> # Gather 2D slices from a 3D tensor
158 >>> ragged.gather_nd(params, [[2], [0]])
159 [ [ [ ], ['210'] ]
160 [ ['000', '001'], ['010'] ] ]
161
162 >>> # Gather 1D slices from a 3D tensor
163 >>> ragged.gather_nd(params, [[2, 1], [0, 0]])
164 [['210'], ['000', '001']]
165
166 >>> # Gather scalars from a 3D tensor
167 >>> ragged.gather_nd(params, [[0, 0, 1], [1, 1, 2]])
168 ['001', '112']
169 ```
170 """
171 if not isinstance(batch_dims, int) or batch_dims != 0:
172 raise ValueError('batch_dims != 0 is not supported for ragged gather yet.')
173 if not (ragged_tensor.is_ragged(params) or ragged_tensor.is_ragged(indices)):
174 return array_ops.gather_nd(params, indices, name)
175
176 with ops.name_scope(name, 'RaggedGatherNd', [params, indices]):
177
178 params = ragged_tensor.convert_to_tensor_or_ragged_tensor(
179 params, name='params')
180 indices = ragged_tensor.convert_to_tensor_or_ragged_tensor(
181 indices, name='indices')
182 params, indices = ragged_tensor.match_row_splits_dtypes(params, indices)
183 indices_shape = indices.shape
184 indices_ndims = indices_shape.ndims

Callers

nothing calls this directly

Calls 15

is_raggedMethod · 0.80
with_flat_valuesMethod · 0.80
to_tensorMethod · 0.80
onesMethod · 0.80
tileMethod · 0.80
reshapeMethod · 0.80
row_startsMethod · 0.80
rangeFunction · 0.70
gatherFunction · 0.70
gather_ndMethod · 0.45
name_scopeMethod · 0.45
from_tensorMethod · 0.45

Tested by

no test coverage detected