pub fn unfold_split(
t: &TensorDynLen,
left_inds: &[DynIndex],
) -> Result<(Tensor, usize, usize, usize, Vec<DynIndex>, Vec<DynIndex>)>Expand description
Unfold a tensor into a matrix by splitting indices into left and right groups.
This function validates the split, permutes the tensor so that left indices come first, and returns a rank-2 native tenferro tensor along with metadata.
§Arguments
t- Input tensorleft_inds- Indices to place on the left (row) side of the matrix
§Returns
A tuple (matrix_tensor, left_len, m, n, left_indices, right_indices) where:
matrix_tensoris a rank-2tenferro::Tensorwith shape[m, n]left_lenis the number of left indicesmis the product of left index dimensionsnis the product of right index dimensionsleft_indicesis the vector of left indices (cloned)right_indicesis the vector of right indices (cloned)
§Errors
Returns an error if:
- The tensor rank is < 2
left_indsis empty or contains all indicesleft_indscontains indices not in the tensor or duplicates- Native reshape fails
§Examples
use tensor4all_core::{DynIndex, TensorDynLen, unfold_split};
let i = DynIndex::new_dyn(2);
let j = DynIndex::new_dyn(3);
// 2x3 dense tensor with data [1..6]
let t = TensorDynLen::from_dense(
vec![i.clone(), j.clone()],
vec![1.0, 2.0, 3.0, 4.0, 5.0, 6.0],
).unwrap();
let (matrix, left_len, m, n, left_indices, right_indices) =
unfold_split(&t, &[i]).unwrap();
assert_eq!(left_len, 1);
assert_eq!(m, 2);
assert_eq!(n, 3);
assert_eq!(left_indices.len(), 1);
assert_eq!(right_indices.len(), 1);