pub fn add_multiple_of_row<H>(&mut self, multiple: &F, other: &Sparse<F, C>)
    where
        H: Zero + Add<F, Output=H>,
        F: Add<F, Output=H> + From<H>,
        for<'r> &'r F: Mul<&'r F, Output=F>,
    {
        debug_assert_eq!(other.len(), self.len());
        debug_assert!(multiple.borrow().is_not_zero());

        let mut new_tuples = Vec::new();

        let mut j = 0;
        let old_data = mem::replace(&mut self.data, Vec::with_capacity(0));
        for (i, value) in old_data {
            while j < other.data.len() && other.data[j].0 < i {
                let new_value = multiple * &other.data[j].1;
                new_tuples.push((other.data[j].0, new_value.into()));
                j += 1;
            }

            if j < other.data.len() && i == other.data[j].0 {
                let new_value = value + multiple * &other.data[j].1;
                if !new_value.is_zero() {
                    new_tuples.push((i, new_value.into()));
                }
                j += 1;
            } else {
                new_tuples.push((i, value));
            }
        }
        for (j, value) in &other.data[j..] {
            new_tuples.push((*j, multiple * value));
        }

        self.data = new_tuples;
    }
/// Add the multiple of another row to this row.
///
/// # Arguments
///
/// * `multiple`: Non-zero constant that all elements of the `other` vector are multiplied with.
/// * `other`: Vector to add a multiple of to this vector.
///
/// # Return value
///
/// A new `SparseVector`.
///
/// # Note
///
/// The implementation of this method doesn't look pretty, but it seems to be reasonably fast.
/// If this method is too slow, it might be wise to consider the switching of the `SparseVector`
/// storage backend from a `Vec` to a `HashMap`.
Add the multiple of another row to this row.
Add the multiple of another row to this row .
pub fn add_multiple_of_row<H>(&mut self, multiple: &F, other: &Sparse<F, C>)
    where
        H: Zero + Add<F, Output=H>,
        F: Add<F, Output=H> + From<H>,
        for<'r> &'r F: Mul<&'r F, Output=F>,
    {
        debug_assert_eq!(other.len(), self.len());
        debug_assert!(multiple.borrow().is_not_zero());
        let mut new_tuples = Vec::new();
        let mut j = 0;
        let old_data = mem::replace(&mut self.data, Vec::with_capacity(0));
        for (i, value) in old_data {
            while j < other.data.len() && other.data[j].0 < i {
                let new_value = multiple * &other.data[j].1;
                new_tuples.push((other.data[j].0, new_value.into()));
                j += 1;
            }
            if j < other.data.len() && i == other.data[j].0 {
                let new_value = value + multiple * &other.data[j].1;
                if !new_value.is_zero() {
                    new_tuples.push((i, new_value.into()));
                }
                j += 1;
            } else {
                new_tuples.push((i, value));
            }
        }
        for (j, value) in &other.data[j..] {
            new_tuples.push((*j, multiple * value));
        }
        self.data = new_tuples;
    }
pub fn add_multiple_of_row < H > ( & mut self , multiple : & F , other : & Sparse < F , C > ) where H : Zero + Add < F , Output = H > , F : Add < F , Output = H > + From < H > , for < ' r > & ' r F : Mul < & ' r F , Output = F > , { debug_assert_eq ! ( other len ( ) self len ( ) ) ; debug_assert ! ( multiple borrow ( ) is_not_zero ( ) ) ; let mut new_tuples = Vec :: new ( ) ; let mut j = 0 ; let old_data = mem :: replace ( & mut self . data , Vec :: with_capacity ( 0 ) ) ; for ( i , value ) in old_data { while j < other . data . len ( ) && other . data [ j ] . 0 < i { let new_value = multiple * & other . data [ j ] . 1 ; new_tuples . push ( ( other . data [ j ] . 0 , new_value . into ( ) ) ) ; j += 1 ; } if j < other . data . len ( ) && i == other . data [ j ] . 0 { let new_value = value + multiple * & other . data [ j ] . 1 ; if ! new_value . is_zero ( ) { new_tuples . push ( ( i , new_value . into ( ) ) ) ; } j += 1 ; } else { new_tuples . push ( ( i , value ) ) ; } } for ( j , value ) in & other . data [ j .. ] { new_tuples . push ( ( * j , multiple * value ) ) ; } self . data = new_tuples ; }
Add the multiple of another row to this row.
Add the multiple of another row to this row .
&mut self
multiple
&F
other
&Sparse<F, C>
&mut self
multiple
&F
other
&Sparse<F, C>
return value
A new `SparseVector`.
A new ` SparseVector ` .
note
The implementation of this method doesn't look pretty, but it seems to be reasonably fast.
If this method is too slow, it might be wise to consider the switching of the `SparseVector`
storage backend from a `Vec` to a `HashMap`.
The implementation of this method doesn ' t look pretty but it seems to be reasonably fast . If this method is too slow it might be wise to consider the switching of the ` SparseVector ` storage backend from a ` Vec ` to a ` HashMap ` .