diff --git a/CHANGELOG.md b/CHANGELOG.md index 96485d3f..758f884f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Added * 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. + * The `::repeat(...)` constructor that is an alternative name to + `::from_element(...)`. diff --git a/src/core/construction.rs b/src/core/construction.rs index 12bf5fe6..638a0ae2 100644 --- a/src/core/construction.rs +++ b/src/core/construction.rs @@ -38,6 +38,15 @@ impl MatrixMN 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. #[inline] pub fn zeros_generic(nrows: R, ncols: C) -> Self @@ -235,6 +244,14 @@ macro_rules! impl_constructors( 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`. #[inline] pub fn zeros($($args: usize),*) -> Self