source: Sophya/trunk/SophyaLib/NTools/tvector.h@ 299

Last change on this file since 299 was 299, checked in by ansari, 26 years ago

TMatrix et TVector suite cmv 17/5/99

File size: 2.4 KB
Line 
1// This may look like C code, but it is really -*- C++ -*-
2// C.Magneville 05/99
3#ifndef TVECTOR_SEEN
4#define TVECTOR_SEEN
5
6#include "tmatrix.h"
7class GeneralFit;
8
9namespace PlanckDPC {
10
11template <class T>
12class TVector : public TMatrix<T> {
13public:
14
15 // Creation / destruction
16 TVector(uint_4 n=1);
17 TVector(uint_4 n, T* values,Bridge* br=NULL);
18 TVector(const TVector<T>& v);
19 TVector(const TVector<T>& v,bool share);
20 TVector(const TMatrix<T>& a);
21
22 // Gestion taille/Remplissage
23 inline void ReSize(uint_4 n) {TMatrix<T>::ReSize(n,1);} // Reallocation de place
24
25 // Informations pointeur/data
26 inline uint_4 NElts() const {return NRows();}
27
28 // Acces aux elements
29 inline T& operator()(uint_4 n) {return (*this)[n];}
30 inline T const& operator()(uint_4 n) const {return (*this)[n];}
31
32 // Operateur d'affectation
33 inline TVector& operator = (const TVector& v)
34 {TMatrix<T>::operator =(v); return *this;}
35 inline TVector& operator = (T x)
36 {for(uint_4 i=0;i<NRows();i++) (*this)(i)=x; return *this;}
37
38 // Residus et fonction fittees.
39 TVector<T> FitResidus(GeneralFit& gfit);
40 TVector<T> FitFunction(GeneralFit& gfit);
41
42};
43
44// produit scalaire, matrice*vecteur
45template <class T> inline T operator* (const TVector<T>& v1, const TVector<T>& v2)
46 {if(v1.NRows() != v2.NRows())
47 throw(SzMismatchError("TVector::operator*(TVector& v1,TVector v2) size mismatch"));
48 T *p = const_cast<T *>(v1.Data()), *pEnd = p+v1.NElts(),
49 *q = const_cast<T *>(v2.Data()), r = 0;
50 while (p<pEnd) r += *p++ * *q++;
51 return r;}
52
53template <class T> inline TVector<T> operator* (const TMatrix<T>& a, const TVector<T>& b)
54 {return TVector<T>(a * ((TMatrix<T> const&)(b)));}
55
56// Resolution du systeme A*C = B
57inline r_8 LinSolveInPlace(TMatrix<r_8>& a, TVector<r_8>& b)
58{
59if(a.NCols() != b.NRows() || a.NCols() != a.NRows())
60 throw(SzMismatchError("LinSolveInPlace(TMatrix<r_8>,TVector<r_8>) size mismatch"));
61return TMatrix<r_8>::GausPiv(a,b);
62}
63
64// Resolution du systeme A*C = B, avec C retourne dans B
65inline r_8 LinSolve(const TMatrix<r_8>& a, const TVector<r_8>& b, TVector<r_8>& c)
66{
67if(a.NCols() != b.NRows() || a.NCols() != a.NRows())
68 throw(SzMismatchError("LinSolve(TMatrix<r_8>,TVector<r_8>) size mismatch"));
69c = b;
70TMatrix<r_8> a1(a);
71return TMatrix<r_8>::GausPiv(a1,c);
72}
73
74} // Fin du namespace
75
76#endif
Note: See TracBrowser for help on using the repository browser.