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 |
|
---|
8 | namespace SOPHYA {
|
---|
9 |
|
---|
10 | class GeneralFit;
|
---|
11 |
|
---|
12 | template <class T>
|
---|
13 | class TVector : public TMatrix<T> {
|
---|
14 | public:
|
---|
15 |
|
---|
16 | // Creation / destruction
|
---|
17 | TVector(uint_4 n=1);
|
---|
18 | TVector(uint_4 n, T* values,Bridge* br=NULL);
|
---|
19 | TVector(const TVector<T>& v);
|
---|
20 | TVector(const TVector<T>& v,bool share);
|
---|
21 | TVector(const TMatrix<T>& a);
|
---|
22 |
|
---|
23 | // Gestion taille/Remplissage
|
---|
24 | inline void ReSize(uint_4 n) {TMatrix<T>::ReSize(n,1);} // Reallocation de place
|
---|
25 | inline void Realloc(uint_4 n,bool force=false) {TMatrix<T>::Realloc(n,1,force);}
|
---|
26 |
|
---|
27 | // Informations pointeur/data
|
---|
28 | inline uint_4 NElts() const {return NRows();}
|
---|
29 |
|
---|
30 | // Acces aux elements
|
---|
31 | inline T& operator()(uint_4 n) {return (*this)[n];}
|
---|
32 | inline T const& operator()(uint_4 n) const {return (*this)[n];}
|
---|
33 | inline T& Element(uint_4 n) {return (*this)[n];}
|
---|
34 | inline T const& Element(uint_4 n) const {return (*this)[n];}
|
---|
35 |
|
---|
36 | // Operateur d'affectation
|
---|
37 | inline TVector& operator = (const TVector& v)
|
---|
38 | {TMatrix<T>::operator =(v); return *this;}
|
---|
39 | inline TVector& operator = (T x)
|
---|
40 | {for(uint_4 i=0;i<NRows();i++) (*this)(i)=x; return *this;}
|
---|
41 |
|
---|
42 | // Residus et fonction fittees.
|
---|
43 | TVector<T> FitResidus(GeneralFit& gfit,double xorg=0.,double dx=1.);
|
---|
44 | TVector<T> FitFunction(GeneralFit& gfit,double xorg=0.,double dx=1.);
|
---|
45 |
|
---|
46 | };
|
---|
47 |
|
---|
48 | // produit scalaire, matrice*vecteur
|
---|
49 | template <class T>
|
---|
50 | inline T operator* (const TVector<T>& v1, const TVector<T>& v2)
|
---|
51 | {if(v1.NRows() != v2.NRows())
|
---|
52 | throw(SzMismatchError("TVector::operator*(TVector& v1,TVector v2) size mismatch"));
|
---|
53 | T *p = const_cast<T *>(v1.Data()), *pEnd = p+v1.NElts(),
|
---|
54 | *q = const_cast<T *>(v2.Data()), r = 0;
|
---|
55 | while (p<pEnd) r += *p++ * *q++;
|
---|
56 | return r;}
|
---|
57 |
|
---|
58 | template <class T>
|
---|
59 | inline TVector<T> operator* (const TMatrix<T>& a, const TVector<T>& b)
|
---|
60 | {return TVector<T>(a * ((TMatrix<T> const&)(b)));}
|
---|
61 |
|
---|
62 | // Resolution du systeme A*C = B
|
---|
63 | inline r_8 LinSolveInPlace(TMatrix<r_8>& a, TVector<r_8>& b)
|
---|
64 | {
|
---|
65 | if(a.NCols() != b.NRows() || a.NCols() != a.NRows())
|
---|
66 | throw(SzMismatchError("LinSolveInPlace(TMatrix<r_8>,TVector<r_8>) size mismatch"));
|
---|
67 | return TMatrix<r_8>::GausPiv(a,b);
|
---|
68 | }
|
---|
69 |
|
---|
70 | // Resolution du systeme A*C = B, avec C retourne dans B
|
---|
71 | inline r_8 LinSolve(const TMatrix<r_8>& a, const TVector<r_8>& b, TVector<r_8>& c)
|
---|
72 | {
|
---|
73 | if(a.NCols() != b.NRows() || a.NCols() != a.NRows())
|
---|
74 | throw(SzMismatchError("LinSolve(TMatrix<r_8>,TVector<r_8>) size mismatch"));
|
---|
75 | c = b;
|
---|
76 | TMatrix<r_8> a1(a);
|
---|
77 | return TMatrix<r_8>::GausPiv(a1,c);
|
---|
78 | }
|
---|
79 |
|
---|
80 | // Typedef pour simplifier et compatibilite Peida
|
---|
81 | typedef TVector<r_8> Vector;
|
---|
82 |
|
---|
83 | /////////////////////////////////////////////////////////////////////////
|
---|
84 | // Classe pour la gestion de persistance
|
---|
85 | template <class T>
|
---|
86 | class FIO_TVector : public PPersist {
|
---|
87 | public:
|
---|
88 | FIO_TVector();
|
---|
89 | FIO_TVector(string const & filename);
|
---|
90 | FIO_TVector(const TVector<T> & obj);
|
---|
91 | FIO_TVector(TVector<T> * obj);
|
---|
92 | virtual ~FIO_TVector();
|
---|
93 | virtual AnyDataObj* DataObj();
|
---|
94 | inline operator TVector<T>() { return(*dobj); }
|
---|
95 | protected :
|
---|
96 | virtual void ReadSelf(PInPersist&);
|
---|
97 | virtual void WriteSelf(POutPersist&) const;
|
---|
98 | TVector<T> * dobj;
|
---|
99 | bool ownobj;
|
---|
100 | };
|
---|
101 |
|
---|
102 | template <class T>
|
---|
103 | inline POutPersist& operator << (POutPersist& os, TVector<T> & obj)
|
---|
104 | { FIO_TVector<T> fio(&obj); fio.Write(os); return(os); }
|
---|
105 | template <class T>
|
---|
106 | inline PInPersist& operator >> (PInPersist& is, TVector<T> & obj)
|
---|
107 | { FIO_TVector<T> fio(&obj); fio.Read(is); return(is); }
|
---|
108 |
|
---|
109 | } // Fin du namespace
|
---|
110 |
|
---|
111 | #endif
|
---|