General Purpose Geodetic Library
SgSymMatrix.h
Go to the documentation of this file.
1 /*
2  *
3  * This file is a part of Space Geodetic Library. The library is used by
4  * nuSolve, a part of CALC/SOLVE system, and designed to make analysis of
5  * geodetic VLBI observations.
6  * Copyright (C) 2010-2020 Sergei Bolotin.
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 
23 #ifndef SG_SYM_MATRIX_H
24 #define SG_SYM_MATRIX_H
25 
26 
27 #ifdef HAVE_CONFIG_H
28 # include <config.h>
29 #endif
30 
31 
32 #include <SgUtMatrix.h>
33 
34 
35 
36 
37 /***===================================================================================================*/
42 /*=====================================================================================================*/
43 class SgSymMatrix: public SgUtMatrix
44 {
45  public:
46  //
47  // constructors/destructors:
48  //
52  inline SgSymMatrix();
53 
60  inline SgSymMatrix(unsigned int N, bool IsNeedClear = true);
61 
66  inline SgSymMatrix(const SgSymMatrix& P);
67 
71  inline ~SgSymMatrix();
72 
73 
74 
75  //
76  // Interfaces:
77  //
83  inline double& operator()(unsigned int i, unsigned int j);
84 
89  inline double getElement(unsigned int i, unsigned int j) const;
90 
96  inline void setElement(unsigned int i, unsigned int j, double d);
97 
98  inline double** &base() {return B_;};
99 
100  inline const double* const* base_c() const {return B_;};
101 
102 
103  //
104  // Functions:
105  //
109  inline SgSymMatrix& operator=(const SgSymMatrix& P);
110 
114  inline SgSymMatrix& operator+=(const SgSymMatrix& P);
115 
119  inline SgSymMatrix& operator-=(const SgSymMatrix& P);
120 
124  inline SgSymMatrix& operator=(double d);
125 
129  inline SgSymMatrix& operator*=(double d);
130 
134  inline SgSymMatrix& operator/=(double d);
135 
138  inline SgSymMatrix T() const;
139 
140 
141 
142  //
143  // Friends:
144  //
148  friend inline SgSymMatrix operator-(const SgSymMatrix& P);
149 
154  friend inline SgSymMatrix operator/(const SgSymMatrix& P, double d);
155 
160  friend inline SgSymMatrix operator*(const SgSymMatrix& P, double d);
161 
166  friend inline SgSymMatrix operator*(double d, const SgSymMatrix& P);
167 
172  friend inline SgSymMatrix operator+(const SgSymMatrix& P1, const SgSymMatrix& P2);
173 
178  friend inline SgSymMatrix operator-(const SgSymMatrix& P1, const SgSymMatrix& P2);
179 
184  friend SgVector operator*(const SgSymMatrix& P, const SgVector& V);
185 
186  friend SgMatrix calcProduct_mat_x_mat(const SgMatrix& M1, const SgSymMatrix& P2);
187 
188 
189  //
190  // I/O:
191  //
192  // ...
193 
194 
195 
196 private:
201  friend SgSymMatrix operator~(const SgSymMatrix& P);
202 };
203 /*=====================================================================================================*/
204 
205 
206 
207 
208 /*=====================================================================================================*/
209 /* */
210 /* SgSymMatrix's inline members: */
211 /* */
212 /*=====================================================================================================*/
213 //
214 //
215 // CONSTRUCTORS:
216 //
217 // An empty constructor:
219  : SgUtMatrix()
220 {
221  // nothing to do
222 };
223 
224 
225 
226 // A regular constructor:
227 inline SgSymMatrix::SgSymMatrix(unsigned int N, bool IsNeedClear)
228  : SgUtMatrix(N, IsNeedClear)
229 {
230  // nothing to do
231 };
232 
233 
234 
235 // A copying constructor:
237  : SgUtMatrix(P)
238 {
239  // nothing to do
240 };
241 
242 
243 
244 // A destructor:
246 {
247  // nothing to do
248 };
249 
250 
251 
252 
253 //
254 // INTERFACES:
255 //
256 // returns a reference on (i,j)-th element:
257 inline double& SgSymMatrix::operator()(unsigned int i, unsigned int j)
258 {
259 #ifdef DEBUG
260  if (NRow_<=i)
261  std::cerr << "WARNING: double& SgSymMatrix::operator()(unsigned int i, unsigned int j):"
262  << " row's index [" << i << "] out of range [0.." << NRow_-1 << "]\n";
263  if (NCol_<=j)
264  std::cerr << "WARNING: double& SgSymMatrix::operator()(unsigned int i, unsigned int j):"
265  << " column's index [" << j + "] out of range [0.." << NCol_-1 << "]\n";
266 #endif //DEBUG
267 
268  return (i<NRow_ && j<NCol_)?*(*(B_+std::max(j,i))+std::min(i,j)):dTmp_;
269 };
270 
271 
272 
273 // returns a value of (i,j)-th element:
274 inline double SgSymMatrix::getElement(unsigned int i, unsigned int j) const
275 {
276 #ifdef DEBUG
277  if (NRow_<=i)
278  std::cerr << "WARNING: double SgSymMatrix::getElement(unsigned int, unsigned int):"
279  << " row's index [" << i << "] out of range [0.." << NRow_-1 << "]\n";
280  if (NCol_<=j)
281  std::cerr << "WARNING: double SgSymMatrix::getElement(unsigned int, unsigned int):"
282  << " column's index [" << j << "] out of range [0.." << NCol_-1 << "]\n";
283 #endif //DEBUG
284 
285  return (i<NRow_ && j<NCol_)?*(*(B_+std::max(j,i))+std::min(i,j)):0.0;
286 };
287 
288 
289 
290 // sets a value of (i,j)-th element:
291 inline void SgSymMatrix::setElement(unsigned int i, unsigned int j, double d)
292 {
293 #ifdef DEBUG
294  if (NRow_<=i)
295  std::cerr << "WARNING: void SgSymMatrix::setElement(unsigned int i, unsigned int j,"
296  << " double d): row's index [" << i << "] out of range [0.." << NRow_-1 << "]\n";
297  if (NCol_<=j)
298  std::cerr << "WARNING: void SgSymMatrix::setElement(unsigned int i, unsigned int j,"
299  << " double d): column's index [" << j + "] out of range [0.." << NCol_-1 << "]\n";
300 #endif //DEBUG
301 
302  if (i<NRow_ && j<NCol_)
303  *(*(B_+std::max(j,i))+std::min(i,j)) = d;
304 };
305 
306 
307 
308 
309 //
310 // FUNCTIONS:
311 //
312 //
314 {
315  return (SgSymMatrix&)(SgUtMatrix::operator=(P));
316 };
317 
318 
319 
320 //
322 {
323  return (SgSymMatrix&)(SgUtMatrix::operator+=(P));
324 };
325 
326 
327 
328 //
330 {
331  return (SgSymMatrix&)(SgUtMatrix::operator-=(P));
332 };
333 
334 
335 
336 //
338 {
339  return (SgSymMatrix&)(SgUtMatrix::operator=(d));
340 };
341 
342 
343 
344 //
346 {
347  return (SgSymMatrix&)(SgUtMatrix::operator*=(d));
348 };
349 
350 
351 
352 //
354 {
355  return (SgSymMatrix&)(SgUtMatrix::operator/=(d));
356 };
357 
358 
359 
360 // in this case, just returns a copy of the matrix:
362 {
363  return SgSymMatrix(*this);
364 };
365 
366 
367 
368 
369 //
370 // FRIENDS:
371 //
372 //
373 inline SgSymMatrix operator*(const SgSymMatrix& P, double d)
374 {
375  return SgSymMatrix(P)*=d;
376 };
377 
378 
379 
380 //
381 inline SgSymMatrix operator*(double d, const SgSymMatrix& P)
382 {
383  return SgSymMatrix(P)*=d;
384 };
385 
386 
387 
388 //
389 inline SgSymMatrix operator/(const SgSymMatrix& P, double d)
390 {
391  return SgSymMatrix(P)/=d;
392 };
393 
394 
395 
396 //
398 {
399  return SgSymMatrix(P)*=-1.0;
400 };
401 
402 
403 
404 //
405 inline SgSymMatrix operator+(const SgSymMatrix& P1, const SgSymMatrix& P2)
406 {
407  return SgSymMatrix(P1)+=P2;
408 };
409 
410 
411 
412 //
413 inline SgSymMatrix operator-(const SgSymMatrix& P1, const SgSymMatrix& P2)
414 {
415  return SgSymMatrix(P1)-=P2;
416 };
417 
418 
419 
420 // disabled:
422 {
423  return SgSymMatrix(P);
424 };
425 /*=====================================================================================================*/
426 
427 
428 
429 
430 /*=====================================================================================================*/
431 //
432 // aux functions:
433 //
434 // output to std stream:
439 std::ostream &operator<<(std::ostream& s, const SgSymMatrix& P);
440 
441 
442 
443 #endif // SG_SYM_MATRIX_H
SgSymMatrix operator-(const SgSymMatrix &P)
Definition: SgSymMatrix.h:397
SgSymMatrix operator/(const SgSymMatrix &P, double d)
Definition: SgSymMatrix.h:389
SgSymMatrix operator*(const SgSymMatrix &P, double d)
Definition: SgSymMatrix.h:373
std::ostream & operator<<(std::ostream &s, const SgSymMatrix &P)
SgSymMatrix operator~(const SgSymMatrix &P)
Definition: SgSymMatrix.h:421
SgSymMatrix operator+(const SgSymMatrix &P1, const SgSymMatrix &P2)
Definition: SgSymMatrix.h:405
double dTmp_
Local temporary variable.
Definition: SgMatrix.h:262
unsigned int NCol_
An number of columns in a matrix.
Definition: SgMatrix.h:260
double ** B_
A pointer on a pointer of a first element of the matrix.
Definition: SgMatrix.h:261
unsigned int NRow_
An number of rows in a matrix.
Definition: SgMatrix.h:249
double getElement(unsigned int i, unsigned int j) const
Definition: SgSymMatrix.h:274
friend SgSymMatrix operator-(const SgSymMatrix &P)
Definition: SgSymMatrix.h:397
double & operator()(unsigned int i, unsigned int j)
Definition: SgSymMatrix.h:257
const double *const * base_c() const
Definition: SgSymMatrix.h:100
SgSymMatrix T() const
Definition: SgSymMatrix.h:361
void setElement(unsigned int i, unsigned int j, double d)
Definition: SgSymMatrix.h:291
friend SgSymMatrix operator/(const SgSymMatrix &P, double d)
Definition: SgSymMatrix.h:389
SgSymMatrix & operator+=(const SgSymMatrix &P)
Definition: SgSymMatrix.h:321
friend SgSymMatrix operator*(const SgSymMatrix &P, double d)
Definition: SgSymMatrix.h:373
SgSymMatrix & operator-=(const SgSymMatrix &P)
Definition: SgSymMatrix.h:329
SgSymMatrix & operator/=(double d)
Definition: SgSymMatrix.h:353
double **& base()
Definition: SgSymMatrix.h:98
friend SgSymMatrix operator~(const SgSymMatrix &P)
Definition: SgSymMatrix.h:421
friend SgMatrix calcProduct_mat_x_mat(const SgMatrix &M1, const SgSymMatrix &P2)
Definition: SgSymMatrix.cpp:73
SgSymMatrix & operator*=(double d)
Definition: SgSymMatrix.h:345
friend SgSymMatrix operator+(const SgSymMatrix &P1, const SgSymMatrix &P2)
Definition: SgSymMatrix.h:405
SgSymMatrix & operator=(const SgSymMatrix &P)
Definition: SgSymMatrix.h:313
SgUtMatrix & operator*=(double d)
Definition: SgUtMatrix.h:448
SgUtMatrix & operator-=(const SgUtMatrix &R)
Definition: SgUtMatrix.h:424
SgUtMatrix & operator=(const SgUtMatrix &R)
Definition: SgUtMatrix.cpp:39
SgUtMatrix & operator/=(double d)
Definition: SgUtMatrix.h:461
SgUtMatrix & operator+=(const SgUtMatrix &R)
Definition: SgUtMatrix.h:400