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

Function _expand_ellipsis

tensorflow/python/ops/ragged/ragged_getitem.py:288–313  ·  view source on GitHub ↗

Expands the ellipsis at the start of `key_list`. Assumes that the first element of `key_list` is Ellipsis. This will either remove the Ellipsis (if it corresponds to zero indices) or prepend a new `slice(None, None, None)` (if it corresponds to more than zero indices). Args: key_list:

(key_list, num_remaining_dims)

Source from the content-addressed store, hash-verified

286
287
288def _expand_ellipsis(key_list, num_remaining_dims):
289 """Expands the ellipsis at the start of `key_list`.
290
291 Assumes that the first element of `key_list` is Ellipsis. This will either
292 remove the Ellipsis (if it corresponds to zero indices) or prepend a new
293 `slice(None, None, None)` (if it corresponds to more than zero indices).
294
295 Args:
296 key_list: The arguments to `__getitem__()`.
297 num_remaining_dims: The number of dimensions remaining.
298
299 Returns:
300 A copy of `key_list` with he ellipsis expanded.
301 Raises:
302 ValueError: If ragged_rank.shape.ndims is None
303 IndexError: If there are too many elements in `key_list`.
304 """
305 if num_remaining_dims is None:
306 raise ValueError("Ellipsis not supported for unknown shape RaggedTensors")
307 num_indices = sum(1 for idx in key_list if idx is not array_ops.newaxis)
308 if num_indices > num_remaining_dims + 1:
309 raise IndexError("Too many indices for RaggedTensor")
310 elif num_indices == num_remaining_dims + 1:
311 return key_list[1:]
312 else:
313 return [slice(None, None, None)] + key_list
314
315
316def _tensors_in_key_list(key_list):

Callers 2

_ragged_getitemFunction · 0.85

Calls 2

sumFunction · 0.85
sliceFunction · 0.50

Tested by

no test coverage detected