MCPcopy Create free account
hub / github.com/tensorflow/tfjs / stack_

Function stack_

tfjs-core/src/ops/stack.ts:44–63  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

42 * @doc {heading: 'Tensors', subheading: 'Slicing and Joining'}
43 */
44function 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
65export const stack = /* @__PURE__ */ op({stack_});

Callers

nothing calls this directly

Calls 2

convertToTensorArrayFunction · 0.90
runKernelMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…