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

Function op

tensorflow/contrib/labeled_tensor/python/ops/ops.py:895–959  ·  view source on GitHub ↗

Computes the given reduction across the given axes of a LabeledTensor. See `tf.{op_name}` for full details. Args: labeled_tensor: The input tensor. axes: A set of axes or None. If None, all axes will be reduced. Axes must all be strings, in which case those dime

(labeled_tensor, axes=None, name=None)

Source from the content-addressed store, hash-verified

893 @tc.returns(core.LabeledTensor)
894 @tc.accepts(core.LabeledTensorLike, ReduceAxes, tc.Optional(string_types))
895 def op(labeled_tensor, axes=None, name=None):
896 """Computes the given reduction across the given axes of a LabeledTensor.
897
898 See `tf.{op_name}` for full details.
899
900 Args:
901 labeled_tensor: The input tensor.
902 axes: A set of axes or None.
903 If None, all axes will be reduced.
904 Axes must all be strings, in which case those dimensions will be
905 removed, or pairs of (name, None) or (name, label), in which case those
906 dimensions will be kept.
907 name: Optional op name.
908
909 Returns:
910 The reduced LabeledTensor.
911
912 Raises:
913 ValueError: if any of the axes to reduce over are not found on
914 `labeled_tensor`.
915 """
916 with ops.name_scope(name, default_name, [labeled_tensor]) as scope:
917 labeled_tensor = core.convert_to_labeled_tensor(labeled_tensor)
918
919 if axes is None:
920 axes = labeled_tensor.axes.keys()
921
922 if isinstance(axes, (string_types, tuple)):
923 axes = [axes]
924
925 reduction_axes = {}
926 axes_to_squeeze = []
927 for a in axes:
928 if isinstance(a, string_types):
929 # We squeeze out this axis.
930 reduction_axes[a] = a
931 axes_to_squeeze.append(a)
932 else:
933 # We keep this axis, with the user-provided labels.
934 (axis_name, label) = a
935 if label is not None:
936 # The input was a single label, so make it a list so it can be
937 # turned into an Axis.
938 label = [label]
939 reduction_axes[axis_name] = (axis_name, label)
940
941 for axis_name in reduction_axes:
942 if axis_name not in labeled_tensor.axes:
943 raise ValueError('Axis %s not in axes %s' %
944 (axis_name, labeled_tensor.axes))
945
946 intermediate_axes = []
947 reduction_dimensions = []
948 for i, axis in enumerate(labeled_tensor.axes.values()):
949 if axis.name in reduction_axes:
950 intermediate_axes.append(reduction_axes[axis.name])
951 reduction_dimensions.append(i)
952 else:

Calls 6

squeezeFunction · 0.70
reduce_fnFunction · 0.50
name_scopeMethod · 0.45
keysMethod · 0.45
appendMethod · 0.45
valuesMethod · 0.45