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:
parent
d81a895a87
commit
6300d34356
@ -1011,6 +1011,14 @@ where
|
|||||||
N: Scalar + Zero + One,
|
N: Scalar + Zero + One,
|
||||||
DefaultAllocator: Allocator<N, R>,
|
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.
|
/// The column vector with a 1 as its first component, and zero elsewhere.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn x() -> Self
|
pub fn x() -> Self
|
||||||
|
Loading…
Reference in New Issue
Block a user