From 6300d343566390120defa1190e84e92a457d31c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crozet?= Date: Sat, 13 Jun 2020 10:06:48 +0200 Subject: [PATCH] Add the ::ith constructor for vectors. This initializes a vectors to zero except the i-th element set to a given value. --- src/base/construction.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/base/construction.rs b/src/base/construction.rs index ae8c10d4..f810acdf 100644 --- a/src/base/construction.rs +++ b/src/base/construction.rs @@ -1011,6 +1011,14 @@ where N: Scalar + Zero + One, DefaultAllocator: Allocator, { + /// 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