pub fn native_tensor_primal_to_diag<T: TensorElement>(
tensor: &Tensor,
) -> Result<Vec<T>, BridgeError>Expand description
Materialize diagonal values from a native tensor, promoting to the
matching real (f64) or complex (Complex64) dtype.
Real native tensors (f32, f64, i32, i64, bool) are promoted to
f64; complex tensors (c32, c64) are promoted to Complex64. The
scalar type T selects the promoted target.
§Errors
Returns an error when the native tensor is not compatible with the scalar target (a dtype mismatch) or the materialization fails.
§Examples
use tenferro::Tensor as NativeTensor;
use tensor4all_tensorbackend::native_tensor_primal_to_diag;
let native = NativeTensor::from_vec_col_major(vec![3, 3], vec![1.0_f64, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 3.0])?;
let diag = native_tensor_primal_to_diag::<f64>(&native)?;
assert_eq!(diag, vec![1.0, 2.0, 3.0]);