Stacks a list of rank-`R` tensors into one rank-`(R+1)` tensor in parallel. Requires that the shape of inputs be known at graph construction time. Packs the list of tensors in `values` into a tensor with rank one higher than each tensor in `values`, by packing them along the first dimension.
(values, name="parallel_stack")
| 1047 | |
| 1048 | @tf_export("parallel_stack") |
| 1049 | def parallel_stack(values, name="parallel_stack"): |
| 1050 | """Stacks a list of rank-`R` tensors into one rank-`(R+1)` tensor in parallel. |
| 1051 | |
| 1052 | Requires that the shape of inputs be known at graph construction time. |
| 1053 | |
| 1054 | Packs the list of tensors in `values` into a tensor with rank one higher than |
| 1055 | each tensor in `values`, by packing them along the first dimension. |
| 1056 | Given a list of length `N` of tensors of shape `(A, B, C)`; the `output` |
| 1057 | tensor will have the shape `(N, A, B, C)`. |
| 1058 | |
| 1059 | For example: |
| 1060 | |
| 1061 | ```python |
| 1062 | x = tf.constant([1, 4]) |
| 1063 | y = tf.constant([2, 5]) |
| 1064 | z = tf.constant([3, 6]) |
| 1065 | tf.parallel_stack([x, y, z]) # [[1, 4], [2, 5], [3, 6]] |
| 1066 | ``` |
| 1067 | |
| 1068 | The difference between `stack` and `parallel_stack` is that `stack` requires |
| 1069 | all the inputs be computed before the operation will begin but doesn't require |
| 1070 | that the input shapes be known during graph construction. |
| 1071 | |
| 1072 | `parallel_stack` will copy pieces of the input into the output as they become |
| 1073 | available, in some situations this can provide a performance benefit. |
| 1074 | |
| 1075 | Unlike `stack`, `parallel_stack` does NOT support backpropagation. |
| 1076 | |
| 1077 | This is the opposite of unstack. The numpy equivalent is |
| 1078 | |
| 1079 | tf.parallel_stack([x, y, z]) = np.asarray([x, y, z]) |
| 1080 | |
| 1081 | Args: |
| 1082 | values: A list of `Tensor` objects with the same shape and type. |
| 1083 | name: A name for this operation (optional). |
| 1084 | |
| 1085 | Returns: |
| 1086 | output: A stacked `Tensor` with the same type as `values`. |
| 1087 | """ |
| 1088 | with ops.name_scope(name): |
| 1089 | value_t = ops.convert_to_tensor(values[0]) |
| 1090 | value_shape = ops.convert_to_tensor(value_t).get_shape() |
| 1091 | |
| 1092 | output_shape = tensor_shape.TensorShape([len(values)]) |
| 1093 | output_shape = output_shape.concatenate(value_shape) |
| 1094 | # expand_dims converts concat to stack. |
| 1095 | return gen_array_ops.parallel_concat( |
| 1096 | [expand_dims(value, 0) for value in values], shape=output_shape) |
| 1097 | |
| 1098 | |
| 1099 | @tf_export("stack") |
nothing calls this directly
no test coverage detected