pub struct igraph_matrix_bool_t { /* private fields */ }Implementations§
Source§impl igraph_matrix_bool_t
impl igraph_matrix_bool_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_bool_t],
) -> Result<Self>
pub fn from_column_major( nrow: usize, ncol: usize, data: &[igraph_bool_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_bool_t],
) -> Result<Self>
pub fn from_row_major( nrow: usize, ncol: usize, data: &[igraph_bool_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_bool_t]>>(rows: &[R]) -> Result<Self>
pub fn from_rows<R: AsRef<[igraph_bool_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_bool_t] ⓘ
pub fn as_slice(&self) -> &[igraph_bool_t] ⓘ
All the elements, in column-major order.
Sourcepub fn as_mut_slice(&mut self) -> &mut [igraph_bool_t] ⓘ
pub fn as_mut_slice(&mut self) -> &mut [igraph_bool_t] ⓘ
All the elements, in column-major order, mutably.
Sourcepub fn get(&self, row: usize, col: usize) -> Option<&igraph_bool_t>
pub fn get(&self, row: usize, col: usize) -> Option<&igraph_bool_t>
The element at (row, col), if in bounds.
Sourcepub fn column(&self, j: usize) -> &[igraph_bool_t] ⓘ
pub fn column(&self, j: usize) -> &[igraph_bool_t] ⓘ
Sourcepub fn rows(&self) -> impl Iterator<Item = Vec<igraph_bool_t>> + '_
pub fn rows(&self) -> impl Iterator<Item = Vec<igraph_bool_t>> + '_
Iterates over copies of the rows.
Sourcepub fn columns(&self) -> impl Iterator<Item = &[igraph_bool_t]> + '_
pub fn columns(&self) -> impl Iterator<Item = &[igraph_bool_t]> + '_
Iterates over the columns, as slices.
Sourcepub fn to_rows(&self) -> Vec<Vec<igraph_bool_t>>
pub fn to_rows(&self) -> Vec<Vec<igraph_bool_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_bool_t
impl igraph_matrix_bool_t
Sourcepub fn view(
data: &[igraph_bool_t],
nrow: usize,
ncol: usize,
) -> Result<View<'_, Self>>
pub fn view( data: &[igraph_bool_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_bool_t)
pub fn fill(&mut self, value: igraph_bool_t)
Sets every element to value
(igraph_matrix_fill).
Sourcepub fn set_row(&mut self, i: usize, values: &[igraph_bool_t]) -> Result<()>
pub fn set_row(&mut self, i: usize, values: &[igraph_bool_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_bool_t]) -> Result<()>
pub fn set_col(&mut self, j: usize, values: &[igraph_bool_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_bool_t) -> bool
pub fn contains(&self, value: igraph_bool_t) -> bool
Whether some element equals value
(igraph_matrix_contains).
Sourcepub fn search(
&self,
from: usize,
value: igraph_bool_t,
) -> Option<(usize, usize)>
pub fn search( &self, from: usize, value: igraph_bool_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_bool_t> ⓘ
pub fn diagonal(&self) -> Vec<igraph_bool_t> ⓘ
The main diagonal, m[(i, i)] for i < min(nrow, ncol).
Sourcepub fn indexed_iter(
&self,
) -> impl Iterator<Item = ((usize, usize), &igraph_bool_t)> + '_
pub fn indexed_iter( &self, ) -> impl Iterator<Item = ((usize, usize), &igraph_bool_t)> + '_
Iterates over ((row, col), &value) in column-major order.
Source§impl igraph_matrix_bool_t
impl igraph_matrix_bool_t
Sourcepub fn count_true(&self) -> usize
pub fn count_true(&self) -> usize
Number of true elements.