pub fn stack_tensor2d(
tensors: &[ArrayBase<OwnedRepr<f32>, Dim<[usize; 2]>>],
) -> Result<ArrayBase<OwnedRepr<f32>, Dim<[usize; 3]>>, OCRError>Expand description
Stacks a slice of 2D tensors into a single 3D tensor.
§Arguments
tensors- A slice of 2D tensors to stack.
§Returns
Ok(Tensor3D)- A 3D tensor created by stacking the input tensors.Err(OCRError)- An error if the input tensors are invalid (e.g., empty, inconsistent shapes).
§Examples
use oar_ocr_core::utils::tensor::{stack_tensor2d, vec_to_tensor2d};
// Create tensors first
let data1 = vec![vec![1.0, 2.0], vec![3.0, 4.0]];
let data2 = vec![vec![5.0, 6.0], vec![7.0, 8.0]];
let tensor1 = vec_to_tensor2d(&data1)?;
let tensor2 = vec_to_tensor2d(&data2)?;
let tensors = vec![tensor1, tensor2];
let stacked_tensor = stack_tensor2d(&tensors)?;