pub struct igraph_matrix_complex_t { /* private fields */ }Implementations§
Source§impl igraph_matrix_complex_t
impl igraph_matrix_complex_t
Sourcepub fn zeros(nrow: usize, ncol: usize) -> Self
pub fn zeros(nrow: usize, ncol: usize) -> Self
Creates a nrow × ncol matrix filled with zeros
(igraph_matrix_init).
§Panics
If igraph cannot allocate the matrix, or the size overflows,
like Vec::with_capacity.
Sourcepub fn from_column_major(
nrow: usize,
ncol: usize,
data: &[igraph_complex_t],
) -> Result<Self>
pub fn from_column_major( nrow: usize, ncol: usize, data: &[igraph_complex_t], ) -> Result<Self>
Builds a matrix from its elements given in column-major order
(igraph’s storage order, see
igraph_matrix_init_array).
§Errors
ErrorKind::InvalidValue
if data.len() != nrow * ncol.
Sourcepub fn from_row_major(
nrow: usize,
ncol: usize,
data: &[igraph_complex_t],
) -> Result<Self>
pub fn from_row_major( nrow: usize, ncol: usize, data: &[igraph_complex_t], ) -> Result<Self>
Builds a matrix from its elements given in row-major order.
§Errors
ErrorKind::InvalidValue
if data.len() != nrow * ncol.
Sourcepub fn from_rows<R: AsRef<[igraph_complex_t]>>(rows: &[R]) -> Result<Self>
pub fn from_rows<R: AsRef<[igraph_complex_t]>>(rows: &[R]) -> Result<Self>
Builds a matrix from a slice of rows (a 0 × 0 matrix for no
rows).
§Errors
ErrorKind::InvalidValue
if the rows do not all have the same length.
Sourcepub fn nrow(&self) -> usize
pub fn nrow(&self) -> usize
Number of rows (igraph_matrix_nrow).
Sourcepub fn ncol(&self) -> usize
pub fn ncol(&self) -> usize
Number of columns (igraph_matrix_ncol).
Sourcepub fn as_slice(&self) -> &[igraph_complex_t]
pub fn as_slice(&self) -> &[igraph_complex_t]
All the elements, in column-major order.
Sourcepub fn as_mut_slice(&mut self) -> &mut [igraph_complex_t]
pub fn as_mut_slice(&mut self) -> &mut [igraph_complex_t]
All the elements, in column-major order, mutably.
Sourcepub fn get(&self, row: usize, col: usize) -> Option<&igraph_complex_t>
pub fn get(&self, row: usize, col: usize) -> Option<&igraph_complex_t>
The element at (row, col), if in bounds.
Sourcepub fn column(&self, j: usize) -> &[igraph_complex_t]
pub fn column(&self, j: usize) -> &[igraph_complex_t]
Sourcepub fn row(&self, i: usize) -> Vec<igraph_complex_t>
pub fn row(&self, i: usize) -> Vec<igraph_complex_t>
Sourcepub fn rows(&self) -> impl Iterator<Item = Vec<igraph_complex_t>> + '_
pub fn rows(&self) -> impl Iterator<Item = Vec<igraph_complex_t>> + '_
Iterates over copies of the rows.
Sourcepub fn columns(&self) -> impl Iterator<Item = &[igraph_complex_t]> + '_
pub fn columns(&self) -> impl Iterator<Item = &[igraph_complex_t]> + '_
Iterates over the columns, as slices.
Sourcepub fn to_rows(&self) -> Vec<Vec<igraph_complex_t>>
pub fn to_rows(&self) -> Vec<Vec<igraph_complex_t>>
Converts into a row-major Vec of rows.
Sourcepub fn transposed(&self) -> Self
pub fn transposed(&self) -> Self
Returns the transposed matrix.
Sourcepub fn resize(&mut self, nrow: usize, ncol: usize)
pub fn resize(&mut self, nrow: usize, ncol: usize)
Resizes to nrow × ncol
(igraph_matrix_resize); igraph
does not preserve the content meaningfully, so this wrapper
resets every element to zero. Use
add_rows, add_cols,
remove_row and
remove_col to keep the content.
Source§impl igraph_matrix_complex_t
impl igraph_matrix_complex_t
Sourcepub fn view(
data: &[igraph_complex_t],
nrow: usize,
ncol: usize,
) -> Result<View<'_, Self>>
pub fn view( data: &[igraph_complex_t], nrow: usize, ncol: usize, ) -> Result<View<'_, Self>>
A read-only matrix view of column-major data, without
copying it; the view dereferences to the matrix type, so it
can be handed to igraph as a const matrix input
(igraph_matrix_view).
§Errors
ErrorKind::InvalidValue
if data.len() != nrow * ncol.
Sourcepub fn fill(&mut self, value: igraph_complex_t)
pub fn fill(&mut self, value: igraph_complex_t)
Sets every element to value
(igraph_matrix_fill).
Sourcepub fn set_row(&mut self, i: usize, values: &[igraph_complex_t]) -> Result<()>
pub fn set_row(&mut self, i: usize, values: &[igraph_complex_t]) -> Result<()>
Replaces row i with values
(igraph_matrix_set_row).
§Errors
ErrorKind::InvalidValue
if i is out of bounds or values.len() != ncol.
Sourcepub fn set_col(&mut self, j: usize, values: &[igraph_complex_t]) -> Result<()>
pub fn set_col(&mut self, j: usize, values: &[igraph_complex_t]) -> Result<()>
Replaces column j with values
(igraph_matrix_set_col).
§Errors
ErrorKind::InvalidValue
if j is out of bounds or values.len() != nrow.
Sourcepub fn select_rows(&self, rows: &[igraph_int_t]) -> Result<Self>
pub fn select_rows(&self, rows: &[igraph_int_t]) -> Result<Self>
A new matrix made of the given rows, in the given order
(repetitions allowed)
(igraph_matrix_select_rows).
§Errors
ErrorKind::InvalidValue for out of bounds rows.
Sourcepub fn select_cols(&self, cols: &[igraph_int_t]) -> Result<Self>
pub fn select_cols(&self, cols: &[igraph_int_t]) -> Result<Self>
A new matrix made of the given columns, in the given order
(igraph_matrix_select_cols).
§Errors
ErrorKind::InvalidValue for out of bounds columns.
Sourcepub fn select_rows_cols(
&self,
rows: &[igraph_int_t],
cols: &[igraph_int_t],
) -> Result<Self>
pub fn select_rows_cols( &self, rows: &[igraph_int_t], cols: &[igraph_int_t], ) -> Result<Self>
The submatrix at the intersection of the given rows and columns
(igraph_matrix_select_rows_cols).
§Errors
ErrorKind::InvalidValue for out of bounds indices.
Sourcepub fn swap_rows(&mut self, i: usize, j: usize) -> Result<()>
pub fn swap_rows(&mut self, i: usize, j: usize) -> Result<()>
Swaps rows i and j
(igraph_matrix_swap_rows).
§Errors
ErrorKind::InvalidValue for out of bounds rows.
Sourcepub fn swap_cols(&mut self, i: usize, j: usize) -> Result<()>
pub fn swap_cols(&mut self, i: usize, j: usize) -> Result<()>
Swaps columns i and j
(igraph_matrix_swap_cols).
§Errors
ErrorKind::InvalidValue for out of bounds columns.
Sourcepub fn transpose(&mut self)
pub fn transpose(&mut self)
Transposes the matrix in place
(igraph_matrix_transpose);
see also transposed.
Sourcepub fn rbind(&mut self, other: &Self) -> Result<()>
pub fn rbind(&mut self, other: &Self) -> Result<()>
Appends the rows of other below this matrix
(igraph_matrix_rbind).
§Errors
ErrorKind::InvalidValue if the column counts differ.
Sourcepub fn cbind(&mut self, other: &Self) -> Result<()>
pub fn cbind(&mut self, other: &Self) -> Result<()>
Appends the columns of other to the right of this matrix
(igraph_matrix_cbind).
§Errors
ErrorKind::InvalidValue if the row counts differ.
Sourcepub fn add_rows(&mut self, n: usize)
pub fn add_rows(&mut self, n: usize)
Appends n rows of zeros
(igraph_matrix_add_rows).
Sourcepub fn add_cols(&mut self, n: usize)
pub fn add_cols(&mut self, n: usize)
Appends n columns of zeros
(igraph_matrix_add_cols).
Sourcepub fn remove_row(&mut self, i: usize) -> Result<()>
pub fn remove_row(&mut self, i: usize) -> Result<()>
Sourcepub fn remove_col(&mut self, j: usize) -> Result<()>
pub fn remove_col(&mut self, j: usize) -> Result<()>
Sourcepub fn is_symmetric(&self) -> bool
pub fn is_symmetric(&self) -> bool
Whether the matrix is square and equal to its transpose
(igraph_matrix_is_symmetric).
Sourcepub fn contains(&self, value: igraph_complex_t) -> bool
pub fn contains(&self, value: igraph_complex_t) -> bool
Whether some element equals value
(igraph_matrix_contains).
Sourcepub fn search(
&self,
from: usize,
value: igraph_complex_t,
) -> Option<(usize, usize)>
pub fn search( &self, from: usize, value: igraph_complex_t, ) -> Option<(usize, usize)>
The (row, col) of the first occurrence of value at or after
the column-major position from, if any
(igraph_matrix_search).
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Number of elements the matrix can hold without reallocating
(igraph_matrix_capacity).
Sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Frees the unused storage
(igraph_matrix_resize_min).
Sourcepub fn diagonal(&self) -> Vec<igraph_complex_t>
pub fn diagonal(&self) -> Vec<igraph_complex_t>
The main diagonal, m[(i, i)] for i < min(nrow, ncol).
Sourcepub fn indexed_iter(
&self,
) -> impl Iterator<Item = ((usize, usize), &igraph_complex_t)> + '_
pub fn indexed_iter( &self, ) -> impl Iterator<Item = ((usize, usize), &igraph_complex_t)> + '_
Iterates over ((row, col), &value) in column-major order.
Source§impl igraph_matrix_complex_t
impl igraph_matrix_complex_t
Sourcepub fn from_parts(re: &Matrix, im: &Matrix) -> Result<Self>
pub fn from_parts(re: &Matrix, im: &Matrix) -> Result<Self>
Builds a complex matrix from the matrices of its real and imaginary
parts (igraph_matrix_complex_create).
use igraph::prelude::*;
let re = Matrix::from_rows(&[[1.0, 0.0], [0.0, 1.0]]).unwrap();
let im = Matrix::from_rows(&[[0.0, -1.0], [1.0, 0.0]]).unwrap();
let z = MatrixComplex::from_parts(&re, &im).unwrap();
assert_eq!(z[(1, 0)].im(), 1.0);
let (r, i) = z.realimag();
assert_eq!((r, i), (re, im));§Errors
ErrorKind::InvalidValue if the shapes differ.
Sourcepub fn from_polar(r: &Matrix, theta: &Matrix) -> Result<Self>
pub fn from_polar(r: &Matrix, theta: &Matrix) -> Result<Self>
Builds a complex matrix from the moduli r and arguments theta
(radians) of its elements
(igraph_matrix_complex_create_polar).
§Errors
ErrorKind::InvalidValue if the shapes differ.
Sourcepub fn real(&self) -> Matrix
pub fn real(&self) -> Matrix
The real parts
(igraph_matrix_complex_real).
Sourcepub fn imag(&self) -> Matrix
pub fn imag(&self) -> Matrix
The imaginary parts
(igraph_matrix_complex_imag).
Sourcepub fn realimag(&self) -> (Matrix, Matrix)
pub fn realimag(&self) -> (Matrix, Matrix)
(real parts, imaginary parts) in one call
(igraph_matrix_complex_realimag).
Sourcepub fn add(&mut self, other: &Self) -> Result<()>
pub fn add(&mut self, other: &Self) -> Result<()>
Element-wise self += other
(igraph_matrix_complex_add).
§Errors
ErrorKind::InvalidValue if the shapes differ.
Sourcepub fn sub(&mut self, other: &Self) -> Result<()>
pub fn sub(&mut self, other: &Self) -> Result<()>
Element-wise self -= other
(igraph_matrix_complex_sub).
§Errors
ErrorKind::InvalidValue if the shapes differ.
Sourcepub fn mul_elements(&mut self, other: &Self) -> Result<()>
pub fn mul_elements(&mut self, other: &Self) -> Result<()>
Element-wise product
(igraph_matrix_complex_mul_elements).
§Errors
ErrorKind::InvalidValue if the shapes differ.
Sourcepub fn div_elements(&mut self, other: &Self) -> Result<()>
pub fn div_elements(&mut self, other: &Self) -> Result<()>
Element-wise division
(igraph_matrix_complex_div_elements).
§Errors
ErrorKind::InvalidValue if the shapes differ.
Sourcepub fn scale(&mut self, factor: igraph_complex_t)
pub fn scale(&mut self, factor: igraph_complex_t)
Multiplies every element by factor
(igraph_matrix_complex_scale).
Sourcepub fn add_constant(&mut self, value: igraph_complex_t)
pub fn add_constant(&mut self, value: igraph_complex_t)
Adds value to every element
(igraph_matrix_complex_add_constant).
Sourcepub fn sum(&self) -> igraph_complex_t
pub fn sum(&self) -> igraph_complex_t
Sum of all elements
(igraph_matrix_complex_sum).
Sourcepub fn prod(&self) -> igraph_complex_t
pub fn prod(&self) -> igraph_complex_t
Product of all elements (one for an empty matrix)
(igraph_matrix_complex_prod).
Sourcepub fn rowsums(&self) -> Vec<igraph_complex_t>
pub fn rowsums(&self) -> Vec<igraph_complex_t>
The sum of each row
(igraph_matrix_complex_rowsum).
Sourcepub fn colsums(&self) -> Vec<igraph_complex_t>
pub fn colsums(&self) -> Vec<igraph_complex_t>
The sum of each column
(igraph_matrix_complex_colsum).
Sourcepub fn all_almost_e(&self, other: &Self, eps: f64) -> bool
pub fn all_almost_e(&self, other: &Self, eps: f64) -> bool
Whether the shapes agree and all elements are equal up to the
relative tolerance eps
(igraph_matrix_complex_all_almost_e).
Sourcepub fn zapsmall(&mut self, tol: f64) -> Result<()>
pub fn zapsmall(&mut self, tol: f64) -> Result<()>
Replaces the real and imaginary parts smaller in magnitude than the
absolute tolerance tol by exact zeros (tol = 0: igraph’s default,
about 1e-10)
(igraph_matrix_complex_zapsmall).
§Errors
ErrorKind::InvalidValue if tol < 0.