pub struct DiagonalMatrix<const N: usize> {
pub elements: [f64; N],
}Expand description
A square, diagonal matrix with N rows and N columns.
matrix.elements[i] is the matrix element $A_{ii}$.
All off-diagonal elements are 0.
§Example
use hoomd_linear_algebra::matrix::DiagonalMatrix;
let a = DiagonalMatrix {
elements: [-2.0, 3.0],
};
assert_eq!(a[(0, 0)], -2.0);
assert_eq!(a[(0, 1)], 0.0);
assert_eq!(a[(1, 0)], 0.0);
assert_eq!(a[(1, 1)], 3.0);Fields§
§elements: [f64; N]The members of the diagonal of the matrix
Implementations§
Source§impl<const N: usize> DiagonalMatrix<N>
impl<const N: usize> DiagonalMatrix<N>
Trait Implementations§
Source§impl<const N: usize> Add for DiagonalMatrix<N>
impl<const N: usize> Add for DiagonalMatrix<N>
Source§fn add(self, rhs: Self) -> Self
fn add(self, rhs: Self) -> Self
Add two diagonal matrices.
§Example
use hoomd_linear_algebra::matrix::DiagonalMatrix;
let a = DiagonalMatrix {
elements: [-3.0, 2.0, -8.0],
};
let b = DiagonalMatrix {
elements: [4.0, -4.0, 12.0],
};
let c = a + b;
assert_eq!(c[0], 1.0);
assert_eq!(c[1], -2.0);
assert_eq!(c[2], 4.0);Source§type Output = DiagonalMatrix<N>
type Output = DiagonalMatrix<N>
The resulting type after applying the
+ operator.Source§impl<const N: usize> AddAssign for DiagonalMatrix<N>
impl<const N: usize> AddAssign for DiagonalMatrix<N>
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
Performs the
+= operation. Read moreSource§impl<const N: usize> Clone for DiagonalMatrix<N>
impl<const N: usize> Clone for DiagonalMatrix<N>
Source§fn clone(&self) -> DiagonalMatrix<N>
fn clone(&self) -> DiagonalMatrix<N>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<const N: usize> Debug for DiagonalMatrix<N>
impl<const N: usize> Debug for DiagonalMatrix<N>
Source§impl<'de, const N: usize> Deserialize<'de> for DiagonalMatrix<N>
impl<'de, const N: usize> Deserialize<'de> for DiagonalMatrix<N>
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<const N: usize> GeneralMatrix for DiagonalMatrix<N>
impl<const N: usize> GeneralMatrix for DiagonalMatrix<N>
Source§impl<const N: usize> Index<(usize, usize)> for DiagonalMatrix<N>
impl<const N: usize> Index<(usize, usize)> for DiagonalMatrix<N>
Source§fn index(&self, index: (usize, usize)) -> &f64
fn index(&self, index: (usize, usize)) -> &f64
Index matrix elements by (row, column).
§Example
use hoomd_linear_algebra::matrix::DiagonalMatrix;
let a = DiagonalMatrix {
elements: [1.0, 2.0, 3.0],
};
assert_eq!(a[(0, 0)], 1.0);
assert_eq!(a[(1, 1)], 2.0);
assert_eq!(a[(0, 2)], 0.0);
assert_eq!(a[(2, 2)], 3.0);Source§impl<const N: usize> Index<usize> for DiagonalMatrix<N>
impl<const N: usize> Index<usize> for DiagonalMatrix<N>
Source§impl<const N: usize, const M: usize> MatMul<DiagonalMatrix<M>> for Matrix<N, M>
impl<const N: usize, const M: usize> MatMul<DiagonalMatrix<M>> for Matrix<N, M>
Source§fn matmul(&self, rhs: &DiagonalMatrix<M>) -> Self::Output
fn matmul(&self, rhs: &DiagonalMatrix<M>) -> Self::Output
Matrix-diagonal matrix multiplication.
This is equivalent to scaling each column of a Matrix by the corresponding
element in a DiagonalMatrix.
§Examples
use hoomd_linear_algebra::{
Full, GeneralMatrix, MatMul,
matrix::{DiagonalMatrix, Matrix22},
};
let diag = DiagonalMatrix {
elements: [3.0, 4.0],
};
let a = Matrix22::full(1.0).matmul(&diag);
assert_eq!(a[(0, 1)], 4.0);
assert_eq!(a[(1, 0)], 3.0);Source§impl<const N: usize> Mul<f64> for DiagonalMatrix<N>
impl<const N: usize> Mul<f64> for DiagonalMatrix<N>
Source§fn mul(self, rhs: f64) -> Self
fn mul(self, rhs: f64) -> Self
Multiply a diagonal matrix by a scalar.
§Example
use hoomd_linear_algebra::matrix::DiagonalMatrix;
let a = DiagonalMatrix {
elements: [-3.0, 2.0, -8.0],
};
let b = a * 3.0;
assert_eq!(b[0], -9.0);
assert_eq!(b[1], 6.0);
assert_eq!(b[2], -24.0);Source§type Output = DiagonalMatrix<N>
type Output = DiagonalMatrix<N>
The resulting type after applying the
* operator.Source§impl<const N: usize> MulAssign<f64> for DiagonalMatrix<N>
impl<const N: usize> MulAssign<f64> for DiagonalMatrix<N>
Source§fn mul_assign(&mut self, rhs: f64)
fn mul_assign(&mut self, rhs: f64)
Performs the
*= operation. Read moreSource§impl<const N: usize> Neg for DiagonalMatrix<N>
impl<const N: usize> Neg for DiagonalMatrix<N>
Source§fn neg(self) -> Self
fn neg(self) -> Self
Negate a diagonal matrix.
§Example
use hoomd_linear_algebra::matrix::DiagonalMatrix;
let a = DiagonalMatrix {
elements: [-3.0, 2.0, -8.0],
};
let b = -a;
assert_eq!(b[0], 3.0);
assert_eq!(b[1], -2.0);
assert_eq!(b[2], 8.0);Source§type Output = DiagonalMatrix<N>
type Output = DiagonalMatrix<N>
The resulting type after applying the
- operator.Source§impl<const N: usize> PartialEq for DiagonalMatrix<N>
impl<const N: usize> PartialEq for DiagonalMatrix<N>
Source§impl<const N: usize> Serialize for DiagonalMatrix<N>
impl<const N: usize> Serialize for DiagonalMatrix<N>
Source§impl<const N: usize> Sub for DiagonalMatrix<N>
impl<const N: usize> Sub for DiagonalMatrix<N>
Source§fn sub(self, rhs: Self) -> Self
fn sub(self, rhs: Self) -> Self
Subtract two diagonal matrices.
§Example
use hoomd_linear_algebra::matrix::DiagonalMatrix;
let a = DiagonalMatrix {
elements: [-3.0, 2.0, -8.0],
};
let b = DiagonalMatrix {
elements: [4.0, -4.0, 12.0],
};
let c = a - b;
assert_eq!(c[0], -7.0);
assert_eq!(c[1], 6.0);
assert_eq!(c[2], -20.0);Source§type Output = DiagonalMatrix<N>
type Output = DiagonalMatrix<N>
The resulting type after applying the
- operator.Source§impl<const N: usize> SubAssign for DiagonalMatrix<N>
impl<const N: usize> SubAssign for DiagonalMatrix<N>
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
Performs the
-= operation. Read moreimpl<const N: usize> Copy for DiagonalMatrix<N>
impl<const N: usize> StructuralPartialEq for DiagonalMatrix<N>
Auto Trait Implementations§
impl<const N: usize> Freeze for DiagonalMatrix<N>
impl<const N: usize> RefUnwindSafe for DiagonalMatrix<N>
impl<const N: usize> Send for DiagonalMatrix<N>
impl<const N: usize> Sync for DiagonalMatrix<N>
impl<const N: usize> Unpin for DiagonalMatrix<N>
impl<const N: usize> UnwindSafe for DiagonalMatrix<N>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more