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

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

FIO_... + grosses modifs cmv 19/5/99

File size: 3.0 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"
7
8namespace PlanckDPC {
9
10class GeneralFit;
11
12template <class T>
13class TVector : public TMatrix<T> {
14public:
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
26 // Informations pointeur/data
27 inline uint_4 NElts() const {return NRows();}
28
29 // Acces aux elements
30 inline T& operator()(uint_4 n) {return (*this)[n];}
31 inline T const& operator()(uint_4 n) const {return (*this)[n];}
32
33 // Operateur d'affectation
34 inline TVector& operator = (const TVector& v)
35 {TMatrix<T>::operator =(v); return *this;}
36 inline TVector& operator = (T x)
37 {for(uint_4 i=0;i<NRows();i++) (*this)(i)=x; return *this;}
38
39 // Residus et fonction fittees.
40 TVector<T> FitResidus(GeneralFit& gfit,double xorg=0.,double dx=1.);
41 TVector<T> FitFunction(GeneralFit& gfit,double xorg=0.,double dx=1.);
42
43};
44
45// produit scalaire, matrice*vecteur
46template <class T> inline T operator* (const TVector<T>& v1, const TVector<T>& v2)
47 {if(v1.NRows() != v2.NRows())
48 throw(SzMismatchError("TVector::operator*(TVector& v1,TVector v2) size mismatch"));
49 T *p = const_cast<T *>(v1.Data()), *pEnd = p+v1.NElts(),
50 *q = const_cast<T *>(v2.Data()), r = 0;
51 while (p<pEnd) r += *p++ * *q++;
52 return r;}
53
54template <class T> inline TVector<T> operator* (const TMatrix<T>& a, const TVector<T>& b)
55 {return TVector<T>(a * ((TMatrix<T> const&)(b)));}
56
57// Resolution du systeme A*C = B
58inline r_8 LinSolveInPlace(TMatrix<r_8>& a, TVector<r_8>& b)
59{
60if(a.NCols() != b.NRows() || a.NCols() != a.NRows())
61 throw(SzMismatchError("LinSolveInPlace(TMatrix<r_8>,TVector<r_8>) size mismatch"));
62return TMatrix<r_8>::GausPiv(a,b);
63}
64
65// Resolution du systeme A*C = B, avec C retourne dans B
66inline r_8 LinSolve(const TMatrix<r_8>& a, const TVector<r_8>& b, TVector<r_8>& c)
67{
68if(a.NCols() != b.NRows() || a.NCols() != a.NRows())
69 throw(SzMismatchError("LinSolve(TMatrix<r_8>,TVector<r_8>) size mismatch"));
70c = b;
71TMatrix<r_8> a1(a);
72return TMatrix<r_8>::GausPiv(a1,c);
73}
74
75/////////////////////////////////////////////////////////////////////////
76// Classe pour la gestion de persistance
77template <class T>
78class FIO_TVector : public PPersist {
79public:
80 FIO_TVector();
81 FIO_TVector(string const & filename);
82 FIO_TVector(const TVector<T> & obj);
83 FIO_TVector(TVector<T> * obj);
84 virtual ~FIO_TVector();
85 virtual AnyDataObj* DataObj();
86 inline operator TVector<T>() { return(*dobj); }
87protected :
88 virtual void ReadSelf(PInPersist&);
89 virtual void WriteSelf(POutPersist&) const;
90 TVector<T> * dobj;
91 bool ownobj;
92};
93
94} // Fin du namespace
95
96#endif
Note: See TracBrowser for help on using the repository browser.