pub fn stack<T, C>(
_ctx: &mut C,
tensors: &[&Tensor<T>],
axis: usize,
) -> Result<Tensor<T>>where
T: Scalar,
C: TensorMetadataContextFor,Expand description
Stack tensors along a new dimension.
Creates a new dimension at axis and concatenates the input tensors
along it. All input tensors must have the same shape.
The context parameter enables future GPU-backend dispatch. Currently
delegates to Tensor::stack.
§Errors
Returns an error if tensors have different shapes, the axis is out of range, or the tensor list is empty.
§Examples
ⓘ
use tenferro_device::LogicalMemorySpace;
use tenferro_prims::{tensor_ops, CpuContext};
use tenferro_tensor::{MemoryOrder, Tensor};
let mut ctx = CpuContext::new(1);
let a = Tensor::<f64>::zeros(
&[2, 3],
LogicalMemorySpace::MainMemory,
MemoryOrder::ColumnMajor,
).unwrap();
let b = Tensor::<f64>::zeros(
&[2, 3],
LogicalMemorySpace::MainMemory,
MemoryOrder::ColumnMajor,
).unwrap();
let result = tensor_ops::stack(&mut ctx, &[&a, &b], 0).unwrap();
assert_eq!(result.dims(), &[2, 2, 3]);