Skip to main content

symmetrize_into

Function symmetrize_into 

Source
pub fn symmetrize_into<T>(
    dest: &mut StridedViewMut<'_, T>,
    src: &StridedView<'_, T>,
    exec: Exec<'_>,
) -> Result<(), StridedError>
where T: Copy + Add<Output = T> + Mul<Output = T> + FromPrimitive + Div<Output = T> + Send + Sync,
Expand description

Symmetrize a square matrix: dest = (src + src^T) / 2.

ยงErrors

Returns StridedError::RankMismatch when src is not rank 2, StridedError::NonSquare when its two extents differ, and StridedError::ScalarConversion only when T::from_f64(0.5) returns None. num_traits::FromPrimitive::from_f64 truncates for the primitive integer types (i32::from_f64(0.5) == Some(0)), so an integer T is not rejected: it scales by zero, and the result is zero rather than a half. Writing through zip_map2_into adds StridedError::RankMismatch or StridedError::ShapeMismatch when dest and the transposed src describe different extents, and StridedError::NonInjectiveOutputLayout when the destination layout cannot be proven representable and injective: two logical indices name one offset, or the element count or address span is too large to represent. Nothing is written unless validation succeeds.