Struct rest_tensors::matrix::MatrixFull
source · [−]Expand description
MatrixFull is a column-major
2D array designed for quantum chemistry calculations.
Basic Usage for General-purpose Use
Usage for Advanced and/or Specific Uses
-
Also provides wrappers to lapack and blas functions, including:
matrix::matrix_blas_lapack
- perform the matrix-matrix operation for C = alpha*op( A )*op( B ) + beta*C:
_dgemm
- compute the eigenvalues and, optionally, eigenvectors:
_dsyev
- compute the Cholesky factorization of a real symmetric positive definite matrix A:
_dpotrf
- perform the matrix inversion:
_dinverse
- many others …
NOTE:: all functions in lapack and blas libraries can be imported in the similar way for any matrix struct with theBasicMatrix
trait .
Construction
There are several ways to construct a matrix from different sources
- Create a new matrix filled with a given element.
use rest_tensors::MatrixFull;
let matr = MatrixFull::new([3,4],1.0f64);
//| 1.0 | 1.0 | 1.0 | 1.0 |
//| 1.0 | 1.0 | 1.0 | 1.0 |
//| 1.0 | 1.0 | 1.0 | 1.0 |
- Cenerate a new matrix from a vector. For example, a 3x4 matrix from a vector with 12 elements
use rest_tensors::MatrixFull;
let new_vec = vec![
1.0, 2.0, 3.0,
4.0, 5.0, 6.0,
7.0, 8.0, 9.0,
10.0, 11.0, 12.0];
let matr = MatrixFull::from_vec([3,4],new_vec).unwrap();
assert_eq!(matr[(1,2)],8.0)
//| 1.0 | 4.0 | 7.0 |10.0 |
//| 2.0 | 5.0 | 8.0 |11.0 |
//| 3.0 | 6.0 | 9.0 |12.0 |
Indexing
The MatrixFull
struct allows to access values by index, based on the Index
trait.
- For any matrix element, it is accessable via
[usize;2]
or(usize, usize)
in the order ofrow and column
use rest_tensors::MatrixFull;
let mut matr = MatrixFull::new([2,2],0.0);
matr[[0,0]] = 1.0;
matr[(1,1)] = 1.0;
assert_eq!(matr, MatrixFull::from_vec([2,2],vec![
1.0,0.0,
0.0,1.0]).unwrap());
- It is also accessable via
get2d(_mut)
andset2d
in the traits ofTensorOpt
and/orTensorOptMut
use rest_tensors::MatrixFull;
use rest_tensors::TensorOptMut;
let mut matr = MatrixFull::new([2,2],0.0);
let mut mat00 = matr.get2d_mut([0,0]).unwrap();
*mat00 = 1.0;
matr.set2d([1,1],1.0);
assert_eq!(matr, MatrixFull::from_vec([2,2],vec![
1.0,0.0,
0.0,1.0]).unwrap());
- For all or part of elements in the a given column, they are accessable via
(Range<usize>,usize)
or(RangeFull, usize)
, and return as a slice
use rest_tensors::MatrixFull;
let new_vec = vec![
1.0, 2.0, 3.0,
4.0, 5.0, 6.0,
7.0, 8.0, 9.0,
10.0, 11.0, 12.0];
let mut matr = MatrixFull::from_vec([3,4],new_vec).unwrap();
let mut part_column_2nd = &mut matr[(0..2,2)];
assert_eq!(part_column_2nd, &[7.0,8.0]);
let mut full_column_2nd = &mut matr[(..,2)];
assert_eq!(full_column_2nd, &[7.0,8.0,9.0]);
// _______
//| 1.0 | 4.0 || 7.0 ||10.0 |
//| 2.0 | 5.0 || 8.0 ||11.0 |
//| 3.0 | 6.0 || 9.0 ||12.0 |
// -------
- For the elements in several continued columns, they are accessable via
(RangeFull, Range<usize>)
, and return as a slice
use rest_tensors::MatrixFull;
let new_vec = vec![
1.0, 2.0, 3.0,
4.0, 5.0, 6.0,
7.0, 8.0, 9.0,
10.0, 11.0, 12.0];
let mut matr = MatrixFull::from_vec([3,4],new_vec).unwrap();
let mut columns23 = &mut matr[(..,1..3)];
assert_eq!(columns23, &[4.0,5.0,6.0,7.0,8.0,9.0]);
// _____________
//| 1.0 || 4.0 | 7.0 ||10.0 |
//| 2.0 || 5.0 | 8.0 ||11.0 |
//| 3.0 || 6.0 | 9.0 ||12.0 |
// -------------
- In general, a sub matrix in the area of
(Range<usize>, Range<usize>)
is accessable viaget_submatrix()
andget_submatrix_mut()
, and return as aSubMatrixFull<T>
andSubMatrixFullMut<T>
use rest_tensors::MatrixFull;
use rest_tensors::SubMatrixFull;
let new_vec = vec![
1.0, 2.0, 3.0,
4.0, 5.0, 6.0,
7.0, 8.0, 9.0,
10.0, 11.0, 12.0];
let mut matr = MatrixFull::from_vec([3,4],new_vec).unwrap();
let mut sub_matr = matr.get_submatrix(0..2,2..4);
assert_eq!(sub_matr.data(), vec![7.0,8.0,10.0,11.0]);
// _____________
//| 1.0 | 4.0 || 7.0 |10.0 ||
//| 2.0 | 5.0 || 8.0 |11.0 ||
// -----------
//| 3.0 | 6.0 | 9.0 |12.0 |
Math Operations
The MatrixFull
struct enables the basic mathmatic operations, including +
, +=
, -
, -=
, *
, *=
, /
, and /=
based on the traits of Add
, AddAssign
, Sub
, SubAssign
,
Mul
, MulAssign
, Div
, DivAssign
, respectively
- Add or subtract for two matrices:
MatrixFull<T>
+/-MatrixFull<T>
. NOTE: 1) The size of two matrices should be the same. Otherwise, the program stops with panic!
use rest_tensors::MatrixFull;
let vec_a = vec![
1.0, 2.0, 3.0,
4.0, 5.0, 6.0,
7.0, 8.0, 9.0,
10.0, 11.0, 12.0];
let matr_a = MatrixFull::from_vec([3,4],vec_a).unwrap();
// | 1.0 | 4.0 | 7.0 | 10.0 |
//matr_a = | 2.0 | 5.0 | 8.0 | 11.0 |
// | 3.0 | 6.0 | 9.0 | 12.0 |
let vec_b = (13..25).map(|x| x as f64).collect::<Vec<f64>>();
let matr_b = MatrixFull::from_vec([3,4],vec_b).unwrap();
// | 13.0 | 16.0 | 19.0 | 22.0 |
//matr_b = | 14.0 | 17.0 | 20.0 | 23.0 |
// | 15.0 | 18.0 | 21.0 | 24.0 |
// matr_c = matr_a + matr_b;
// NOTE: both matr_a and matr_b are consumed after `+` and `-` operations,
let mut matr_c = matr_a.clone() + matr_b.clone();
// | 14.0 | 20.0 | 26.0 | 32.0 |
//matr_c = | 16.0 | 22.0 | 28.0 | 34.0 |
// | 18.0 | 24.0 | 30.0 | 36.0 |
assert_eq!(matr_c[(..,3)], [32.0,34.0,36.0]);
// matr_c = matr_c - matr_b = matr_a
// NOTE: matr_b is consumed after `+` and `-` operations,
matr_c -= matr_b;
assert_eq!(matr_c, matr_a);
- Add or subtract between two matrices with different types:
MatrixFull<T> +/- (Sub)MatrixFull<T>
NOTE: the matrix:MatrixFull<&T>
should be used after the operators of ‘+’ and ‘-’.
use rest_tensors::MatrixFull;
let vec_a = vec![
1.0, 2.0, 3.0,
4.0, 5.0, 6.0,
7.0, 8.0, 9.0,
10.0, 11.0, 12.0];
let matr_a = MatrixFull::from_vec([3,4],vec_a).unwrap();
// | 1.0 | 4.0 | 7.0 | 10.0 |
//matr_a = | 2.0 | 5.0 | 8.0 | 11.0 | with the type of MatrixFull<f64>
// | 3.0 | 6.0 | 9.0 | 12.0 |
let matr_b = matr_a.get_submatrix(0..2,1..3);
//matr_b = | 4.0 | 7.0 |
// | 5.0 | 8.0 | with the type of SubMatrixFull<f64>(MatrixFull<&f64>)
let vec_c = (5..9).map(|x| x as f64).collect::<Vec<f64>>();
let matr_c = MatrixFull::from_vec([2,2],vec_c).unwrap();
//matr_c = | 5.0 | 7.0 |
// | 6.0 | 8.0 | with the type of MatrixFull<f64>
// matr_d = matr_b: `SubMatrixFull<f64>` + matr_c: `MatrixFull<f64>`;
// NOTE: both matr_c and matr_b are dropped after the add operation.
let mut matr_d = matr_b + matr_c.clone();
//matr_d = | 9.0 | 14.0 |
// | 11.0 | 16.0 | with the type of MatrixFull<f64>
assert_eq!(matr_d.data(), vec![9.0,11.0,14.0,16.0]);
// matr_d: `MatrixFull<f64>` -= matr_c: `SubMatrixFull<f64>` = matr_c;
// NOTE: both matr_c and matr_b are dropped after the add operation.
let matr_b = matr_a.get_submatrix(0..2,1..3);
//matr_b = | 4.0 | 7.0 |
// | 5.0 | 8.0 | with the type of SubMatrixFull<&f64>
matr_d -= matr_b;
assert_eq!(matr_d, matr_c)
- Enable
SubMatrixFullMut<T>
the operations of ‘+=’ and ‘-=’ with(Sub)MatrixFull<T>
use rest_tensors::MatrixFull;
let vec_a = vec![
1.0, 2.0, 3.0,
4.0, 5.0, 6.0,
7.0, 8.0, 9.0,
10.0, 11.0, 12.0];
let mut matr_a = MatrixFull::from_vec([3,4],vec_a).unwrap();
// | 1.0 | 4.0 | 7.0 | 10.0 |
//matr_a = | 2.0 | 5.0 | 8.0 | 11.0 | with the type of MatrixFull<f64>
// | 3.0 | 6.0 | 9.0 | 12.0 |
let mut matr_b = matr_a.get_submatrix_mut(0..2,1..3);
//matr_b = | 4.0 | 7.0 |
// | 5.0 | 8.0 | with the type of MatrixFull<&f64>
let vec_c = (5..9).map(|x| x as f64).collect::<Vec<f64>>();
let matr_c = MatrixFull::from_vec([2,2],vec_c).unwrap();
//matr_c = | 5.0 | 7.0 |
// | 6.0 | 8.0 | with the type of MatrixFull<f64>
// matr_a[(0..2, 1..3)] += matr_c
matr_b += matr_c;
// | 1.0 | 9.0 | 14.0 | 10.0 |
//matr_a = | 2.0 | 11.0 | 16.0 | 11.0 | with the type of MatrixFull<f64>
// | 3.0 | 6.0 | 9.0 | 12.0 |
assert_eq!(matr_a.get_submatrix(0..2,1..3).data(), vec![9.0,11.0,14.0,16.0]);
- Enable
(Sub)MatrixFull<T>
+/-<T>
, and(Sub)MatrixFull(Mut)<T>
+=/-=<T>
use rest_tensors::MatrixFull;
let vec_a = vec![
1.0, 2.0, 3.0,
4.0, 5.0, 6.0,
7.0, 8.0, 9.0,
10.0, 11.0, 12.0];
let mut matr_a = MatrixFull::from_vec([3,4],vec_a).unwrap();
// matr_b = matr_a + 2.0
let mut matr_b = matr_a.clone() + 2.0;
assert_eq!(matr_b[(..,0)], [3.0, 4.0, 5.0]);
// matr_b = matr_b - 2.0 = matr_a
matr_b -= 2.0;
assert_eq!(matr_b, matr_a);
let mut matr_b = matr_a.get_submatrix_mut(0..2,1..3);
//matr_b = | 4.0 | 7.0 |
// | 5.0 | 8.0 | with the type of MatrixFull<&f64>
matr_b += 2.0;
// | 1.0 | 6.0 | 9.0 | 10.0 |
//matr_a = | 2.0 | 7.0 | 10.0 | 11.0 | with the type of MatrixFull<f64>
// | 3.0 | 6.0 | 9.0 | 12.0 |
assert_eq!(matr_a.get_submatrix(0..2,1..3).data(), vec![6.0,7.0,9.0,10.0]);
- Enable
(Sub)MatrixFull<T>
*(/)<T>
, and(Sub)MatrixFull(Mut)<T>
+=(/=)<T>
use rest_tensors::MatrixFull;
let vec_a = vec![
1.0, 2.0, 3.0,
4.0, 5.0, 6.0,
7.0, 8.0, 9.0,
10.0, 11.0, 12.0];
let matr_a = MatrixFull::from_vec([3,4],vec_a).unwrap();
// matr_b = matr_a * 2.0
// NOTE: 2.0 should be located after the operator '*' and '/'
let mut matr_b = matr_a.clone() * 2.0;
assert_eq!(matr_b[(..,0)], [2.0, 4.0, 6.0]);
// matr_b = matr_b / 2.0 = matr_a
matr_b /= 2.0;
assert_eq!(matr_b, matr_a);
// | 1.0 | 4.0 | 7.0 | 10.0 |
//matr_b = | 2.0 | 5.0 | 8.0 | 11.0 | with the type of MatrixFull<f64>
// | 3.0 | 6.0 | 9.0 | 12.0 |
let mut matr_c = matr_b.get_submatrix_mut(0..2,1..3);
matr_c *= 2.0;
// after the multiply operation
// | 1.0 | 8.0 | 14.0 | 10.0 |
//matr_b = | 2.0 | 10.0 | 16.0 | 11.0 | with the type of MatrixFull<f64>
// | 3.0 | 6.0 | 9.0 | 12.0 |
assert_eq!(matr_b.get_submatrix(0..2,1..3).data(), vec![8.0,10.0,14.0,16.0]);
Iterators
- The
MatrixFull
struct implements the standard iterators ofiter()
,iter_mut()
, andinto_iter()
, which are nothing but the wrappers to the iterators ofMatrixFull<T>.data: Vec<T>
use rest_tensors::MatrixFull;
let mut matr_a = MatrixFull::from_vec(
[3,4],
(1..13).collect::<Vec<i32>>()
).unwrap();
let mut vec_a = (1..13).collect::<Vec<i32>>();
matr_a.into_iter().zip(vec_a.iter()).for_each(|(m_item, v_item)| {
assert_eq!(m_item, v_item);
});
matr_a.iter_mut().zip(vec_a.iter()).for_each(|(m_item, v_item)| {
assert_eq!(m_item, v_item)
});
As a column-major 2-dimention tensor, MatrixFull
also provides special iterators with
respect to rows and/or columns:
iter_column(j)
anditer_column_mut(j)
provides the standard iterators for the immutable and mutable elements, respectively, in thej
th column.
use rest_tensors::MatrixFull;
let matr_a = MatrixFull::from_vec(
[3,4],
(1..13).collect::<Vec<i32>>()
).unwrap();
// _____
// | 1 || 4 || 7 | 10 |
//matr_a = | 2 || 5 || 8 | 11 | with the type of MatrixFull<i32>
// | 3 || 6 || 9 | 12 |
// -----
let column_j = MatrixFull::from_vec([3,1],vec![4,5,6]).unwrap();
matr_a.iter_column(1).zip(column_j.iter()).for_each(|(m_item, c_item)| {
assert_eq!(m_item, c_item)
})
iter_columns(Range<usize>)
anditer_columns_mut(Range<usize>)
provides the chunck iterators for a set of columns withinRange<usize>
. The iteratior gives the elements of different columns chunck by chunck.
iter_columns_full()
and iter_columns_full_mut()
are the specific cases, which iterate over all columns
use rest_tensors::MatrixFull;
let matr_a = MatrixFull::from_vec(
[3,4],
(1..13).collect::<Vec<i32>>()
).unwrap();
// __________
// | 1 || 4 | 7 || 10 |
//matr_a = | 2 || 5 | 8 || 11 | with the type of MatrixFull<i32>
// | 3 || 6 | 9 || 12 |
// ----------
let columns = vec![[4,5,6],[7,8,9]];
matr_a.iter_columns(1..3).zip(columns.iter()).for_each(|(m_item, c_item)| {
assert_eq!(m_item, c_item)
})
iter_submatrix()
anditer_submatrix_mut()
provide home-made StepBy iterators in the column-major order for the immutable and mutable elements in the sub-matrix, respectively.
use rest_tensors::MatrixFull;
let matr_a = MatrixFull::from_vec(
[3,4],
(1..13).collect::<Vec<i32>>()
).unwrap();
// __________
// | 1 || 4 | 7 || 10 |
//matr_a = | 2 || 5 | 8 || 11 | with the type of MatrixFull<i32>
// ----------
// | 3 | 6 | 9 | 12 |
let smatr_a = MatrixFull::from_vec([2,2],vec![4,5,7,8]).unwrap();
matr_a.iter_submatrix(0..2,1..3).zip(smatr_a.iter()).for_each(|(m_item, sm_item)| {
assert_eq!(m_item, sm_item)
})
- Based on
iter_submatrix()
anditer_submatrix_mut()
,MatrixFull
provides flatten iterators for rows, i.e.iter_row()
,iter_row_mut()
,iter_rows()
,iter_rows_mut()
use rest_tensors::MatrixFull;
let matr_a = MatrixFull::from_vec(
[3,4],
(1..13).collect::<Vec<i32>>()
).unwrap();
// | 1 | 4 | 7 | 10 |
// _____________________
//matr_a = | 2 | 5 | 8 | 11 | with the type of MatrixFull<i32>
// ------ --------------
// | 3 | 6 | 9 | 12 |
//
let row_1 = vec![&2,&5,&8,&11];
let from_iter_row = matr_a.iter_row(1).collect::<Vec<&i32>>();
assert_eq!(row_1, from_iter_row);
- Iterate the diagonal terms using
iter_diagonal().unwrap()
anditer_diagonal_mut().unwrap()
use rest_tensors::MatrixFull;
let matr_a = MatrixFull::from_vec(
[4,4],
(1..17).collect::<Vec<i32>>()
).unwrap();
// | 1 | 5 | 9 | 13 |
//matr_a = | 2 | 6 | 10 | 14 | with the type of MatrixFull<i32>
// | 3 | 7 | 11 | 15 |
// | 4 | 8 | 12 | 16 |
//
let diagonal = vec![&1,&6,&11,&16];
let from_diagonal_iter = matr_a.iter_diagonal().unwrap().collect::<Vec<&i32>>();
assert_eq!(from_diagonal_iter, diagonal);
- Iterate the upper part of the matrix using
iter_matrixupper().unwrap()
anditer_matrixupper_mut().unwrap()
use rest_tensors::MatrixFull;
let matr_a = MatrixFull::from_vec(
[4,4],
(1..17).collect::<Vec<i32>>()
).unwrap();
// | 1 | 5 | 9 | 13 |
//matr_a = | 2 | 6 | 10 | 14 | with the type of MatrixFull<i32>
// | 3 | 7 | 11 | 15 |
// | 4 | 8 | 12 | 16 |
//
let upper = vec![&1,&5,&6,&9,&10,&11,&13,&14,&15,&16];
let from_upper_iter = matr_a.iter_matrixupper().unwrap().collect::<Vec<&i32>>();
assert_eq!(from_upper_iter, upper);
Slicing
The MatrixFull<T>
struct provides the tools to slice the data for a given column or a set of continued columns:
slice_column(j:usize)->&[T]
, slice_column_mut(j:usize)->&mut[T]
,
and slice_columns(j:Range<usize>)->&[T]
, slice_columns_mut(j:Range<usize>)->&mut[T]
use rest_tensors::MatrixFull;
let matr_a = MatrixFull::from_vec(
[3,4],
(1..13).collect::<Vec<i32>>()
).unwrap();
// | 1 | 4 | 7 | 10 |
//matr_a = | 2 | 5 | 8 | 11 | with the type of MatrixFull<i32>
// | 3 | 6 | 9 | 12 |
let column_1 = matr_a.slice_column(1);
assert_eq!(column_1, &[4,5,6]);
let column_12 = matr_a.slice_columns(1..3);
assert_eq!(column_12, &[4,5,6,7,8,9]);
Fields
size: [usize; 2]
the number of row and column, column major
indicing: [usize; 2]
indicing is defined to facilitate the element nevigation, in particular for 3-rank tensors, RIFull
data: Vec<T>
the data stored in the Vec
struct
Implementations
sourceimpl<T> MatrixFull<T>
impl<T> MatrixFull<T>
sourcepub fn empty() -> MatrixFull<T>
pub fn empty() -> MatrixFull<T>
initialize an empty MatrixFull entity
sourcepub fn new(size: [usize; 2], new_default: T) -> MatrixFull<T>where
T: Copy + Clone,
pub fn new(size: [usize; 2], new_default: T) -> MatrixFull<T>where
T: Copy + Clone,
generate a new MatrixFull entity, where all elemental values as “new_default”
pub fn data(&self) -> Vec<T>where
T: Copy + Clone,
pub unsafe fn from_vec_unchecked(
size: [usize; 2],
new_vec: Vec<T>
) -> MatrixFull<T>
pub fn from_vec(size: [usize; 2], new_vec: Vec<T>) -> Option<MatrixFull<T>>
sourcepub fn reshape(&mut self, size: [usize; 2])
pub fn reshape(&mut self, size: [usize; 2])
reshape the matrix without change the data and its ordering
pub fn iter(&self) -> Iter<'_, T>
pub fn iter_mut(&mut self) -> IterMut<'_, T>
sourcepub fn iter_submatrix(
&self,
x: Range<usize>,
y: Range<usize>
) -> SubMatrixStepBy<Iter<'_, T>>ⓘNotable traits for SubMatrixStepBy<I>impl<I> Iterator for SubMatrixStepBy<I>where
I: Iterator, type Item = I::Item;
pub fn iter_submatrix(
&self,
x: Range<usize>,
y: Range<usize>
) -> SubMatrixStepBy<Iter<'_, T>>ⓘNotable traits for SubMatrixStepBy<I>impl<I> Iterator for SubMatrixStepBy<I>where
I: Iterator, type Item = I::Item;
I: Iterator, type Item = I::Item;
iter_submatrix
provides a home-made submatrix StepBy iterator for the elements in the sub-matrix one by one
Example
use rest_tensors::MatrixFull;
let mut matr_a = MatrixFull::from_vec(
[3,4],
(1..13).collect::<Vec<i32>>()
).unwrap();
// | 1 | 4 | 7 | 10 |
//matr_a = | 2 | 5 | 8 | 11 | with the type of MatrixFull<i32>
// | 3 | 6 | 9 | 12 |
let mut tmp_iter = matr_a.iter_submatrix_mut(1..2,0..4).collect::<Vec<&mut i32>>();
assert_eq!(tmp_iter, vec![&2,&5,&8,&11])
pub fn get_submatrix<'a>(
&'a self,
x: Range<usize>,
y: Range<usize>
) -> SubMatrixFull<'_, T>
pub fn iter_submatrix_old(
&self,
x: Range<usize>,
y: Range<usize>
) -> Flatten<IntoIter<&[T]>>
sourcepub fn iter_submatrix_mut_old(
&mut self,
x: Range<usize>,
y: Range<usize>
) -> Flatten<IntoIter<&mut [T]>>
pub fn iter_submatrix_mut_old(
&mut self,
x: Range<usize>,
y: Range<usize>
) -> Flatten<IntoIter<&mut [T]>>
iter_submatrix_mut
provides a flatten iterator for the mutable elements in the sub-matrix one by one
**NOTE:: the current implementation is not efficient.
pub fn iter_submatrix_mut(
&mut self,
x: Range<usize>,
y: Range<usize>
) -> SubMatrixStepBy<IterMut<'_, T>>ⓘNotable traits for SubMatrixStepBy<I>impl<I> Iterator for SubMatrixStepBy<I>where
I: Iterator, type Item = I::Item;
I: Iterator, type Item = I::Item;
pub fn get_submatrix_mut<'a>(
&'a mut self,
x: Range<usize>,
y: Range<usize>
) -> SubMatrixFullMut<'_, T>
pub fn iter_column(&self, y: usize) -> Iter<'_, T>
pub fn iter_column_mut(&mut self, y: usize) -> IterMut<'_, T>
pub fn iter_columns(&self, range_column: Range<usize>) -> ChunksExact<'_, T>
pub fn iter_columns_mut(
&mut self,
range_column: Range<usize>
) -> ChunksExactMut<'_, T>
pub fn iter_columns_full(&self) -> ChunksExact<'_, T>
pub fn iter_columns_full_mut(&mut self) -> ChunksExactMut<'_, T>
pub fn iter_row_old(&self, x: usize) -> Flatten<IntoIter<&[T]>>
pub fn iter_row(&self, x: usize) -> StepBy<Iter<'_, T>>
pub fn iter_row_mut_old(&mut self, x: usize) -> Flatten<IntoIter<&mut [T]>>
pub fn iter_row_mut(&mut self, x: usize) -> StepBy<IterMut<'_, T>>
pub fn iter_rows_old(&self, x: Range<usize>) -> Flatten<IntoIter<&[T]>>
pub fn iter_rows(&self, x: Range<usize>) -> SubMatrixStepBy<Iter<'_, T>>ⓘNotable traits for SubMatrixStepBy<I>impl<I> Iterator for SubMatrixStepBy<I>where
I: Iterator, type Item = I::Item;
I: Iterator, type Item = I::Item;
pub fn iter_rows_mut_old(
&mut self,
x: Range<usize>
) -> Flatten<IntoIter<&mut [T]>>
pub fn iter_rows_mut(
&mut self,
x: Range<usize>
) -> SubMatrixStepBy<IterMut<'_, T>>ⓘNotable traits for SubMatrixStepBy<I>impl<I> Iterator for SubMatrixStepBy<I>where
I: Iterator, type Item = I::Item;
I: Iterator, type Item = I::Item;
pub fn iter_diagonal<'a>(&'a self) -> Option<StepBy<Iter<'_, T>>>
pub fn iter_diagonal_mut<'a>(&'a mut self) -> Option<StepBy<IterMut<'_, T>>>
pub fn iter_matrixupper<'a>(&'a self) -> Option<MatrixUpperStepBy<Iter<'_, T>>>
pub fn iter_matrixupper_mut<'a>(
&'a mut self
) -> Option<MatrixUpperStepBy<IterMut<'_, T>>>
pub fn slice(&self) -> &[T]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
pub fn slice_mut(&mut self) -> &mut [T]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
pub fn slice_column(&self, y: usize) -> &[T]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
pub fn slice_column_mut(&mut self, y: usize) -> &mut [T]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
pub fn slice_columns(&self, y: Range<usize>) -> &[T]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
pub fn slice_columns_mut(&mut self, y: Range<usize>) -> &mut [T]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
sourceimpl<T: Copy + Clone> MatrixFull<T>
impl<T: Copy + Clone> MatrixFull<T>
more matrix operations needed by the rest package
- For transpose A -> A^{T}, use
MatrixFull::transpose
andMatrixFull::transpose_and_drop
use rest_tensors::MatrixFull;
let mut matr_a = MatrixFull::from_vec(
[3,4],
(1..13).collect::<Vec<i32>>()
).unwrap();
// | 1 | 4 | 7 | 10 |
//matr_a = | 2 | 5 | 8 | 11 | with the type of MatrixFull<i32>
// | 3 | 6 | 9 | 12 |
// the second-row elements of matr_a
let row_2 = matr_a.iter_row(2).map(|x| *x).collect::<Vec<i32>>();
assert_eq!(row_2,vec![3,6,9,12]);
// transpose matr_a to matr_b
let mut matr_b = matr_a.transpose();
// the second-column elements of matr_b
let column_2 = matr_b.iter_column(2).map(|x| *x).collect::<Vec<i32>>();
assert_eq!(column_2,vec![3,6,9,12]);
assert_eq!(column_2, row_2)
- Collect the (mut)-refs of the diagonal elements in a vector, use
MatrixFull::get_diagonal_terms
andMatrixFull::get_diagonal_terms_mut
NOTE: because this operation creates a new vector to store the (mut)-refs, it is not efficient. A better way to maniputate the diagonal terms is to use the iterators ofMatrixFull::iter_diagonal
andMatrixFull::iter_diagonal_mut
directly
use rest_tensors::MatrixFull;
let mut matr_a = MatrixFull::from_vec(
[4,4],
(1..17).collect::<Vec<i32>>()
).unwrap();
// | 1 | 5 | 9 | 13 |
//matr_a = | 2 | 6 | 10 | 14 | with the type of MatrixFull<i32>
// | 3 | 7 | 11 | 15 |
// | 4 | 8 | 12 | 16 |
// the second-row elements of matr_a
let diagonal = matr_a.get_diagonal_terms().unwrap();
assert_eq!(diagonal,vec![&1,&6,&11,&16]);
- Collect and copy the upper part of the matrix into the
MatrixUpper
Struct, useMatrixFull::to_matrixupper
- Get the (mutable) reference to the matrix, and encapsulate in various structs for different uses:
–MatrixFull::to_matrixfullslice
toMatrixFullSlice
–MatrixFull::to_matrixfullslicemut
toMatrixFullSliceMut
–MatrixFull::to_matrixfullslice_columns
toSubMatrixFullSlice
sourcepub fn transpose(&self) -> MatrixFull<T>
pub fn transpose(&self) -> MatrixFull<T>
Transpose the matrix: A -> A^{T}
sourcepub fn transpose_and_drop(self) -> MatrixFull<T>
pub fn transpose_and_drop(self) -> MatrixFull<T>
Transpose the matrix: A -> A^{T}
sourcepub fn get_diagonal_terms<'a>(&'a self) -> Option<Vec<&'_ T>>
pub fn get_diagonal_terms<'a>(&'a self) -> Option<Vec<&'_ T>>
pub fn get_diagonal_terms_mut(&mut self) -> Option<Vec<&mut T>>
pub fn to_matrixupper(&self) -> MatrixUpper<T>
pub fn to_matrixfullslicemut(&mut self) -> MatrixFullSliceMut<'_, T>
pub fn to_matrixfullslice(&self) -> MatrixFullSlice<'_, T>
pub fn to_matrixfullslice_columns(
&self,
range_columns: Range<usize>
) -> SubMatrixFullSlice<'_, T>
sourceimpl<T: Copy + Clone + Send + Sync + Sized> MatrixFull<T>
impl<T: Copy + Clone + Send + Sync + Sized> MatrixFull<T>
Useful iterators with rayon parallization
pub fn par_iter_column(&self, j: usize) -> Iter<'_, T>
pub fn par_iter_column_mut(&mut self, j: usize) -> IterMut<'_, T>
pub fn par_iter_columns(
&self,
range_column: Range<usize>
) -> Option<ChunksExact<'_, T>>
pub fn par_iter_columns_mut(
&mut self,
range_column: Range<usize>
) -> Option<ChunksExactMut<'_, T>>
pub fn par_iter_columns_full(&self) -> ChunksExact<'_, T>
pub fn par_iter_columns_full_mut(&mut self) -> ChunksExactMut<'_, T>
sourceimpl<T> MatrixFull<T>where
T: Debug,
impl<T> MatrixFull<T>where
T: Debug,
Add by Tianyi Gao
sourceimpl MatrixFull<f64>
impl MatrixFull<f64>
More math operations for T: f64
pub fn print_debug(&self, x: Range<usize>, y: Range<usize>)
pub fn copy_from_matr<'a, T>(
&mut self,
x: Range<usize>,
y: Range<usize>,
matr_a: &T,
f_x: Range<usize>,
f_y: Range<usize>
)where
T: BasicMatrix<'a, f64>,
pub fn lapack_dgemm(
&mut self,
a: &mut MatrixFull<f64>,
b: &mut MatrixFull<f64>,
opa: char,
opb: char,
alpha: f64,
beta: f64
)
pub fn lapack_dgesv(&mut self, b: &mut MatrixFull<f64>, n: i32) -> MatrixFull<f64>
pub fn ddot(&self, b: &mut MatrixFull<f64>) -> Option<MatrixFull<f64>>
pub fn lapack_inverse(&mut self) -> Option<MatrixFull<f64>>
pub fn lapack_power(&mut self, p: f64, threshold: f64) -> Option<MatrixFull<f64>>
pub fn formated_output_e(&self, n_len: usize, mat_form: &str)
pub fn formated_output(&self, n_len: usize, mat_form: &str)
Trait Implementations
sourceimpl<T: Clone + Add + AddAssign> Add<MatrixFull<T>> for MatrixFull<T>
impl<T: Clone + Add + AddAssign> Add<MatrixFull<T>> for MatrixFull<T>
type Output = MatrixFull<T>
type Output = MatrixFull<T>
+
operator.sourcefn add(self, other: MatrixFull<T>) -> MatrixFull<T>
fn add(self, other: MatrixFull<T>) -> MatrixFull<T>
+
operation. Read moresourceimpl<'a, T: Copy + Clone + Add + AddAssign> Add<MatrixFull<T>> for SubMatrixFull<'a, T>
impl<'a, T: Copy + Clone + Add + AddAssign> Add<MatrixFull<T>> for SubMatrixFull<'a, T>
type Output = MatrixFull<T>
type Output = MatrixFull<T>
+
operator.sourcefn add(self, other: MatrixFull<T>) -> MatrixFull<T>
fn add(self, other: MatrixFull<T>) -> MatrixFull<T>
+
operation. Read moresourceimpl<'a, T: Copy + Clone + Add + AddAssign> Add<SubMatrixFull<'a, T>> for MatrixFull<T>
impl<'a, T: Copy + Clone + Add + AddAssign> Add<SubMatrixFull<'a, T>> for MatrixFull<T>
type Output = MatrixFull<T>
type Output = MatrixFull<T>
+
operator.sourcefn add(self, other: SubMatrixFull<'_, T>) -> MatrixFull<T>
fn add(self, other: SubMatrixFull<'_, T>) -> MatrixFull<T>
+
operation. Read moresourceimpl<T: Clone + Add + AddAssign> Add<T> for MatrixFull<T>
impl<T: Clone + Add + AddAssign> Add<T> for MatrixFull<T>
type Output = MatrixFull<T>
type Output = MatrixFull<T>
+
operator.sourcefn add(self, factor: T) -> MatrixFull<T>
fn add(self, factor: T) -> MatrixFull<T>
+
operation. Read moresourceimpl<T: Clone + Add + AddAssign> AddAssign<MatrixFull<T>> for MatrixFull<T>
impl<T: Clone + Add + AddAssign> AddAssign<MatrixFull<T>> for MatrixFull<T>
sourcefn add_assign(&mut self, other: MatrixFull<T>)
fn add_assign(&mut self, other: MatrixFull<T>)
+=
operation. Read moresourceimpl<'a, T: Clone + Add + AddAssign> AddAssign<MatrixFull<T>> for SubMatrixFullMut<'a, T>
impl<'a, T: Clone + Add + AddAssign> AddAssign<MatrixFull<T>> for SubMatrixFullMut<'a, T>
sourcefn add_assign(&mut self, other: MatrixFull<T>)
fn add_assign(&mut self, other: MatrixFull<T>)
+=
operation. Read moresourceimpl<'a, T: Copy + Clone + Add + AddAssign> AddAssign<SubMatrixFull<'a, T>> for MatrixFull<T>
impl<'a, T: Copy + Clone + Add + AddAssign> AddAssign<SubMatrixFull<'a, T>> for MatrixFull<T>
sourcefn add_assign(&mut self, other: SubMatrixFull<'_, T>)
fn add_assign(&mut self, other: SubMatrixFull<'_, T>)
+=
operation. Read moresourceimpl<T: Clone + Add + AddAssign> AddAssign<T> for MatrixFull<T>
impl<T: Clone + Add + AddAssign> AddAssign<T> for MatrixFull<T>
sourcefn add_assign(&mut self, factor: T)
fn add_assign(&mut self, factor: T)
+=
operation. Read moresourceimpl<'a, T> BasicMatrix<'a, T> for MatrixFull<T>
impl<'a, T> BasicMatrix<'a, T> for MatrixFull<T>
sourceimpl<'a, T> BasicMatrixOpt<'a, T> for MatrixFull<T>where
T: Copy + Clone,
impl<'a, T> BasicMatrixOpt<'a, T> for MatrixFull<T>where
T: Copy + Clone,
fn to_matrixfull(&self) -> Option<MatrixFull<T>>where
T: Copy + Clone,
sourceimpl<T: Clone> Clone for MatrixFull<T>
impl<T: Clone> Clone for MatrixFull<T>
sourcefn clone(&self) -> MatrixFull<T>
fn clone(&self) -> MatrixFull<T>
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresourceimpl<T: Debug> Debug for MatrixFull<T>
impl<T: Debug> Debug for MatrixFull<T>
sourceimpl<T: Clone + Div + DivAssign> Div<T> for MatrixFull<T>
impl<T: Clone + Div + DivAssign> Div<T> for MatrixFull<T>
type Output = MatrixFull<T>
type Output = MatrixFull<T>
/
operator.sourcefn div(self, factor: T) -> MatrixFull<T>
fn div(self, factor: T) -> MatrixFull<T>
/
operation. Read moresourceimpl<T: Clone + Div + DivAssign> DivAssign<T> for MatrixFull<T>
impl<T: Clone + Div + DivAssign> DivAssign<T> for MatrixFull<T>
sourcefn div_assign(&mut self, factor: T)
fn div_assign(&mut self, factor: T)
/=
operation. Read moresourceimpl<T> Index<[usize; 2]> for MatrixFull<T>
impl<T> Index<[usize; 2]> for MatrixFull<T>
sourceimpl<T> Index<(RangeFull, usize)> for MatrixFull<T>
impl<T> Index<(RangeFull, usize)> for MatrixFull<T>
sourceimpl<T> Index<(usize, usize)> for MatrixFull<T>
impl<T> Index<(usize, usize)> for MatrixFull<T>
sourceimpl<T> Index<usize> for MatrixFull<T>
impl<T> Index<usize> for MatrixFull<T>
sourceimpl<T> IndexMut<[usize; 2]> for MatrixFull<T>
impl<T> IndexMut<[usize; 2]> for MatrixFull<T>
sourceimpl<T> IndexMut<(RangeFull, usize)> for MatrixFull<T>
impl<T> IndexMut<(RangeFull, usize)> for MatrixFull<T>
sourceimpl<T> IndexMut<(usize, usize)> for MatrixFull<T>
impl<T> IndexMut<(usize, usize)> for MatrixFull<T>
sourceimpl<T> IndexMut<usize> for MatrixFull<T>
impl<T> IndexMut<usize> for MatrixFull<T>
sourceimpl<'a, T> IntoIterator for &'a MatrixFull<T>
impl<'a, T> IntoIterator for &'a MatrixFull<T>
sourceimpl<T: Clone + Mul + MulAssign> Mul<T> for MatrixFull<T>
impl<T: Clone + Mul + MulAssign> Mul<T> for MatrixFull<T>
type Output = MatrixFull<T>
type Output = MatrixFull<T>
*
operator.sourcefn mul(self, factor: T) -> MatrixFull<T>
fn mul(self, factor: T) -> MatrixFull<T>
*
operation. Read moresourceimpl<T: Clone + Mul + MulAssign> MulAssign<T> for MatrixFull<T>
impl<T: Clone + Mul + MulAssign> MulAssign<T> for MatrixFull<T>
sourcefn mul_assign(&mut self, factor: T)
fn mul_assign(&mut self, factor: T)
*=
operation. Read moresourceimpl<T: PartialEq> PartialEq<MatrixFull<T>> for MatrixFull<T>
impl<T: PartialEq> PartialEq<MatrixFull<T>> for MatrixFull<T>
sourcefn eq(&self, other: &MatrixFull<T>) -> bool
fn eq(&self, other: &MatrixFull<T>) -> bool
sourceimpl<T: Clone + Sub + SubAssign> Sub<MatrixFull<T>> for MatrixFull<T>
impl<T: Clone + Sub + SubAssign> Sub<MatrixFull<T>> for MatrixFull<T>
type Output = MatrixFull<T>
type Output = MatrixFull<T>
-
operator.sourcefn sub(self, other: MatrixFull<T>) -> MatrixFull<T>
fn sub(self, other: MatrixFull<T>) -> MatrixFull<T>
-
operation. Read moresourceimpl<'a, T: Copy + Clone + Sub<Output = T> + SubAssign> Sub<MatrixFull<T>> for SubMatrixFull<'a, T>
impl<'a, T: Copy + Clone + Sub<Output = T> + SubAssign> Sub<MatrixFull<T>> for SubMatrixFull<'a, T>
type Output = MatrixFull<T>
type Output = MatrixFull<T>
-
operator.sourcefn sub(self, other: MatrixFull<T>) -> MatrixFull<T>
fn sub(self, other: MatrixFull<T>) -> MatrixFull<T>
-
operation. Read moresourceimpl<'a, T: Copy + Clone + Sub + SubAssign> Sub<SubMatrixFull<'a, T>> for MatrixFull<T>
impl<'a, T: Copy + Clone + Sub + SubAssign> Sub<SubMatrixFull<'a, T>> for MatrixFull<T>
type Output = MatrixFull<T>
type Output = MatrixFull<T>
-
operator.sourcefn sub(self, other: SubMatrixFull<'_, T>) -> MatrixFull<T>
fn sub(self, other: SubMatrixFull<'_, T>) -> MatrixFull<T>
-
operation. Read moresourceimpl<T: Clone + Sub + SubAssign> Sub<T> for MatrixFull<T>
impl<T: Clone + Sub + SubAssign> Sub<T> for MatrixFull<T>
type Output = MatrixFull<T>
type Output = MatrixFull<T>
-
operator.sourcefn sub(self, f: T) -> MatrixFull<T>
fn sub(self, f: T) -> MatrixFull<T>
-
operation. Read moresourceimpl<T: Clone + Sub + SubAssign> SubAssign<MatrixFull<T>> for MatrixFull<T>
impl<T: Clone + Sub + SubAssign> SubAssign<MatrixFull<T>> for MatrixFull<T>
sourcefn sub_assign(&mut self, other: MatrixFull<T>)
fn sub_assign(&mut self, other: MatrixFull<T>)
-=
operation. Read moresourceimpl<'a, T: Clone + Sub + SubAssign> SubAssign<MatrixFull<T>> for SubMatrixFullMut<'a, T>
impl<'a, T: Clone + Sub + SubAssign> SubAssign<MatrixFull<T>> for SubMatrixFullMut<'a, T>
sourcefn sub_assign(&mut self, other: MatrixFull<T>)
fn sub_assign(&mut self, other: MatrixFull<T>)
-=
operation. Read moresourceimpl<'a, T: Copy + Clone + Sub + SubAssign> SubAssign<SubMatrixFull<'a, T>> for MatrixFull<T>
impl<'a, T: Copy + Clone + Sub + SubAssign> SubAssign<SubMatrixFull<'a, T>> for MatrixFull<T>
sourcefn sub_assign(&mut self, other: SubMatrixFull<'_, T>)
fn sub_assign(&mut self, other: SubMatrixFull<'_, T>)
-=
operation. Read moresourceimpl<T: Clone + Sub + SubAssign> SubAssign<T> for MatrixFull<T>
impl<T: Clone + Sub + SubAssign> SubAssign<T> for MatrixFull<T>
sourcefn sub_assign(&mut self, f: T)
fn sub_assign(&mut self, f: T)
-=
operation. Read moresourceimpl<'a, T> TensorOpt<T> for MatrixFull<T>
impl<'a, T> TensorOpt<T> for MatrixFull<T>
sourceimpl<'a, T> TensorOptMut<'a, T> for MatrixFull<T>
impl<'a, T> TensorOptMut<'a, T> for MatrixFull<T>
fn get1d_mut(&mut self, position: usize) -> Option<&mut T>
fn get2d_mut(&mut self, position: [usize; 2]) -> Option<&mut T>
fn get_mut(&mut self, position: &[usize]) -> Option<&mut T>
fn set1d(&mut self, position: usize, new_data: T)
fn set2d(&mut self, position: [usize; 2], new_data: T)
fn set(&mut self, position: &[usize], new_data: T)
fn get3d_mut(&mut self, position: [usize; 3]) -> Option<&mut T>
fn get4d_mut(&mut self, position: [usize; 4]) -> Option<&mut T>
fn set3d(&mut self, position: [usize; 3], new_data: T)
fn set4d(&mut self, position: [usize; 4], new_data: T)
sourceimpl<'a, T> TensorSlice<T> for MatrixFull<T>
impl<'a, T> TensorSlice<T> for MatrixFull<T>
fn get1d_slice(&self, position: usize, length: usize) -> Option<&[T]>
fn get2d_slice(&self, position: [usize; 2], length: usize) -> Option<&[T]>
fn get_slice(&self, position: &[usize], length: usize) -> Option<&[T]>
fn get3d_slice(&self, position: [usize; 3], length: usize) -> Option<&[T]>
fn get4d_slice(&self, position: [usize; 4], length: usize) -> Option<&[T]>
sourceimpl<'a, T> TensorSliceMut<'a, T> for MatrixFull<T>
impl<'a, T> TensorSliceMut<'a, T> for MatrixFull<T>
fn get1d_slice_mut(&mut self, position: usize, length: usize) -> Option<&mut [T]>
fn get2d_slice_mut(
&mut self,
position: [usize; 2],
length: usize
) -> Option<&mut [T]>
fn get_slice_mut(&mut self, position: &[usize], length: usize) -> Option<&mut [T]>
fn get3d_slice_mut(
&mut self,
position: [usize; 3],
length: usize
) -> Option<&mut [T]>
fn get4d_slice_mut(
&mut self,
position: [usize; 4],
length: usize
) -> Option<&mut [T]>
impl<'a, T> MathMatrix<'a, T> for MatrixFull<T>where
T: Copy + Clone,
more math operations for the rest package
These operators are provided by the trait of MathMatrix
.
Here, we illustrate the usage mainly using the MatrixFull
struct. You can perform these operations for MatrixFullSlice
,
MatrixFullSliceMut
, SubMatrixFull
, and SubMatrixFullMut
.
We also provide the rayon parallel version of these operators by the trait of ParMathMatrix
.
- For C = A + B, use
MathMatrix::add
andParMathMatrix::par_add
- For C = A + c*B, use
MathMatrix::scaled_add
andParMathMatrix::par_scaled_add
- For A += B, use
MathMatrix::self_add
andParMathMatrix::par_self_add
- For A += c*B, using
MathMatrix::self_scaled_add
andParMathMatrix::par_scaled_add
- For aA + bB -> A, using
MathMatrix::self_general_add
andParMathMatrix::par_self_general_add
- For C = A -B, use
MathMatrix::sub
andParMathMatrix::par_sub
- For A -= B, use
MathMatrix::self_sub
andParMathMatrix::par_self_sub
- For A *= a, use
MathMatrix::self_multiple
andParMathMatrix::par_self_multiple
Several examples are given as follow:
-
- add and self_sub
use rest_tensors::{MatrixFull, MathMatrix};
let vec_a = vec![
1.0, 2.0, 3.0,
4.0, 5.0, 6.0,
7.0, 8.0, 9.0,
10.0, 11.0, 12.0];
let matr_a = MatrixFull::from_vec([3,4],vec_a).unwrap();
// | 1.0 | 4.0 | 7.0 | 10.0 |
//matr_a = | 2.0 | 5.0 | 8.0 | 11.0 |
// | 3.0 | 6.0 | 9.0 | 12.0 |
let vec_b = (13..25).map(|x| x as f64).collect::<Vec<f64>>();
let matr_b = MatrixFull::from_vec([3,4],vec_b).unwrap();
// | 13.0 | 16.0 | 19.0 | 22.0 |
//matr_b = | 14.0 | 17.0 | 20.0 | 23.0 |
// | 15.0 | 18.0 | 21.0 | 24.0 |
// matr_c = matr_a + matr_b;
let mut matr_c = MatrixFull::add(&matr_a, &matr_b).unwrap();
// | 14.0 | 20.0 | 26.0 | 32.0 |
//matr_c = | 16.0 | 22.0 | 28.0 | 34.0 |
// | 18.0 | 24.0 | 30.0 | 36.0 |
assert_eq!(matr_c[(..,3)], [32.0,34.0,36.0]);
// matr_c_ref: MatrixFullSliceMut<f64>
let mut matr_c_ref = matr_c.to_matrixfullslicemut();
// matr_c -= matr_b = matr_a
matr_c_ref.self_sub(&matr_b);
assert_eq!(matr_c, matr_a);
-
- scaled add and self_sub
use rest_tensors::{MatrixFull, MathMatrix, ParMathMatrix};
let vec_a = vec![
1.0, 2.0, 3.0,
4.0, 5.0, 6.0,
7.0, 8.0, 9.0,
10.0, 11.0, 12.0];
let matr_a = MatrixFull::from_vec([3,4],vec_a).unwrap();
// | 1.0 | 4.0 | 7.0 | 10.0 |
//matr_a = | 2.0 | 5.0 | 8.0 | 11.0 |
// | 3.0 | 6.0 | 9.0 | 12.0 |
let vec_b = (13..25).map(|x| x as f64).collect::<Vec<f64>>();
let mut matr_b = MatrixFull::from_vec([3,4],vec_b).unwrap();
// | 13.0 | 16.0 | 19.0 | 22.0 |
//matr_b = | 14.0 | 17.0 | 20.0 | 23.0 |
// | 15.0 | 18.0 | 21.0 | 24.0 |
// matr_c = 1.0*matr_a + matr_b
let mut matr_c = matr_b.scaled_add(&matr_a, 1.0).unwrap();
// | 14.0 | 20.0 | 26.0 | 32.0 |
//matr_c = | 16.0 | 22.0 | 28.0 | 34.0 |
// | 18.0 | 24.0 | 30.0 | 36.0 |
assert_eq!(matr_c[(..,3)], [32.0,34.0,36.0]);
// matr_c_ref: MatrixFullSliceMut<f64>
let mut matr_c_ref = matr_c.to_matrixfullslicemut();
// matr_c -= matr_b = matr_a, using the rayon parallel version
matr_c_ref.par_self_sub(&matr_b);
assert_eq!(matr_c, matr_a);
impl<'a, T> ParMathMatrix<'a, T> for MatrixFull<T>where
T: Copy + Clone + Send + Sync,
impl<T> StructuralPartialEq for MatrixFull<T>
Auto Trait Implementations
impl<T> RefUnwindSafe for MatrixFull<T>where
T: RefUnwindSafe,
impl<T> Send for MatrixFull<T>where
T: Send,
impl<T> Sync for MatrixFull<T>where
T: Sync,
impl<T> Unpin for MatrixFull<T>where
T: Unpin,
impl<T> UnwindSafe for MatrixFull<T>where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<T> Pointable for T
impl<T> Pointable for T
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read morefn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.