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

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

cvector.h ne servait a rien cmv 23/10/99

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