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

Function pack

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

Pack tensors along a new axis. See tf.pack. Args: labeled_tensors: The input tensors, which must have identical axes. new_axis: The name of the new axis, or a tuple containing the name and coordinate labels. axis_position: Optional integer position at which to insert the new

(labeled_tensors, new_axis, axis_position=0, name=None)

Source from the content-addressed store, hash-verified

216 tc.Collection(core.LabeledTensorLike),
217 tc.Union(string_types, core.AxisLike), int, tc.Optional(string_types))
218def pack(labeled_tensors, new_axis, axis_position=0, name=None):
219 """Pack tensors along a new axis.
220
221 See tf.pack.
222
223 Args:
224 labeled_tensors: The input tensors, which must have identical axes.
225 new_axis: The name of the new axis, or a tuple containing the name
226 and coordinate labels.
227 axis_position: Optional integer position at which to insert the new axis.
228 name: Optional op name.
229
230 Returns:
231 The packed tensors as a single LabeledTensor, with `new_axis` in the given
232 `axis_position`.
233
234 Raises:
235 ValueError: If fewer than one input tensors is provided, or if the tensors
236 don't have identical axes.
237 """
238 with ops.name_scope(name, 'lt_pack', labeled_tensors) as scope:
239 labeled_tensors = [
240 core.convert_to_labeled_tensor(lt) for lt in labeled_tensors
241 ]
242
243 if len(labeled_tensors) < 1:
244 raise ValueError('pack expects at least 1 tensors, but received %s' %
245 labeled_tensors)
246
247 axes_0 = labeled_tensors[0].axes
248 for t in labeled_tensors:
249 if t.axes != axes_0:
250 raise ValueError('Non-identical axes. Expected %s but got %s' %
251 (axes_0, t.axes))
252
253 pack_op = array_ops.stack(
254 [t.tensor for t in labeled_tensors], axis=axis_position, name=scope)
255 axes = list(axes_0.values())
256 axes.insert(axis_position, new_axis)
257 return core.LabeledTensor(pack_op, axes)
258
259
260@tc.returns(tc.List(core.LabeledTensor))

Callers 3

map_fnFunction · 0.85
bodyFunction · 0.85
_scanFunction · 0.85

Calls 4

name_scopeMethod · 0.45
stackMethod · 0.45
valuesMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected