Add the `repeat` constructor.
This commit is contained in:
parent
300b3d0452
commit
a35e40b38e
|
@ -8,6 +8,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
||||||
### Added
|
### Added
|
||||||
* The `mint` feature that can be enabled in order to allow conversions from
|
* The `mint` feature that can be enabled in order to allow conversions from
|
||||||
and to types of the [mint](https://crates.io/crates/mint) crate.
|
and to types of the [mint](https://crates.io/crates/mint) crate.
|
||||||
|
* The `::repeat(...)` constructor that is an alternative name to
|
||||||
|
`::from_element(...)`.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,15 @@ impl<N: Scalar, R: Dim, C: Dim> MatrixMN<N, R, C>
|
||||||
Self::from_iterator_generic(nrows, ncols, iter::repeat(elem).take(len))
|
Self::from_iterator_generic(nrows, ncols, iter::repeat(elem).take(len))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Creates a matrix with all its elements set to `elem`.
|
||||||
|
///
|
||||||
|
/// Same as `from_element_generic`.
|
||||||
|
#[inline]
|
||||||
|
pub fn repeat_generic(nrows: R, ncols: C, elem: N) -> Self {
|
||||||
|
let len = nrows.value() * ncols.value();
|
||||||
|
Self::from_iterator_generic(nrows, ncols, iter::repeat(elem).take(len))
|
||||||
|
}
|
||||||
|
|
||||||
/// Creates a matrix with all its elements set to 0.
|
/// Creates a matrix with all its elements set to 0.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn zeros_generic(nrows: R, ncols: C) -> Self
|
pub fn zeros_generic(nrows: R, ncols: C) -> Self
|
||||||
|
@ -235,6 +244,14 @@ macro_rules! impl_constructors(
|
||||||
Self::from_element_generic($($gargs, )* elem)
|
Self::from_element_generic($($gargs, )* elem)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Creates a matrix with all its elements set to `elem`.
|
||||||
|
///
|
||||||
|
/// Same as `.from_element`.
|
||||||
|
#[inline]
|
||||||
|
pub fn repeat($($args: usize,)* elem: N) -> Self {
|
||||||
|
Self::repeat_generic($($gargs, )* elem)
|
||||||
|
}
|
||||||
|
|
||||||
/// Creates a matrix with all its elements set to `0`.
|
/// Creates a matrix with all its elements set to `0`.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn zeros($($args: usize),*) -> Self
|
pub fn zeros($($args: usize),*) -> Self
|
||||||
|
|
Loading…
Reference in New Issue