pub fn hcombine(
    lmatrix: &DMatrix<f32>,
    rmatrix: &DMatrix<f32>,
) -> Result<DMatrix<f32>, MatrixCompareError> {
    // Check for matching number of rows
    if lmatrix.shape().0 != rmatrix.shape().0 {
        return Err(MatrixCompareError);
    }

    // Allocate new matrix
    let rows = lmatrix.shape().0;
    let cols = lmatrix.shape().1 + rmatrix.shape().1;
    let mut concatenated = DMatrix::<f32>::zeros(rows, cols);

    for i in 0..lmatrix.shape().0 {
        for j in 0..lmatrix.shape().1 {
            concatenated[(i, j)] = lmatrix[(i, j)];
        }
    }

    let dy = lmatrix.shape().1;
    for i in 0..rmatrix.shape().0 {
        let mut j_rmatrix = 0;
        for j_shifted in dy..dy + rmatrix.shape().1 {
            concatenated[(i, j_shifted)] = rmatrix[(i, j_rmatrix)];
            j_rmatrix += 1;
        }
    }

    Ok(concatenated)
}
/// Horizontally combines two matrices of similar dimensions
Horizontally combines two matrices of similar dimensions
Horizontally combines two matrices of similar dimensions
pub fn hcombine(
    lmatrix: &DMatrix<f32>,
    rmatrix: &DMatrix<f32>,
) -> Result<DMatrix<f32>, MatrixCompareError> {
    // Check for matching number of rows
    if lmatrix.shape().0 != rmatrix.shape().0 {
        return Err(MatrixCompareError);
    }
    // Allocate new matrix
    let rows = lmatrix.shape().0;
    let cols = lmatrix.shape().1 + rmatrix.shape().1;
    let mut concatenated = DMatrix::<f32>::zeros(rows, cols);
    for i in 0..lmatrix.shape().0 {
        for j in 0..lmatrix.shape().1 {
            concatenated[(i, j)] = lmatrix[(i, j)];
        }
    }
    let dy = lmatrix.shape().1;
    for i in 0..rmatrix.shape().0 {
        let mut j_rmatrix = 0;
        for j_shifted in dy..dy + rmatrix.shape().1 {
            concatenated[(i, j_shifted)] = rmatrix[(i, j_rmatrix)];
            j_rmatrix += 1;
        }
    }
    Ok(concatenated)
}
pub fn hcombine ( lmatrix : & DMatrix < f32 > , rmatrix : & DMatrix < f32 > , ) -> Result < DMatrix < f32 > , MatrixCompareError > { // Check for matching number of rows if lmatrix . shape ( ) . 0 != rmatrix . shape ( ) . 0 { return Err ( MatrixCompareError ) ; } // Allocate new matrix let rows = lmatrix . shape ( ) . 0 ; let cols = lmatrix . shape ( ) . 1 + rmatrix . shape ( ) . 1 ; let mut concatenated = DMatrix :: < f32 > :: zeros ( rows , cols ) ; for i in 0 .. lmatrix . shape ( ) . 0 { for j in 0 .. lmatrix . shape ( ) . 1 { concatenated [ ( i , j ) ] = lmatrix [ ( i , j ) ] ; } } let dy = lmatrix . shape ( ) . 1 ; for i in 0 .. rmatrix . shape ( ) . 0 { let mut j_rmatrix = 0 ; for j_shifted in dy .. dy + rmatrix . shape ( ) . 1 { concatenated [ ( i , j_shifted ) ] = rmatrix [ ( i , j_rmatrix ) ] ; j_rmatrix += 1 ; } } Ok ( concatenated ) }
Horizontally combines two matrices of similar dimensions
Horizontally combines two matrices of similar dimensions
lmatrix
&DMatrix<f32>
rmatrix
&DMatrix<f32>
lmatrix
&DMatrix<f32>
rmatrix
&DMatrix<f32>