MCPcopy Create free account
hub / github.com/NVIDIA/FasterTransformer / reshape_to_matrix

Function reshape_to_matrix

examples/tensorflow/encoder/utils/encoder.py:157–168  ·  view source on GitHub ↗

Reshapes a >= rank 2 tensor to a rank 2 tensor (i.e., a matrix).

(input_tensor)

Source from the content-addressed store, hash-verified

155 return shape
156
157def reshape_to_matrix(input_tensor):
158 """Reshapes a >= rank 2 tensor to a rank 2 tensor (i.e., a matrix)."""
159 ndims = input_tensor.shape.ndims
160 if ndims < 2:
161 raise ValueError("Input tensor must have at least rank 2. Shape = %s" %
162 (input_tensor.shape))
163 if ndims == 2:
164 return input_tensor
165
166 width = input_tensor.shape[-1]
167 output_tensor = tf.reshape(input_tensor, [-1, width])
168 return output_tensor
169
170
171def reshape_from_matrix(output_tensor, orig_shape_list):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected