This file is indexed.

/usr/include/ASL/math/aslMatrices.h is in libasl-dev 0.1.7-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
/*
 * Advanced Simulation Library <http://asl.org.il>
 * 
 * Copyright 2015 Avtech Scientific <http://avtechscientific.com>
 *
 *
 * This file is part of Advanced Simulation Library (ASL).
 *
 * ASL is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, version 3 of the License.
 *
 * ASL is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with ASL. If not, see <http://www.gnu.org/licenses/>.
 *
 */


/// \file aslMatrices.h Matrices

#ifndef ASLMATRICES
#define ASLMATRICES


#include "../aslUtilities.h"
#include "aslVectors.h"


namespace asl
{
	/// class algebraic matrix. 
	/// The class is an implementation of a dynamic matrix with defined algebraic operations
	template <typename T = double> class AMatr
	{
		private: 
			unsigned int nRow;
			unsigned int nCol;			
			AVec<T> internalVec;
		public:
			inline AMatr();
			inline AMatr(unsigned int nR, unsigned int nC);
      		inline AMatr(const AMatr<T> &a);
			inline AMatr(unsigned int nR, unsigned int nC, AVec<T> v);
			template <typename T1> AMatr(const AMatr<T1> &a);
			const AMatr<T> & operator=(const AMatr & a);
			///doesn't chek boundaries
			inline T& operator()(int i, int j) {return internalVec[i*nCol+j];}
      		///doesn't chek boundaries
			inline const T& operator()(int i, int j)const {return internalVec[i*nCol+j];}
			///doesn't chek boundaries
			inline T& operator[](int i) {return internalVec[i];}
			///doesn't chek boundaries
			inline const T& operator[](int i)const {return internalVec[i];}
			inline unsigned int getNRow() const;
			inline unsigned int getNCol() const;
			inline void resize(unsigned int nR, unsigned int nCol);
			inline const AVec<T> & getInternalVec() const;
			inline AVec<T> & getInternalVec();
			void setRow(unsigned int r, const AVec<T> & a);
			void setColumn(unsigned int c, const AVec<T> & a);
	};

	
	/// \relates AMatr	
	template <typename T> std::ostream& operator<<(std::ostream &f,const AMatr<T> & a); 
	/// \relates AMatr	
	template <typename T> 
		inline const AMatr<T> & operator+=(AMatr<T> & a, const AMatr<T> & b);
	/// \relates AMatr	
	template <typename T> 
		inline const AMatr<T> operator+ (const AMatr<T> & a, const AMatr<T> & b); 
	/// \relates AMatr	
	template <typename T> 
		inline const AMatr<T> operator- (const AMatr<T> & a, const AMatr<T> & b);
	/// \relates AMatr	
	template <typename T> 
		const AMatr<T> operator* (const AMatr<T> &a, const AMatr<T> & b); 

	/// \relates AMatr	
	template <typename T> 
		const AVec<T> operator* (const AMatr<T> &a, const AVec<T> & b); 

	/// \relates AMatr	
	template <typename T> 
		const AVec<T> operator* (const AVec<T> &a, const AMatr<T> & b); 

	/// \relates AMatr	
	template <typename T> 
		const AMatr<T> operator* (const AMatr<T> &a, const T & b); 

	/// \relates AMatr	
	template <typename T> 
		const AMatr<T> operator* (const T &a, const AMatr<T> & b); 
	
	///Trace of a matrix \f$Tr(A)\equiv A_{ii}\f$ \relates AMatr	
	template <typename T> const T trace(const AMatr<T> &a); 

	///Trace of a matrix product \f$Tr(A B)\equiv A_{ij}B_{ji}\f$ \relates AMatr	
 	template <typename T> const T trace(const AMatr<T> & a, const AMatr<T> & b);
	/// \relates AMatr	
	template <typename T> 
		inline const AMatr<T> operator/ (const AMatr<T> & b, const T & a); 

