pub struct igraph_matrix_int_t { /* private fields */ }Implementations§
Source§impl igraph_matrix_int_t
impl igraph_matrix_int_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_int_t],
) -> Result<Self>
pub fn from_column_major( nrow: usize, ncol: usize, data: &[igraph_int_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_int_t],
) -> Result<Self>
pub fn from_row_major( nrow: usize, ncol: usize, data: &[igraph_int_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_int_t]>>(rows: &[R]) -> Result<Self>
pub fn from_rows<R: AsRef<[igraph_int_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_int_t] ⓘ
pub fn as_slice(&self) -> &[igraph_int_t] ⓘ
All the elements, in column-major order.
Sourcepub fn as_mut_slice(&mut self) -> &mut [igraph_int_t] ⓘ
pub fn as_mut_slice(&mut self) -> &mut [igraph_int_t] ⓘ
All the elements, in column-major order, mutably.
Sourcepub fn get(&self, row: usize, col: usize) -> Option<&igraph_int_t>
pub fn get(&self, row: usize, col: usize) -> Option<&igraph_int_t>
The element at (row, col), if in bounds.
Sourcepub fn column(&self, j: usize) -> &[igraph_int_t] ⓘ
pub fn column(&self, j: usize) -> &[igraph_int_t] ⓘ
Sourcepub fn rows(&self) -> impl Iterator<Item = Vec<igraph_int_t>> + '_
pub fn rows(&self) -> impl Iterator<Item = Vec<igraph_int_t>> + '_
Iterates over copies of the rows.
Sourcepub fn columns(&self) -> impl Iterator<Item = &[igraph_int_t]> + '_
pub fn columns(&self) -> impl Iterator<Item = &[igraph_int_t]> + '_
Iterates over the columns, as slices.
Sourcepub fn to_rows(&self) -> Vec<Vec<igraph_int_t>>
pub fn to_rows(&self) -> Vec<Vec<igraph_int_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_int_t
impl igraph_matrix_int_t
Sourcepub fn view(
data: &[igraph_int_t],
nrow: usize,
ncol: usize,
) -> Result<View<'_, Self>>
pub fn view( data: &[igraph_int_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_int_t)
pub fn fill(&mut self, value: igraph_int_t)
Sets every element to value
(igraph_matrix_fill).
Sourcepub fn set_row(&mut self, i: usize, values: &[igraph_int_t]) -> Result<()>
pub fn set_row(&mut self, i: usize, values: &[igraph_int_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_int_t]) -> Result<()>
pub fn set_col(&mut self, j: usize, values: &[igraph_int_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_int_t) -> bool
pub fn contains(&self, value: igraph_int_t) -> bool
Whether some element equals value
(igraph_matrix_contains).
Sourcepub fn search(&self, from: usize, value: igraph_int_t) -> Option<(usize, usize)>
pub fn search(&self, from: usize, value: igraph_int_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_int_t> ⓘ
pub fn diagonal(&self) -> Vec<igraph_int_t> ⓘ
The main diagonal, m[(i, i)] for i < min(nrow, ncol).
Sourcepub fn indexed_iter(
&self,
) -> impl Iterator<Item = ((usize, usize), &igraph_int_t)> + '_
pub fn indexed_iter( &self, ) -> impl Iterator<Item = ((usize, usize), &igraph_int_t)> + '_
Iterates over ((row, col), &value) in column-major order.
Source§impl igraph_matrix_int_t
impl igraph_matrix_int_t
Sourcepub fn min(&self) -> Option<igraph_int_t>
pub fn min(&self) -> Option<igraph_int_t>
The smallest element, or None if the matrix is empty
(igraph_matrix_min).
Sourcepub fn max(&self) -> Option<igraph_int_t>
pub fn max(&self) -> Option<igraph_int_t>
The largest element, or None if the matrix is empty
(igraph_matrix_max).
Sourcepub fn which_min(&self) -> Option<(usize, usize)>
pub fn which_min(&self) -> Option<(usize, usize)>
(row, col) of the smallest element, or None if empty
(igraph_matrix_which_min).
Sourcepub fn which_max(&self) -> Option<(usize, usize)>
pub fn which_max(&self) -> Option<(usize, usize)>
(row, col) of the largest element, or None if empty
(igraph_matrix_which_max).
Sourcepub fn minmax(&self) -> Option<(igraph_int_t, igraph_int_t)>
pub fn minmax(&self) -> Option<(igraph_int_t, igraph_int_t)>
(min, max), or None if empty (as igraph_matrix_minmax).
Sourcepub fn maxdifference(&self, other: &Self) -> f64
pub fn maxdifference(&self, other: &Self) -> f64
The largest absolute element-wise difference, comparing the
elements in column-major order
(igraph_matrix_maxdifference).
Sourcepub fn all_l(&self, other: &Self) -> bool
pub fn all_l(&self, other: &Self) -> bool
Whether the shapes agree and every element is < the other’s
(igraph_matrix_all_l).
Sourcepub fn all_g(&self, other: &Self) -> bool
pub fn all_g(&self, other: &Self) -> bool
Whether the shapes agree and every element is > the other’s
(igraph_matrix_all_g).
Sourcepub fn all_le(&self, other: &Self) -> bool
pub fn all_le(&self, other: &Self) -> bool
Whether the shapes agree and every element is <= the other’s
(igraph_matrix_all_le).
Sourcepub fn all_ge(&self, other: &Self) -> bool
pub fn all_ge(&self, other: &Self) -> bool
Whether the shapes agree and every element is >= the other’s
(igraph_matrix_all_ge).
Source§impl igraph_matrix_int_t
impl igraph_matrix_int_t
Sourcepub fn add(&mut self, other: &Self) -> Result<()>
pub fn add(&mut self, other: &Self) -> Result<()>
Element-wise self += other, wrapping on overflow (Rust counterpart
of igraph_matrix_int_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, wrapping on overflow (Rust counterpart
of igraph_matrix_int_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, wrapping on overflow (Rust counterpart of
igraph_matrix_int_mul_elements).
§Errors
ErrorKind::InvalidValue if the shapes differ.
Sourcepub fn scale(&mut self, factor: igraph_int_t)
pub fn scale(&mut self, factor: igraph_int_t)
Multiplies every element by factor, wrapping on overflow (Rust
counterpart of igraph_matrix_int_scale).
Sourcepub fn add_constant(&mut self, value: igraph_int_t)
pub fn add_constant(&mut self, value: igraph_int_t)
Adds value to every element, wrapping on overflow (Rust
counterpart of igraph_matrix_int_add_constant).
Sourcepub fn div_elements(&mut self, other: &Self) -> Result<()>
pub fn div_elements(&mut self, other: &Self) -> Result<()>
Element-wise integer division self[(i,j)] /= other[(i,j)], rounding
towards zero (Rust counterpart of igraph_matrix_int_div_elements,
whose C version traps on a zero divisor).
§Errors
ErrorKind::InvalidValue if
the shapes differ or some divisor is zero (nothing is modified then).
Sourcepub fn prod(&self) -> igraph_int_t
pub fn prod(&self) -> igraph_int_t
Product of all elements (one for an empty matrix), wrapping on
overflow (Rust counterpart of igraph_matrix_int_prod).
Sourcepub fn sum(&self) -> igraph_int_t
pub fn sum(&self) -> igraph_int_t
Sum of all elements, wrapping on overflow (Rust counterpart of
igraph_matrix_int_sum).
Sourcepub fn rowsums(&self) -> Vec<igraph_int_t> ⓘ
pub fn rowsums(&self) -> Vec<igraph_int_t> ⓘ
The sum of each row (Rust counterpart of igraph_matrix_int_rowsum).
Sourcepub fn colsums(&self) -> Vec<igraph_int_t> ⓘ
pub fn colsums(&self) -> Vec<igraph_int_t> ⓘ
The sum of each column (Rust counterpart of igraph_matrix_int_colsum).
Trait Implementations§
Source§impl Clone for igraph_matrix_int_t
impl Clone for igraph_matrix_int_t
Source§impl Debug for igraph_matrix_int_t
impl Debug for igraph_matrix_int_t
Source§impl Default for igraph_matrix_int_t
impl Default for igraph_matrix_int_t
Source§impl Display for igraph_matrix_int_t
impl Display for igraph_matrix_int_t
Source§impl Drop for igraph_matrix_int_t
impl Drop for igraph_matrix_int_t
Source§impl From<&igraph_matrix_int_t> for igraph_matrix_t
impl From<&igraph_matrix_int_t> for igraph_matrix_t
Source§fn from(m: &igraph_matrix_int_t) -> Self
fn from(m: &igraph_matrix_int_t) -> Self
Converts an integer matrix to a real one.