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

Function _check_index

tensorflow/python/ops/array_ops.py:642–655  ·  view source on GitHub ↗

Check if a given value is a valid index into a tensor.

(idx)

Source from the content-addressed store, hash-verified

640
641
642def _check_index(idx):
643 """Check if a given value is a valid index into a tensor."""
644 if isinstance(idx, (six.integer_types, tensor_shape.Dimension)):
645 return
646
647 # Optimistic check. Assumptions:
648 # * any object with a dtype is supported
649 # * any object with a dtype has a sizeable shape attribute.
650 dtype = getattr(idx, "dtype", None)
651 if (dtype is None or dtypes.as_dtype(dtype) not in _SUPPORTED_SLICE_DTYPES or
652 idx.shape and len(idx.shape) == 1):
653 # TODO(slebedev): IndexError seems more appropriate here, but it
654 # will break `_slice_helper` contract.
655 raise TypeError(_SLICE_TYPE_ERROR + ", got {!r}".format(idx))
656
657
658def _slice_helper(tensor, slice_spec, var=None):

Callers 1

_slice_helperFunction · 0.85

Calls 1

formatMethod · 0.45

Tested by

no test coverage detected