MatrixGetSubmatrix

Trait MatrixGetSubmatrix 

Source
pub trait MatrixGetSubmatrix
where Self: Sized + MatrixDimensions,
{ // Required method unsafe fn get_submatrix_unchecked( &self, row_1: i64, row_2: i64, col_1: i64, col_2: i64, ) -> Self; // Provided methods fn get_row( &self, row: impl TryInto<i64> + Display + Clone, ) -> Result<Self, MathError> { ... } unsafe fn get_row_unchecked(&self, row: i64) -> Self { ... } fn get_column( &self, column: impl TryInto<i64> + Display + Clone, ) -> Result<Self, MathError> { ... } unsafe fn get_column_unchecked(&self, column: i64) -> Self { ... } fn get_submatrix( &self, row_1: impl TryInto<i64> + Display, row_2: impl TryInto<i64> + Display, col_1: impl TryInto<i64> + Display, col_2: impl TryInto<i64> + Display, ) -> Result<Self, MathError> { ... } fn get_rows(&self) -> Vec<Self> { ... } fn get_columns(&self) -> Vec<Self> { ... } }
Expand description

Is implemented by Matrices to get submatrices such as rows, columns, etc.

Required Methods§

Source

unsafe fn get_submatrix_unchecked( &self, row_1: i64, row_2: i64, col_1: i64, col_2: i64, ) -> Self

Returns a deep copy of the submatrix defined by the given parameters and does not check the provided dimensions. There is also a safe version of this function that checks the input.

Parameters: row_1: the starting row of the submatrix row_2: the ending row of the submatrix col_1: the starting column of the submatrix col_2: the ending column of the submatrix

Returns the submatrix from (row_1, col_1) to (row_2, col_2)(exclusively).

§Safety

To use this function safely, make sure that the selected submatrix is part of the matrix. If it is not, memory leaks, unexpected panics, etc. might occur.

Provided Methods§

Source

fn get_row( &self, row: impl TryInto<i64> + Display + Clone, ) -> Result<Self, MathError>

Outputs the row vector of the specified row.

Parameters:

  • row: specifies the row of the matrix to return

Negative indices can be used to index from the back, e.g., -1 for the last element.

Returns a row vector of the matrix at the position of the given row or an error if specified row is not part of the matrix.

§Errors and Failures
Source

unsafe fn get_row_unchecked(&self, row: i64) -> Self

Outputs the row vector of the specified row.

Parameters:

  • row: specifies the row of the matrix to return

Returns a row vector of the matrix at the position of the given row.

§Safety

To use this function safely, make sure that the selected row is part of the matrix. If it is not, memory leaks, unexpected panics, etc. might occur.

Source

fn get_column( &self, column: impl TryInto<i64> + Display + Clone, ) -> Result<Self, MathError>

Outputs the column vector of the specified column.

Parameters:

  • column: specifies the column of the matrix to return

Negative indices can be used to index from the back, e.g., -1 for the last element.

Returns a column vector of the matrix at the position of the given column or an error if specified column is not part of the matrix.

§Errors and Failures
Source

unsafe fn get_column_unchecked(&self, column: i64) -> Self

Outputs the column vector of the specified column.

Parameters:

  • column: specifies the row of the matrix to return

Returns a column vector of the matrix at the position of the given column.

§Safety

To use this function safely, make sure that the selected column is part of the matrix. If it is not, memory leaks, unexpected panics, etc. might occur.

Source

fn get_submatrix( &self, row_1: impl TryInto<i64> + Display, row_2: impl TryInto<i64> + Display, col_1: impl TryInto<i64> + Display, col_2: impl TryInto<i64> + Display, ) -> Result<Self, MathError>

Returns a deep copy of the submatrix defined by the given parameters. All entries starting from (row_1, col_1) to (row_2, col_2)(inclusively) are collected in a new matrix. Note that row_1 >= row_2 and col_1 >= col_2 must hold after converting negative indices. Otherwise the function will panic.

Parameters: row_1: the starting row of the specified submatrix row_2: the ending row of the specified submatrix col_1: the starting column of the specified submatrix col_2: the ending column of the specified submatrix

Negative indices can be used to index from the back, e.g., -1 for the last element.

Returns the submatrix from (row_1, col_1) to (row_2, col_2)(inclusively) or an error if any provided row or column is larger than the matrix.

§Errors and Failures
§Panics …
  • if col_1 > col_2 or row_1 > row_2.
Source

fn get_rows(&self) -> Vec<Self>

Outputs a Vec containing all rows of the matrix in order. Use this function for simple iteration over the rows of the matrix.

§Example
use qfall_math::{integer::MatZ, traits::MatrixGetSubmatrix};
let matrix = MatZ::sample_uniform(3, 3, 0, 16).unwrap();

let mut added_rows = MatZ::new(1, 3);
for row in matrix.get_rows() {
    added_rows = added_rows + row;
}

If an index is required, use .iter().enumerate(), e.g. in this case.

use qfall_math::{integer::MatZ, traits::*};
let mut matrix = MatZ::sample_uniform(3, 3, 0, 16).unwrap();

let mut added_rows = MatZ::new(1, 3);
for (i, row) in matrix.get_rows().iter().enumerate() {
    added_rows = added_rows + row;
    matrix.set_row(i, &added_rows, 0).unwrap();
}
Source

fn get_columns(&self) -> Vec<Self>

Outputs a Vec containing all columns of the matrix in order. Use this function for simple iteration over the columns of the matrix.

§Example
use qfall_math::{integer::MatZ, traits::MatrixGetSubmatrix};
let matrix = MatZ::sample_uniform(3, 3, 0, 16).unwrap();

let mut added_columns = MatZ::new(3, 1);
for column in matrix.get_columns() {
    added_columns = added_columns + column;
}

If an index is required, use .iter().enumerate(), e.g. in this case.

use qfall_math::{integer::MatZ, traits::*};
let mut matrix = MatZ::sample_uniform(3, 3, 0, 16).unwrap();

let mut added_columns = MatZ::new(3, 1);
for (i, column) in matrix.get_columns().iter().enumerate() {
    added_columns = added_columns + column;
    matrix.set_column(i, &added_columns, 0).unwrap();
}

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§