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

Function _SliceHelperVar

tensorflow/python/ops/array_ops.py:999–1042  ·  view source on GitHub ↗

Creates a slice helper object given a variable. This allows creating a sub-tensor from part of the current contents of a variable. See `tf.Tensor.__getitem__` for detailed examples of slicing. This function in addition also allows assignment to a sliced range. This is similar to `__setit

(var, slice_spec)

Source from the content-addressed store, hash-verified

997
998
999def _SliceHelperVar(var, slice_spec):
1000 """Creates a slice helper object given a variable.
1001
1002 This allows creating a sub-tensor from part of the current contents
1003 of a variable. See `tf.Tensor.__getitem__` for detailed examples
1004 of slicing.
1005
1006 This function in addition also allows assignment to a sliced range.
1007 This is similar to `__setitem__` functionality in Python. However,
1008 the syntax is different so that the user can capture the assignment
1009 operation for grouping or passing to `sess.run()`.
1010 For example,
1011
1012 ```python
1013 import tensorflow as tf
1014 A = tf.Variable([[1,2,3], [4,5,6], [7,8,9]], dtype=tf.float32)
1015 with tf.compat.v1.Session() as sess:
1016 sess.run(tf.compat.v1.global_variables_initializer())
1017 print(sess.run(A[:2, :2])) # => [[1,2], [4,5]]
1018
1019 op = A[:2,:2].assign(22. * tf.ones((2, 2)))
1020 print(sess.run(op)) # => [[22, 22, 3], [22, 22, 6], [7,8,9]]
1021 ```
1022
1023 Note that assignments currently do not support NumPy broadcasting
1024 semantics.
1025
1026 Args:
1027 var: An `ops.Variable` object.
1028 slice_spec: The arguments to `Tensor.__getitem__`.
1029
1030 Returns:
1031 The appropriate slice of "tensor", based on "slice_spec".
1032 As an operator. The operator also has a `assign()` method
1033 that can be used to generate an assignment operator.
1034
1035 Raises:
1036 ValueError: If a slice range is negative size.
1037 TypeError: TypeError: If the slice indices aren't int, slice,
1038 ellipsis, tf.newaxis or int32/int64 tensors.
1039
1040 """
1041
1042 return _slice_helper(var.value(), slice_spec, var)
1043
1044
1045ops.Tensor._override_operator("__getitem__", _slice_helper)

Callers

nothing calls this directly

Calls 2

_slice_helperFunction · 0.85
valueMethod · 0.45

Tested by

no test coverage detected