* Unstacks a `tf.Tensor` of rank-`R` into a list of rank-`(R-1)` `tf.Tensor`s. * * ```js * const a = tf.tensor2d([1, 2, 3, 4], [2, 2]); * * tf.unstack(a).forEach(tensor => tensor.print()); * ``` * * @param x A tensor object. * @param axis The axis to unstack along. Defaults to 0 (the first
(x: Tensor|TensorLike, axis = 0)
| 41 | * @doc {heading: 'Tensors', subheading: 'Slicing and Joining'} |
| 42 | */ |
| 43 | function unstack_(x: Tensor|TensorLike, axis = 0): Tensor[] { |
| 44 | const $x = convertToTensor(x, 'x', 'unstack', 'string_or_numeric'); |
| 45 | util.assert( |
| 46 | axis >= -$x.shape.length && axis < $x.shape.length, |
| 47 | () => |
| 48 | `Axis = ${axis} is not in [-${$x.shape.length}, ${$x.shape.length})`); |
| 49 | |
| 50 | const inputs: UnpackInputs = {value: $x}; |
| 51 | const attrs: UnpackAttrs = {axis}; |
| 52 | |
| 53 | return ENGINE.runKernel( |
| 54 | Unpack, inputs as unknown as NamedTensorMap, |
| 55 | attrs as unknown as NamedAttrMap); |
| 56 | } |
| 57 | |
| 58 | export const unstack = /* @__PURE__ */ op({unstack_}); |
nothing calls this directly
no test coverage detected
searching dependent graphs…