Matrix2D

Struct Matrix2D 

Source
pub struct Matrix2D {
    pub rows: usize,
    pub cols: usize,
    pub data: Vec<Vec<f64>>,
}
Expand description

表示具有指定行数和列数的二维矩阵。

Fields§

§rows: usize

矩阵的行数。

§cols: usize

矩阵的列数。

§data: Vec<Vec<f64>>

以二维向量形式存储在矩阵中的数据。

Implementations§

Source§

impl Matrix2D

Source

pub fn new(data: Vec<Vec<f64>>) -> Matrix2D

创建一个新的矩阵。

§参数
  • data - 以二维向量形式表示的矩阵数据。
§返回

返回具有指定数据的 Matrix2D 实例。

§错误

如果输入数据不合法,将引发断言错误:

  • 矩阵必须至少有一行
  • 矩阵必须至少有一列
  • 所有行必须具有相同的列数
Source

pub fn print(&self)

Source

pub fn add(&self, other: &Matrix2D) -> Option<Matrix2D>

执行矩阵加法运算。

§参数
  • other - 与当前矩阵相加的另一个矩阵。
§返回

如果矩阵维度相同,返回包含相加结果的 Matrix2D 实例;如果维度不同,返回 None

Source

pub fn subtract(&self, other: &Matrix2D) -> Option<Matrix2D>

执行矩阵减法运算。

§参数
  • other - 从当前矩阵中减去的另一个矩阵。
§返回

如果矩阵维度相同,返回包含相减结果的 Matrix2D 实例;如果维度不同,返回 None

Source

pub fn multiply(&self, other: &Matrix2D) -> Matrix2D

执行矩阵乘法运算。

§参数
  • other - 与当前矩阵相乘的另一个矩阵。
§返回

包含相乘结果的 Matrix2D 实例。

§注意

如果矩阵维度不符合相乘规则,将会引发 panic。

Source

pub fn transpose(&self) -> Matrix2D

获取当前矩阵的转置。

§返回

包含转置结果的 Matrix2D 实例。

Source

pub fn determinant(&self) -> Option<f64>

Source

pub fn inverse(&self) -> Option<Matrix2D>

Source

pub fn eigenvalue_eigenvector(&self) -> Option<(Vec<f64>, Vec<Vec<f64>>)>

Source

pub fn svd(&self) -> (Matrix2D, Matrix2D, Matrix2D)

Source

pub fn multiply_by_vector(&self, vector: &Vec<f64>) -> Matrix2D

Source

pub fn eye(size: usize) -> Matrix2D

Source

pub fn zeros(rows: usize, cols: usize) -> Matrix2D

Source

pub fn eigen(&self) -> (Vec<f64>, Matrix2D)

Source

pub fn argsort(vector: &Vec<f64>) -> Vec<usize>

Source

pub fn column(&self, col_index: usize) -> Vec<f64>

Trait Implementations§

Source§

impl Clone for Matrix2D

Source§

fn clone(&self) -> Self

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 Debug for Matrix2D

Source§

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

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

impl PartialEq for Matrix2D

Source§

fn eq(&self, other: &Matrix2D) -> 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 StructuralPartialEq for Matrix2D

Auto Trait Implementations§

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.