Substitute: diag -> diagonal.

This commit is contained in:
Sébastien Crozet 2016-04-17 19:47:56 +02:00
parent 0380661bd2
commit 0c84d18850
5 changed files with 14 additions and 14 deletions

View File

@ -838,10 +838,10 @@ macro_rules! dmat_impl(
impl<N: Copy + Clone + Zero> Diagonal<$dvector<N>> for $dmatrix<N> { impl<N: Copy + Clone + Zero> Diagonal<$dvector<N>> for $dmatrix<N> {
#[inline] #[inline]
fn from_diag(diagonal: &$dvector<N>) -> $dmatrix<N> { fn from_diagonal(diagonal: &$dvector<N>) -> $dmatrix<N> {
let mut res = $dmatrix::new_zeros(diagonal.len(), diagonal.len()); let mut res = $dmatrix::new_zeros(diagonal.len(), diagonal.len());
res.set_diag(diagonal); res.set_diagonal(diagonal);
res res
} }
@ -862,7 +862,7 @@ macro_rules! dmat_impl(
impl<N: Copy + Clone + Zero> DiagMut<$dvector<N>> for $dmatrix<N> { impl<N: Copy + Clone + Zero> DiagMut<$dvector<N>> for $dmatrix<N> {
#[inline] #[inline]
fn set_diag(&mut self, diagonal: &$dvector<N>) { fn set_diagonal(&mut self, diagonal: &$dvector<N>) {
let smallest_dim = cmp::min(self.nrows, self.ncols); let smallest_dim = cmp::min(self.nrows, self.ncols);
assert!(diagonal.len() == smallest_dim); assert!(diagonal.len() == smallest_dim);

View File

@ -499,10 +499,10 @@ macro_rules! diag_impl(
($t: ident, $tv: ident, $dimension: expr) => ( ($t: ident, $tv: ident, $dimension: expr) => (
impl<N: Copy + Zero> Diagonal<$tv<N>> for $t<N> { impl<N: Copy + Zero> Diagonal<$tv<N>> for $t<N> {
#[inline] #[inline]
fn from_diag(diagonal: &$tv<N>) -> $t<N> { fn from_diagonal(diagonal: &$tv<N>) -> $t<N> {
let mut res: $t<N> = ::zero(); let mut res: $t<N> = ::zero();
res.set_diag(diagonal); res.set_diagonal(diagonal);
res res
} }
@ -521,7 +521,7 @@ macro_rules! diag_impl(
impl<N: Copy + Zero> DiagMut<$tv<N>> for $t<N> { impl<N: Copy + Zero> DiagMut<$tv<N>> for $t<N> {
#[inline] #[inline]
fn set_diag(&mut self, diagonal: &$tv<N>) { fn set_diagonal(&mut self, diagonal: &$tv<N>) {
for i in 0 .. $dimension { for i in 0 .. $dimension {
unsafe { self.unsafe_set((i, i), diagonal.unsafe_at(i)) } unsafe { self.unsafe_set((i, i), diagonal.unsafe_at(i)) }
} }

View File

@ -123,8 +123,8 @@ macro_rules! diag_impl(
($t: ident, $tv: ident) => ( ($t: ident, $tv: ident) => (
impl<N: Copy + Zero> Diagonal<$tv<N>> for $t<N> { impl<N: Copy + Zero> Diagonal<$tv<N>> for $t<N> {
#[inline] #[inline]
fn from_diag(diagonal: &$tv<N>) -> $t<N> { fn from_diagonal(diagonal: &$tv<N>) -> $t<N> {
$t { submatrix: Diagonal::from_diag(diagonal) } $t { submatrix: Diagonal::from_diagonal(diagonal) }
} }
#[inline] #[inline]

View File

@ -169,7 +169,7 @@ pub trait Dimension: Sized {
/// Trait to get the diagonal of square matrices. /// Trait to get the diagonal of square matrices.
pub trait Diagonal<V> { pub trait Diagonal<V> {
/// Creates a new matrix with the given diagonal. /// Creates a new matrix with the given diagonal.
fn from_diag(diagonal: &V) -> Self; fn from_diagonal(diagonal: &V) -> Self;
/// The diagonal of this matrix. /// The diagonal of this matrix.
fn diagonal(&self) -> V; fn diagonal(&self) -> V;
@ -178,7 +178,7 @@ pub trait Diagonal<V> {
/// Trait to set the diagonal of square matrices. /// Trait to set the diagonal of square matrices.
pub trait DiagMut<V>: Diagonal<V> { pub trait DiagMut<V>: Diagonal<V> {
/// Sets the diagonal of this matrix. /// Sets the diagonal of this matrix.
fn set_diag(&mut self, diagonal: &V); fn set_diagonal(&mut self, diagonal: &V);
} }
/// The shape of an indexable object. /// The shape of an indexable object.

View File

@ -49,7 +49,7 @@ macro_rules! test_cholesky_impl(
// construct symmetric positive definite matrix // construct symmetric positive definite matrix
let mut randmatrix : $t = random(); let mut randmatrix : $t = random();
let mut diagmatrix : $t = Diagonal::from_diag(&na::diagonal(&randmatrix)); let mut diagmatrix : $t = Diagonal::from_diagonal(&na::diagonal(&randmatrix));
diagmatrix = na::abs(&diagmatrix) + 1.0; diagmatrix = na::abs(&diagmatrix) + 1.0;
randmatrix = randmatrix * diagmatrix * na::transpose(&randmatrix); randmatrix = randmatrix * diagmatrix * na::transpose(&randmatrix);
@ -98,7 +98,7 @@ macro_rules! test_eigen_qr_impl(
let randmatrix = na::transpose(&randmatrix) * randmatrix; let randmatrix = na::transpose(&randmatrix) * randmatrix;
let (eigenvectors, eigenvalues) = na::eigen_qr(&randmatrix, &1e-13, 100); let (eigenvectors, eigenvalues) = na::eigen_qr(&randmatrix, &1e-13, 100);
let diagonal: $t = Diagonal::from_diag(&eigenvalues); let diagonal: $t = Diagonal::from_diagonal(&eigenvalues);
let recomp = eigenvectors * diagonal * na::transpose(&eigenvectors); let recomp = eigenvectors * diagonal * na::transpose(&eigenvectors);
println!("eigenvalues: {:?}", eigenvalues); println!("eigenvalues: {:?}", eigenvalues);
println!(" matrix: {:?}", randmatrix); println!(" matrix: {:?}", randmatrix);
@ -110,10 +110,10 @@ macro_rules! test_eigen_qr_impl(
for _ in 0usize .. 10000 { for _ in 0usize .. 10000 {
let randmatrix : $t = random(); let randmatrix : $t = random();
// Take only diagonal part // Take only diagonal part
let randmatrix: $t = Diagonal::from_diag(&randmatrix.diagonal()); let randmatrix: $t = Diagonal::from_diagonal(&randmatrix.diagonal());
let (eigenvectors, eigenvalues) = na::eigen_qr(&randmatrix, &1e-13, 100); let (eigenvectors, eigenvalues) = na::eigen_qr(&randmatrix, &1e-13, 100);
let diagonal: $t = Diagonal::from_diag(&eigenvalues); let diagonal: $t = Diagonal::from_diagonal(&eigenvalues);
let recomp = eigenvectors * diagonal * na::transpose(&eigenvectors); let recomp = eigenvectors * diagonal * na::transpose(&eigenvectors);
println!("eigenvalues: {:?}", eigenvalues); println!("eigenvalues: {:?}", eigenvalues);
println!(" matrix: {:?}", randmatrix); println!(" matrix: {:?}", randmatrix);