Implements `Extend` for `Matrix<N, Dynamic, U1>`.
Extends a `Vector` with new rows populated from an iterator. Inspired by https://github.com/rustsim/nalgebra/issues/446#issuecomment-437931790
This commit is contained in:
parent
c3dd709c0a
commit
f711c107ca
|
@ -751,3 +751,25 @@ where
|
||||||
self.data.extend(iter);
|
self.data.extend(iter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Extend the number of rows of the `Vector` with elements from
|
||||||
|
/// a given iterator.
|
||||||
|
impl<N, S> Extend<N> for Matrix<N, Dynamic, U1, S>
|
||||||
|
where
|
||||||
|
N: Scalar,
|
||||||
|
S: Extend<N>,
|
||||||
|
{
|
||||||
|
/// Extend the number of rows of a `Vector` with elements
|
||||||
|
/// from the given iterator.
|
||||||
|
///
|
||||||
|
/// # Example
|
||||||
|
/// ```
|
||||||
|
/// use nalgebra::DVector;
|
||||||
|
/// let mut vector = DVector::from_vec(3, vec![0, 1, 2]);
|
||||||
|
/// vector.extend(vec![3, 4, 5]);
|
||||||
|
/// assert!(vector.eq(&DVector::from_vec(6, vec![0, 1, 2, 3, 4, 5])));
|
||||||
|
/// ```
|
||||||
|
fn extend<I: IntoIterator<Item=N>>(&mut self, iter: I) {
|
||||||
|
self.data.extend(iter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -258,3 +258,14 @@ impl<N, R: Dim> Extend<N> for MatrixVec<N, R, Dynamic>
|
||||||
"The number of elements produced by the given iterator was not a multiple of the number of rows.");
|
"The number of elements produced by the given iterator was not a multiple of the number of rows.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<N> Extend<N> for MatrixVec<N, Dynamic, U1>
|
||||||
|
{
|
||||||
|
/// Extends the number of rows of the `MatrixVec` with elements
|
||||||
|
/// from the given iterator.
|
||||||
|
fn extend<I: IntoIterator<Item=N>>(&mut self, iter: I)
|
||||||
|
{
|
||||||
|
self.data.extend(iter);
|
||||||
|
self.nrows = Dynamic::new(self.data.len());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue