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

Function _transpose_batch_time

tensorflow/python/ops/rnn.py:43–66  ·  view source on GitHub ↗

Transposes the batch and time dimensions of a Tensor. If the input tensor has rank < 2 it returns the original tensor. Retains as much of the static shape information as possible. Args: x: A Tensor. Returns: x transposed along the first two dimensions.

(x)

Source from the content-addressed store, hash-verified

41
42
43def _transpose_batch_time(x):
44 """Transposes the batch and time dimensions of a Tensor.
45
46 If the input tensor has rank < 2 it returns the original tensor. Retains as
47 much of the static shape information as possible.
48
49 Args:
50 x: A Tensor.
51
52 Returns:
53 x transposed along the first two dimensions.
54 """
55 x_static_shape = x.get_shape()
56 if x_static_shape.rank is not None and x_static_shape.rank < 2:
57 return x
58
59 x_rank = array_ops.rank(x)
60 x_t = array_ops.transpose(
61 x, array_ops.concat(([1, 0], math_ops.range(2, x_rank)), axis=0))
62 x_t.set_shape(
63 tensor_shape.TensorShape(
64 [x_static_shape.dims[1].value,
65 x_static_shape.dims[0].value]).concatenate(x_static_shape[2:]))
66 return x_t
67
68
69def _best_effort_input_batch_size(flat_input):

Callers 2

dynamic_rnnFunction · 0.90
dynamic_rnnFunction · 0.70

Calls 7

transposeMethod · 0.80
get_shapeMethod · 0.45
rankMethod · 0.45
concatMethod · 0.45
rangeMethod · 0.45
set_shapeMethod · 0.45
concatenateMethod · 0.45

Tested by

no test coverage detected