Peano
Loading...
Searching...
No Matches
MatrixOperations.cpph
Go to the documentation of this file.
1template<int Rows, typename Scalar>
4
5 for (int i=0; i<Rows; i++) {
6 result(i,i) = 1.0;
7 }
8
9 return result;
10}
11
12
13template<int Rows, int Cols, typename Scalar>
14Scalar tarch::la::frobeniusNorm(
15 const Matrix<Rows,Cols,Scalar>& matrix
16) {
17 Scalar result(0);
18
19 for (int row=0; row<Rows; row++)
20 for (int col=0; col<Cols; col++) {
21 result += matrix(row,col) * matrix(row,col);
22 }
23
24 return std::sqrt(result);
25}
26
27
28template<int Rows, int Cols, typename Scalar>
29Scalar tarch::la::elementMax(
30 const Matrix<Rows,Cols,Scalar>& matrix
31) {
32 Scalar result(0);
33
34 for (int row=0; row<Rows; row++)
35 for (int col=0; col<Cols; col++) {
36 result = std::max( result, std::abs( matrix(row,col) ) );
37 }
38
39 return result;
40}
41
42
43template<int Rows, int Cols, typename Scalar>
46) {
48
49 for (int i=0; i<Rows; i++) {
50 for (int j=0; j<Cols; j++) {
51 result(i,j) = 1.0/matrix(i,j);
52 }
53 }
54
55 return result;
56}
57
58
59
60template<int Rows, int Cols, typename Scalar>
61tarch::la::Vector<Cols,Scalar> tarch::la::row(const Matrix<Rows,Cols,Scalar>& matrix, int whichRow) {
63
64 for (int i=0; i<Cols; i++) {
65 result(i) = matrix(whichRow,i);
66 }
67
68 return result;
69}
70
71
72template<int Rows, int Cols, typename Scalar>
73tarch::la::Vector<Rows,Scalar> tarch::la::col(const Matrix<Rows,Cols,Scalar>& matrix, int whichColumn) {
75
76 for (int i=0; i<Rows; i++) {
77 result(i) = matrix(i,whichColumn);
78 }
79
80 return result;
81}
82
83
84template<int Rows, int Cols, typename Scalar>
87 #ifdef CompilerICC
88 #pragma ivdep
89 #endif
90 for (int i=0; i < Rows; i++) {
91 for (int j=0; j < Cols; j++) {
92 result(j,i) += matrix(i,j);
93 }
94 }
95 return result;
96}
97
98
99
100template<int Rows, int Cols, typename Scalar>
102 Scalar result = 0;
103 for (int i=0; i < Rows; i++) {
104 for (int j=0; j < Cols; j++) {
105 result += matrix(i,j);
106 }
107 }
108 return result;
109}
110
111
112
113template<int Rows, int Cols, typename Scalar>
114std::ostream& operator<< (
115 std::ostream& os,
117) {
118 os << matrix.toString();
119 return os;
120}
121
122
123template<int Rows, typename Scalar>
124tarch::la::Vector<Rows,Scalar> tarch::la::diag(const Matrix<Rows,Rows,Scalar>& matrix) {
126 for (int i=0; i<Rows; i++) {
127 result(i) = matrix(i,i);
128 }
129 return result;
130}
131
std::ostream & operator<<(std::ostream &os, const tarch::la::Matrix< Rows, Cols, Scalar > &matrix)
Static (i.e.
Definition Matrix.h:42
std::string toString() const
Definition Matrix.cpph:64
j
Definition euler.py:99
CF abs(const CF &cf)
DynamicMatrix transpose(const DynamicMatrix &matrix)
Scalar sum(const Matrix< Rows, Cols, Scalar > &matrix)
Computes the sum of all entries of the matrix.
Vector< Rows, Scalar > col(const Matrix< Rows, Cols, Scalar > &matrix, int whichColumn)
Extract row from matrix.
Vector< Rows, Scalar > diag(const Matrix< Rows, Rows, Scalar > &matrix)
Extract diagonal vector from matrix.
static Matrix< Rows, Rows, Scalar > identity()
Returns the identity matrix.
Vector< Size, Scalar > invertEntries(const Vector< Size, Scalar > &vector)
Vector< Cols, Scalar > row(const Matrix< Rows, Cols, Scalar > &matrix, int whichRow)
Extract row from matrix.
Simple vector class.
Definition Vector.h:150