* Stacks a list of rank-`R` `tf.Tensor`s into one rank-`(R+1)` `tf.Tensor`. * * ```js * const a = tf.tensor1d([1, 2]); * const b = tf.tensor1d([3, 4]); * const c = tf.tensor1d([5, 6]); * tf.stack([a, b, c]).print(); * ``` * * @param tensors A list of tensor objects with the same shape and d
(
tensors: Array<T|TensorLike>, axis = 0)
| 42 | * @doc {heading: 'Tensors', subheading: 'Slicing and Joining'} |
| 43 | */ |
| 44 | function stack_<T extends Tensor>( |
| 45 | tensors: Array<T|TensorLike>, axis = 0): Tensor { |
| 46 | const $tensors = |
| 47 | convertToTensorArray(tensors, 'tensors', 'stack', 'string_or_numeric'); |
| 48 | |
| 49 | util.assert( |
| 50 | $tensors.length >= 1, () => 'Pass at least one tensor to tf.stack'); |
| 51 | |
| 52 | if ($tensors.length > 0) { |
| 53 | util.assert( |
| 54 | axis <= $tensors[0].rank, () => 'Axis must be <= rank of the tensor'); |
| 55 | } |
| 56 | |
| 57 | const inputs: PackInputs = $tensors; |
| 58 | const attrs: PackAttrs = {axis}; |
| 59 | |
| 60 | return ENGINE.runKernel( |
| 61 | Pack, inputs as unknown as NamedTensorMap, |
| 62 | attrs as unknown as NamedAttrMap); |
| 63 | } |
| 64 | |
| 65 | export const stack = /* @__PURE__ */ op({stack_}); |
nothing calls this directly
no test coverage detected
searching dependent graphs…