	///element product of two vectors
	/**
		 \relates AMatr
		 \f$ elementProduct\left(
		                         \left[\begin{array}{c}
		                               a_1\\ \vdots \\ a_n
		                               \end{array}\right],
		                         \left[\begin{array}{c}
		                               b_1\\ \vdots \\ b_n
		                               \end{array}\right] =
		                         \left[\begin{array}{ccc}
		                               a_1b_1 & \cdots & a_1b_n\\
		                               \vdots & \ddots & \vdots\\
		                               a_nb_1 & \cdots & a_nb_n\\
		                               \end{array}\right]
		                         \right)
		 \f$
	 */			
	template <typename T>	
		AMatr<T> elementProduct(const AVec<T> & a, const AVec<T> & b);


	///	 generates a matrix with a row \relates AMatr
	template <typename T> AMatr<T> makeAMatr(const AVec<T> & a);
	
	///	 generates a matrix with two rows 	 \relates AMatr
	template <typename T> AMatr<T> makeAMatr(const AVec<T> & a, const AVec<T> & b);
	
	///	 generates a matrix with three rows  \relates AMatr
	template <typename T> AMatr<T> makeAMatr(const AVec<T> & a, 
	                                         const AVec<T> & b,
	                                         const AVec<T> & c);

	///	 generates a matrix with \p n rows  \relates AMatr
	template <typename T> AMatr<T> makeAMatr(AVec<T> *a, unsigned int n);

	/// \relates AMatr	
	template <typename T=int>AMatr<T> makeAMatrUnit(unsigned int n);

	
	/// returns AVec containing the diagonal elements
	/**
		\relates AMatr 
		the finction is valid only for square matrices
	*/
	template <typename T> AVec<T> getDiagonal(const AMatr<T> & a);
	
	/// returns AVec<T> containing the uper off diagonal elements
	/**
		\relates AMatr
		the function is valid only for square matrices
		\todo implement
	*/
	template <typename T> AVec<T> getOffDiagonalUp(const AMatr<T> & a);

	/// computes determinant expression fo cases 2x2 and 3x3 only
	/**
		 \relates AMatr		 
	*/
	template <typename T> T det(const AMatr<T> & m);

	/// returns solution of a system of linear equations
	/**
		\ingroup ComplexDataTypes		 
	*/
	template <typename T> AVec<T> solveSystem(const AMatr<T> & a, 
	                                          const AVec<T> & b);

	/// generate matrix with content of the matrix \p a but with replaced row \p r by vector \p b \relates AMatr<T>		 
	template <typename T> 
		AMatr<T> replaceRow(const AMatr<T> & a, const AVec<T> & b, unsigned int r);

	/// generate matrix with content of the matrix \p a but with replaced column \p c by vector \p b \relates AMatr<T>		 
	template <typename T> 
		AMatr<T> replaceColumn(const AMatr<T> & a, const AVec<T> & b, unsigned int c);

	/// returns inverse matrix for cases 2x2 and 3x3 \relates AMatr<T> 
	template <typename T> 
		AMatr<T> inverseMatrix(const AMatr<T> & a);

	
// ------------------------------ Implementation -----------------
	template <typename T> inline AMatr<T>::AMatr():
		nRow(0),
		nCol(0)
	{
	}

	template <typename T> inline AMatr<T>::AMatr(unsigned int nR, unsigned int nC):
		nRow(nR),
		nCol(nC),
		internalVec(nR*nC)
	{
	}
    template <typename T> inline AMatr<T>::AMatr(const AMatr<T> &a):
		nRow(a.nRow),
		nCol(a.nCol),
		internalVec(a.internalVec)
	{
	}
	template <typename T> inline AMatr<T>::AMatr(unsigned int nR, unsigned int nC, AVec<T> v):
		nRow(nR),
		nCol(nC),
		internalVec(v)
	{
	}

	template <typename T> inline AVec<T> & AMatr<T>::getInternalVec()
	{
		return internalVec;
	}

	template <typename T> inline const AVec<T> & AMatr<T>::getInternalVec() const
	{
		return internalVec;
	}
		
	template <typename T> inline unsigned int AMatr<T>::getNRow() const
	{
		return nRow;
	}
	
	template <typename T> inline unsigned int AMatr<T>::getNCol() const
	{
		return nCol;
	}
	
	template <typename T> 
		inline void AMatr<T>::resize(unsigned int nr, unsigned int nc)
	{
		nRow=nr; 
		nCol=nc;
		internalVec.resize(nr*nc);
	}

	template <typename T> 
		inline const AMatr<T> & operator+=(AMatr<T> & a, const AMatr<T> & b)
	{
		a.getInternalVec += b.getInternalVec;
		return a;
	}

	template <typename T> 
		inline const AMatr<T> operator+ (const AMatr<T> & a, const AMatr<T> & b) 
	{
		return {a.getNRow(),a.getNCol(),a.getInternalVec() + b.getInternalVec()};
	}

	template <typename T> 
		inline const AMatr<T> operator- (const AMatr<T> & a,const AMatr<T> & b) 
	{  
		return {a.getNRow(),a.getNCol(),a.getInternalVec() - b.getInternalVec()};
	}

	template <typename T> 
		inline const AMatr<T> operator/ (const AMatr<T> & b, const T & a) 
	{
		return {b.getNRow(), b.getNCol(), b.getInternalVec() / a};
	}
	
	/// Eigenvalues and eigenvectors calcutaion for symetric matrix 2x2
	/**
		\param a matrix element
		\param b matrix element
		\param c matrix element
		\param l1 first eigenvalue
		\param l2 second eigenvalue
		\param v1x x component of first eigenvector
		\param v1y y component of first eigenvector
		\param v2x x component of second eigenvector
		\param v2y y component of second eigenvector
		
		\f[
		     A= 
		     \left| \begin{array}{cc}
			a & c \\
			c & b 
		     \end{array}\right| 
		\f]
			
	*/
	void getEValEVecMatSym2x2(double a, double b, double c, double & l1, double & l2, double & v1x, double & v1y, double & v2x, double & v2y);
	/// Eigenvalues and eigenvectors calcutaion for symetric matrix 2x2
	/**
		\param a matrix element
		\param b matrix element
		\param c matrix element
		\param l1 first eigenvalue
		\param l2 second eigenvalue
		\param v1x x component of first eigenvector
		\param v1y y component of first eigenvector
		\param v2x x component of second eigenvector
		\param v2y y component of second eigenvector
		
		\f[
		     A= 
		     \left| \begin{array}{cc}
			a & c \\
			c & b 
		     \end{array}\right| 
		\f]
			
	*/
	void getEValEVecMatSym2x2(double a, double b, double c, double & l1, double & l2, double & v1x, double & v1y, double & v2x, double & v2y);

	/// Eigenvalues and eigenvectors calcutaion for symetric matrix 2x2
	/**
		\param a matrix element
		\param b matrix element
		\param c matrix element
		\param d matrix element
		\param e matrix element
		\param f matrix element
		\param l1 first eigenvalue
		\param l2 second eigenvalue
		\param l3 second eigenvalue
		\param v1x x component of first eigenvector
		\param v1y y component of first eigenvector
		\param v1z z component of first eigenvector
		\param v2x x component of second eigenvector
		\param v2y y component of second eigenvector
		\param v2z z component of second eigenvector
		\param v3x x component of second eigenvector
		\param v3y y component of second eigenvector
		\param v3z z component of second eigenvector
		
		\f[
		     A= 
		     \left| \begin{array}{ccc}
			a & d & e\\
			d & b & f \\
		    e & f & c \\
		     \end{array}\right| 
		\f]
			
	*/
	void getEValEVecMatSym3x3(double a, double b, double c, double e, double f, double g, 
	                          double & l1, double & l2, double & l3, 
	                          double & v1x, double & v1y, double & v1z, 
	                          double & v2x, double & v2y, double & v2z,
	                          double & v3x, double & v3y, double & v3z);
		 
} // asl

#endif //ASLMATRICES