MCPcopy Create free account
hub / github.com/alibaba/bigcomputing / _transpose_batch_time

Function _transpose_batch_time

DIEN/rnn.py:49–76  ·  view source on GitHub ↗

Transpose the batch and time dimensions of a Tensor. Retains as much of the static shape information as possible. Args: x: A tensor of rank 2 or higher. Returns: x transposed along the first two dimensions. Raises: ValueError: if `x` is rank 1 or lower.

(x)

Source from the content-addressed store, hash-verified

47
48
49def _transpose_batch_time(x):
50 """Transpose the batch and time dimensions of a Tensor.
51
52 Retains as much of the static shape information as possible.
53
54 Args:
55 x: A tensor of rank 2 or higher.
56
57 Returns:
58 x transposed along the first two dimensions.
59
60 Raises:
61 ValueError: if `x` is rank 1 or lower.
62 """
63 x_static_shape = x.get_shape()
64 if x_static_shape.ndims is not None and x_static_shape.ndims < 2:
65 raise ValueError(
66 "Expected input tensor %s to have rank at least 2, but saw shape: %s" %
67 (x, x_static_shape))
68 x_rank = array_ops.rank(x)
69 x_t = array_ops.transpose(
70 x, array_ops.concat(
71 ([1, 0], math_ops.range(2, x_rank)), axis=0))
72 x_t.set_shape(
73 tensor_shape.TensorShape([
74 x_static_shape[1].value, x_static_shape[0].value
75 ]).concatenate(x_static_shape[2:]))
76 return x_t
77
78
79def _best_effort_input_batch_size(flat_input):

Callers 1

dynamic_rnnFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected