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"
|
---|
7 | class GeneralFit;
|
---|
8 |
|
---|
9 | namespace PlanckDPC {
|
---|
10 |
|
---|
11 | template <class T>
|
---|
12 | class TVector : public TMatrix<T> {
|
---|
13 | public:
|
---|
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
|
---|
45 | template <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 |
|
---|
53 | template <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
|
---|
57 | inline r_8 LinSolveInPlace(TMatrix<r_8>& a, TVector<r_8>& b)
|
---|
58 | {
|
---|
59 | if(a.NCols() != b.NRows() || a.NCols() != a.NRows())
|
---|
60 | throw(SzMismatchError("LinSolveInPlace(TMatrix<r_8>,TVector<r_8>) size mismatch"));
|
---|
61 | return TMatrix<r_8>::GausPiv(a,b);
|
---|
62 | }
|
---|
63 |
|
---|
64 | // Resolution du systeme A*C = B, avec C retourne dans B
|
---|
65 | inline r_8 LinSolve(const TMatrix<r_8>& a, const TVector<r_8>& b, TVector<r_8>& c)
|
---|
66 | {
|
---|
67 | if(a.NCols() != b.NRows() || a.NCols() != a.NRows())
|
---|
68 | throw(SzMismatchError("LinSolve(TMatrix<r_8>,TVector<r_8>) size mismatch"));
|
---|
69 | c = b;
|
---|
70 | TMatrix<r_8> a1(a);
|
---|
71 | return TMatrix<r_8>::GausPiv(a1,c);
|
---|
72 | }
|
---|
73 |
|
---|
74 | } // Fin du namespace
|
---|
75 |
|
---|
76 | #endif
|
---|