Add the ::ith constructor for vectors.

This initializes a vectors to zero except the i-th element set to a given value.
This commit is contained in:
Sébastien Crozet 2020-06-13 10:06:48 +02:00
parent d81a895a87
commit 6300d34356
1 changed files with 8 additions and 0 deletions

View File

@ -1011,6 +1011,14 @@ where
N: Scalar + Zero + One,
DefaultAllocator: Allocator<N, R>,
{
/// The column vector with `val` as its i-th component.
#[inline]
pub fn ith(i: usize, val: N) -> Self {
let mut res = Self::zeros();
res[i] = val;
res
}
/// The column vector with a 1 as its first component, and zero elsewhere.
#[inline]
pub fn x() -> Self