[299] | 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 PlanckDPC {
|
---|
| 9 |
|
---|
[307] | 10 | class GeneralFit;
|
---|
| 11 |
|
---|
[299] | 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 |
|
---|
| 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.
|
---|
[301] | 40 | TVector<T> FitResidus(GeneralFit& gfit,double xorg=0.,double dx=1.);
|
---|
| 41 | TVector<T> FitFunction(GeneralFit& gfit,double xorg=0.,double dx=1.);
|
---|
[299] | 42 |
|
---|
| 43 | };
|
---|
| 44 |
|
---|
| 45 | // produit scalaire, matrice*vecteur
|
---|
| 46 | template <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 |
|
---|
| 54 | template <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
|
---|
| 58 | inline r_8 LinSolveInPlace(TMatrix<r_8>& a, TVector<r_8>& b)
|
---|
| 59 | {
|
---|
| 60 | if(a.NCols() != b.NRows() || a.NCols() != a.NRows())
|
---|
| 61 | throw(SzMismatchError("LinSolveInPlace(TMatrix<r_8>,TVector<r_8>) size mismatch"));
|
---|
| 62 | return TMatrix<r_8>::GausPiv(a,b);
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | // Resolution du systeme A*C = B, avec C retourne dans B
|
---|
| 66 | inline r_8 LinSolve(const TMatrix<r_8>& a, const TVector<r_8>& b, TVector<r_8>& c)
|
---|
| 67 | {
|
---|
| 68 | if(a.NCols() != b.NRows() || a.NCols() != a.NRows())
|
---|
| 69 | throw(SzMismatchError("LinSolve(TMatrix<r_8>,TVector<r_8>) size mismatch"));
|
---|
| 70 | c = b;
|
---|
| 71 | TMatrix<r_8> a1(a);
|
---|
| 72 | return TMatrix<r_8>::GausPiv(a1,c);
|
---|
| 73 | }
|
---|
| 74 |
|
---|
[306] | 75 | /////////////////////////////////////////////////////////////////////////
|
---|
| 76 | // Classe pour la gestion de persistance
|
---|
| 77 | template <class T>
|
---|
| 78 | class FIO_TVector : public PPersist {
|
---|
| 79 | public:
|
---|
| 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); }
|
---|
| 87 | protected :
|
---|
| 88 | virtual void ReadSelf(PInPersist&);
|
---|
| 89 | virtual void WriteSelf(POutPersist&) const;
|
---|
| 90 | TVector<T> * dobj;
|
---|
| 91 | bool ownobj;
|
---|
| 92 | };
|
---|
| 93 |
|
---|
[490] | 94 | template <class T>
|
---|
| 95 | inline POutPersist& operator << (POutPersist& os, TVector<T> & obj)
|
---|
| 96 | { FIO_TVector<T> fio(&obj); fio.Write(os); return(os); }
|
---|
| 97 | template <class T>
|
---|
| 98 | inline PInPersist& operator >> (PInPersist& is, TVector<T> & obj)
|
---|
| 99 | { FIO_TVector<T> fio(&obj); fio.Read(is); return(is); }
|
---|
| 100 |
|
---|
[299] | 101 | } // Fin du namespace
|
---|
| 102 |
|
---|
| 103 | #endif
|
---|