2018-10-22 04:11:27 +08:00
|
|
|
use na::{DefaultAllocator, Scalar};
|
2018-09-20 16:50:34 +08:00
|
|
|
|
2019-03-23 21:29:07 +08:00
|
|
|
use crate::aliases::{TMat, TVec};
|
|
|
|
use crate::traits::{Alloc, Dimension};
|
2018-09-20 16:50:34 +08:00
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// The `index`-th column of the matrix `m`.
|
2018-10-03 19:28:07 +08:00
|
|
|
///
|
|
|
|
/// # See also:
|
|
|
|
///
|
|
|
|
/// * [`row`](fn.row.html)
|
|
|
|
/// * [`set_column`](fn.set_column.html)
|
|
|
|
/// * [`set_row`](fn.set_row.html)
|
2020-04-06 00:49:48 +08:00
|
|
|
pub fn column<N: Scalar, R: Dimension, C: Dimension>(m: &TMat<N, R, C>, index: usize) -> TVec<N, R>
|
2018-10-22 04:11:27 +08:00
|
|
|
where
|
|
|
|
DefaultAllocator: Alloc<N, R, C>,
|
|
|
|
{
|
2018-09-20 20:23:31 +08:00
|
|
|
m.column(index).into_owned()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Sets to `x` the `index`-th column of the matrix `m`.
|
2018-10-03 19:28:07 +08:00
|
|
|
///
|
|
|
|
/// # See also:
|
|
|
|
///
|
|
|
|
/// * [`column`](fn.column.html)
|
|
|
|
/// * [`row`](fn.row.html)
|
|
|
|
/// * [`set_row`](fn.set_row.html)
|
2019-12-17 07:09:14 +08:00
|
|
|
pub fn set_column<N: Scalar, R: Dimension, C: Dimension>(
|
2018-10-22 04:11:27 +08:00
|
|
|
m: &TMat<N, R, C>,
|
|
|
|
index: usize,
|
|
|
|
x: &TVec<N, R>,
|
|
|
|
) -> TMat<N, R, C>
|
|
|
|
where
|
|
|
|
DefaultAllocator: Alloc<N, R, C>,
|
|
|
|
{
|
2018-09-20 20:23:31 +08:00
|
|
|
let mut res = m.clone();
|
|
|
|
res.set_column(index, x);
|
|
|
|
res
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// The `index`-th row of the matrix `m`.
|
2018-10-03 19:28:07 +08:00
|
|
|
///
|
|
|
|
/// # See also:
|
|
|
|
///
|
|
|
|
/// * [`column`](fn.column.html)
|
|
|
|
/// * [`set_column`](fn.set_column.html)
|
|
|
|
/// * [`set_row`](fn.set_row.html)
|
2019-12-17 07:09:14 +08:00
|
|
|
pub fn row<N: Scalar, R: Dimension, C: Dimension>(m: &TMat<N, R, C>, index: usize) -> TVec<N, C>
|
2020-04-06 00:49:48 +08:00
|
|
|
where
|
|
|
|
DefaultAllocator: Alloc<N, R, C>,
|
|
|
|
{
|
2018-09-20 20:23:31 +08:00
|
|
|
m.row(index).into_owned().transpose()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Sets to `x` the `index`-th row of the matrix `m`.
|
2018-10-03 19:28:07 +08:00
|
|
|
///
|
|
|
|
/// # See also:
|
|
|
|
///
|
|
|
|
/// * [`column`](fn.column.html)
|
|
|
|
/// * [`row`](fn.row.html)
|
|
|
|
/// * [`set_column`](fn.set_column.html)
|
2019-12-17 07:09:14 +08:00
|
|
|
pub fn set_row<N: Scalar, R: Dimension, C: Dimension>(
|
2018-10-22 04:11:27 +08:00
|
|
|
m: &TMat<N, R, C>,
|
|
|
|
index: usize,
|
|
|
|
x: &TVec<N, C>,
|
|
|
|
) -> TMat<N, R, C>
|
|
|
|
where
|
|
|
|
DefaultAllocator: Alloc<N, R, C>,
|
|
|
|
{
|
2018-09-20 20:23:31 +08:00
|
|
|
let mut res = m.clone();
|
|
|
|
res.set_row(index, &x.transpose());
|
|
|
|
res
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|