DiagonalMatrix

Struct DiagonalMatrix 

Source
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>

Source

pub fn to_dense(self) -> Matrix<N, N>

Construct a dense matrix with the given diagonal.

§Example
use hoomd_linear_algebra::matrix::DiagonalMatrix;

let a = DiagonalMatrix {
    elements: [-2.0, 3.0],
};
let b = a.to_dense();
assert_eq!(b.rows, [[-2.0, 0.0], [0.0, 3.0]]);

Trait Implementations§

Source§

impl<const N: usize> Add for DiagonalMatrix<N>

Source§

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>

The resulting type after applying the + operator.
Source§

impl<const N: usize> AddAssign for DiagonalMatrix<N>

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl<const N: usize> Clone for DiagonalMatrix<N>

Source§

fn clone(&self) -> DiagonalMatrix<N>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<const N: usize> Debug for DiagonalMatrix<N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de, const N: usize> Deserialize<'de> for DiagonalMatrix<N>

Source§

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>

Source§

fn zeros() -> Self

Fill a matrix with zeros. Read more
Source§

fn shape(&self) -> (usize, usize)

Get the shape of a matrix (n_rows,n_columns). Read more
Source§

impl<const N: usize> Index<(usize, usize)> for DiagonalMatrix<N>

Source§

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§

type Output = f64

The returned type after indexing.
Source§

impl<const N: usize> Index<usize> for DiagonalMatrix<N>

Source§

fn index(&self, index: usize) -> &f64

Index the diagonal components.

§Example
use hoomd_linear_algebra::{SquareMatrix, matrix::DiagonalMatrix};
let a = DiagonalMatrix {
    elements: [1.0, 2.0, 3.0],
};
assert_eq!(a[0], 1.0);
assert_eq!(a[1], 2.0);
assert_eq!(a[2], 3.0);
Source§

type Output = f64

The returned type after indexing.
Source§

impl<const N: usize> IndexMut<usize> for DiagonalMatrix<N>

Source§

fn index_mut(&mut self, index: usize) -> &mut f64

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<const N: usize, const M: usize> MatMul<DiagonalMatrix<M>> for Matrix<N, M>

Source§

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§

type Output = Matrix<N, M>

The type of the output matrix.
Source§

impl<const N: usize> Mul<f64> for DiagonalMatrix<N>

Source§

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>

The resulting type after applying the * operator.
Source§

impl<const N: usize> MulAssign<f64> for DiagonalMatrix<N>

Source§

fn mul_assign(&mut self, rhs: f64)

Performs the *= operation. Read more
Source§

impl<const N: usize> Neg for DiagonalMatrix<N>

Source§

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>

The resulting type after applying the - operator.
Source§

impl<const N: usize> PartialEq for DiagonalMatrix<N>

Source§

fn eq(&self, other: &DiagonalMatrix<N>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const N: usize> Serialize for DiagonalMatrix<N>

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<const N: usize> Sub for DiagonalMatrix<N>

Source§

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>

The resulting type after applying the - operator.
Source§

impl<const N: usize> SubAssign for DiagonalMatrix<N>

Source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
Source§

impl<const N: usize> Copy for DiagonalMatrix<N>

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,