Struct ComplexMatrix

Source
pub struct ComplexMatrix<T: Float> { /* private fields */ }
Expand description

The complex matrix struct

Implementations§

Source§

impl<T: Float> ComplexMatrix<T>

Source

pub fn new() -> Self

Create a new, initially empty ComplexMatrix

 use sparse_complex::ComplexMatrix;
 let mut m = ComplexMatrix::<f64>::new();
Source

pub fn with_capacity(capacity: usize) -> Self

Create a new, initially empty ComplexMatrix with a given capacity

 use sparse_complex::ComplexMatrix;
 let mut m = ComplexMatrix::<f64>::with_capacity(5);
Source

pub fn from_entries(entries: Vec<(usize, usize, Complex<T>)>) -> Self

Create a new ComplexMatrix from a vector of (row, col, Complex<T>) entries.

 use sparse_complex::ComplexMatrix;
 use num::Complex;
 let entries = vec![(0, 0, Complex::new(1., 1.)), (1, 1, Complex::new(1., 1.))];
 let mut m = ComplexMatrix::<f64>::from_entries(entries);
Source

pub fn add_element(&mut self, row: usize, col: usize, value: Complex<T>)

Add or set an element at location (row, col) with value.

 use sparse_complex::ComplexMatrix;
 use num::Complex;
 
 let Z1: Complex<f64> = Complex { re: 1., im: -1. };
 let Z2: Complex<f64> = Complex { re: -1., im: 1. };
 
 let mut m = ComplexMatrix::new();
 m.add_element(0, 0, Z1);
 m.add_element(1, 1, Z2);
 
 assert_eq!(m.get(0, 0), Some(&Z1));
 assert_eq!(m.get(1, 1), Some(&Z2));
Source

pub fn get(&self, row: usize, col: usize) -> Option<&Complex<T>>

Returns the Element-value at (row, col) if present, or None if not.

 use sparse_complex::ComplexMatrix;
 use num::Complex;
 
 let Z1: Complex<f64> = Complex { re: 1., im: -1. };
 let Z2: Complex<f64> = Complex { re: -1., im: 1. };
 
 let mut m = ComplexMatrix::new();
 m.add_element(0, 0, Z1);
 m.add_element(1, 1, Z2);
 
 assert_eq!(m.get(0, 0), Some(&Z1));
 assert_eq!(m.get(1, 1), Some(&Z2));
Source§

impl ComplexMatrix<f64>

Source

pub fn solve(&self, b: &mut [Complex<f64>]) -> Result<(), &'static str>

Solve the system Ax=b, where:

  • A is a complex matrix
  • b is a complex vector

Returns a Result. Ok(()) if the system was solved successfully, Err(String) if not. The result is stored in b.

The solution use the Eigen::SparseLU.

 use sparse_complex::ComplexMatrix;
 use num::Complex;
 
 let Z1: Complex<f64> = Complex { re: 1., im: -1. };
 let Z2: Complex<f64> = Complex { re: -1., im: 1. };
 
 let mut m = ComplexMatrix::new();
 m.add_element(0, 0, Z1);
 m.add_element(1, 1, Z2);
 
 let mut b = vec![Complex::new(1., 0.), Complex::new(0., 1.)];
 m.solve(&mut b).unwrap();
 
 let expected = vec![Complex::new(0.5, 0.5), Complex::new(0.5, -0.5)];
 assert_eq!(b, expected);
Source§

impl ComplexMatrix<f32>

Source

pub fn solve(&self, b: &mut [Complex<f32>]) -> Result<(), &'static str>

Solve the system Ax=b, where:

  • A is a complex matrix
  • b is a complex vector

Returns a Result. Ok(()) if the system was solved successfully, Err(String) if not. The result is stored in b.

This solution use the Eigen::SparseLU.

 use sparse_complex::ComplexMatrix;
 use num::Complex;
 
 let Z1: Complex<f32> = Complex { re: 1., im: -1. };
 let Z2: Complex<f32> = Complex { re: -1., im: 1. };
 
 let mut m = ComplexMatrix::new();
 m.add_element(0, 0, Z1);
 m.add_element(1, 1, Z2);
 
 let mut b = vec![Complex::new(1., 0.), Complex::new(0., 1.)];
 m.solve(&mut b).unwrap();
 
 let expected = vec![Complex::new(0.5, 0.5), Complex::new(0.5, -0.5)];
 assert_eq!(b, expected);

Trait Implementations§

Source§

impl<T: Clone + Float> Clone for ComplexMatrix<T>

Source§

fn clone(&self) -> ComplexMatrix<T>

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<T: Float + Display> Debug for ComplexMatrix<T>

Source§

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

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

impl<T: PartialEq + Float> PartialEq for ComplexMatrix<T>

Source§

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

Auto Trait Implementations§

§

impl<T> Freeze for ComplexMatrix<T>

§

impl<T> RefUnwindSafe for ComplexMatrix<T>
where T: RefUnwindSafe,

§

impl<T> Send for ComplexMatrix<T>
where T: Send,

§

impl<T> Sync for ComplexMatrix<T>
where T: Sync,

§

impl<T> Unpin for ComplexMatrix<T>
where T: Unpin,

§

impl<T> UnwindSafe for ComplexMatrix<T>
where T: UnwindSafe,

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.