static_math/
traits.rs

1//-------------------------------------------------------------------------
2// @file traits.rs
3//
4// @date 06/01/20 22:19:00
5// @author Martin Noblia
6// @email mnoblia@disroot.org
7//
8// @brief
9//
10// @detail
11//
12// Licence MIT:
13// Copyright <2020> <Martin Noblia>
14//
15// Permission is hereby granted, free of charge, to any person obtaining a copy
16// of this software and associated documentation files (the "Software"), to deal
17// in the Software without restriction, including without limitation the rights
18// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19// copies of the Software, and to permit persons to whom the Software is
20// furnished to do so, subject to the following conditions:
21//
22// The above copyright notice and this permission notice shall be included in
23// all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED
24// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
25// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
26// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
27// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30//--------------------------------------------------------------------------
31/// Generic Trait for Matrix operations and Linear Algebra methods
32pub trait LinearAlgebra<T> {
33    /// get the rows of the matrix
34    fn rows(&self) -> usize;
35
36    /// get the columns of the matrix
37    fn cols(&self) -> usize;
38
39    /// get the overal shape of the matrix
40    fn shape(&self) -> (usize, usize) {
41        (self.rows(), self.cols())
42    }
43
44    /// transpose dimentions of the matrix
45    fn transpose(&self) -> Self
46    where
47        Self: Sized;
48
49    /// get the trace of the matrix
50    fn trace(&self) -> T;
51
52    /// compute the euclidean norm of the matrix
53    fn norm2(&self) -> T;
54
55    /// compute the determinant of the matrix
56    fn det(&self) -> T;
57
58    /// compute the inverse of the matrix
59    fn inverse(&self) -> Option<Self>
60    where
61        Self: Sized;
62
63    /// compute the QR factorization of the matrix(if has inverse)
64    fn qr(&self) -> Option<(Self, Self)>
65    where
66        Self: Sized;
67}