| 1 | // This may look like C code, but it is really -*- C++ -*-
 | 
|---|
| 2 | 
 | 
|---|
| 3 | #ifndef VECTOR_SEEN
 | 
|---|
| 4 | #define VECTOR_SEEN
 | 
|---|
| 5 | #include "matrix.h"
 | 
|---|
| 6 | 
 | 
|---|
| 7 | namespace SOPHYA {
 | 
|---|
| 8 |   class GeneralFit;
 | 
|---|
| 9 |   template <class T> class TVector;
 | 
|---|
| 10 | }
 | 
|---|
| 11 | 
 | 
|---|
| 12 | // <summary> Vecteur colonne pour operations matricielles </summary>
 | 
|---|
| 13 | // Vecteur colonne, en fait une matrice avec une seule colonne, pour faire
 | 
|---|
| 14 | // des operations matricielles.
 | 
|---|
| 15 | class OVector : public OMatrix {
 | 
|---|
| 16 |   friend class TVector<r_8>;
 | 
|---|
| 17 | public:
 | 
|---|
| 18 |   // Constructeur, n = nombre d'elements.
 | 
|---|
| 19 |   EXPLICIT OVector(int n=1);
 | 
|---|
| 20 |   // Constructeur, a partir des valeurs. Pas d'allocation.
 | 
|---|
| 21 |   OVector(int n, double* values);
 | 
|---|
| 22 |   // Constructeur par copie
 | 
|---|
| 23 |   OVector(const OVector& v);
 | 
|---|
| 24 |   // Constructeur par "copie" a partir d'une matrice, qui doit avoir une colonne
 | 
|---|
| 25 |   // <thrown> sizeMismatchErr </thrown>
 | 
|---|
| 26 |   OVector(const OMatrix& a);
 | 
|---|
| 27 |   // Constructeur par copie a partir d'un TVector<r_8>
 | 
|---|
| 28 |   OVector(const TVector<r_8>& v);
 | 
|---|
| 29 | 
 | 
|---|
| 30 |   // Construction automatique pour PPF
 | 
|---|
| 31 |   // <group>
 | 
|---|
| 32 |   enum {classId = ClassId_Vector};
 | 
|---|
| 33 |   int_4                 ClassId() const         { return classId; }
 | 
|---|
| 34 |   static PPersist*      Create() {return new OVector(1);}
 | 
|---|
| 35 |   // </group>
 | 
|---|
| 36 |   
 | 
|---|
| 37 |   // Change la taille du vecteur. Reallocation physique seulement si
 | 
|---|
| 38 |   // pas assez de place, ou forcee si force=true
 | 
|---|
| 39 |   void Realloc(int n, bool force=false);
 | 
|---|
| 40 | 
 | 
|---|
| 41 |   OVector& operator = (const OVector& v);
 | 
|---|
| 42 |   OVector& operator = (double x);
 | 
|---|
| 43 | 
 | 
|---|
| 44 |   // Acces aux elements
 | 
|---|
| 45 |   // <group>
 | 
|---|
| 46 |   double& operator()(int n);
 | 
|---|
| 47 |   double const& operator()(int n) const;
 | 
|---|
| 48 |   // </group>
 | 
|---|
| 49 | 
 | 
|---|
| 50 |   // produit scalaire
 | 
|---|
| 51 |   // <group>
 | 
|---|
| 52 |   friend double operator* (const OVector& v1, const OVector& v2);
 | 
|---|
| 53 |   friend OVector operator* (const OVector& v, double b)
 | 
|---|
| 54 |   {return OVector(((OMatrix const&)v) * b);}
 | 
|---|
| 55 |   // </group>
 | 
|---|
| 56 |   // produit matrice*vecteur
 | 
|---|
| 57 |   friend OVector operator* (const OMatrix& a, const OVector& b)
 | 
|---|
| 58 |   {return OVector(a * ((OMatrix const&) (b)));}
 | 
|---|
| 59 | 
 | 
|---|
| 60 |   // Nombre de lignes du vecteur
 | 
|---|
| 61 |   int NElts() const {return nr;}
 | 
|---|
| 62 | 
 | 
|---|
| 63 |   // Resolution du systeme A*C = B
 | 
|---|
| 64 |   friend double LinSolve(const OMatrix& a, const OVector& b, OVector& c);
 | 
|---|
| 65 |   
 | 
|---|
| 66 |   // Resolution du systeme A*C = B, avec C retourne dans B
 | 
|---|
| 67 |   friend double LinSolveInPlace(OMatrix& a, OVector& b);
 | 
|---|
| 68 | 
 | 
|---|
| 69 |   // Residus et fonction fittees.
 | 
|---|
| 70 |   OVector FitResidus(GeneralFit& gfit,double xorg=0.,double dx=1.);
 | 
|---|
| 71 |   OVector FitFunction(GeneralFit& gfit,double xorg=0.,double dx=1.);
 | 
|---|
| 72 | 
 | 
|---|
| 73 | };
 | 
|---|
| 74 | 
 | 
|---|
| 75 | 
 | 
|---|
| 76 | inline OVector& OVector::operator = (const OVector& v)
 | 
|---|
| 77 | { OMatrix::operator =(v); return *this; }
 | 
|---|
| 78 | 
 | 
|---|
| 79 | 
 | 
|---|
| 80 | inline double const& OVector::operator()(int n) const
 | 
|---|
| 81 | {
 | 
|---|
| 82 | #ifdef RGCHECK
 | 
|---|
| 83 |   if (n<0 || n>=ndata) THROW(rangeCheckErr);
 | 
|---|
| 84 | #endif
 | 
|---|
| 85 |   return data[n];
 | 
|---|
| 86 | }
 | 
|---|
| 87 | 
 | 
|---|
| 88 | 
 | 
|---|
| 89 | inline double& OVector::operator()(int n)
 | 
|---|
| 90 | { 
 | 
|---|
| 91 | #ifdef RGCHECK
 | 
|---|
| 92 |   if (n<0 || n>=ndata) THROW(rangeCheckErr);
 | 
|---|
| 93 | #endif
 | 
|---|
| 94 |   return data[n];
 | 
|---|
| 95 | }
 | 
|---|
| 96 | 
 | 
|---|
| 97 | inline void OVector::Realloc(int n, bool force)
 | 
|---|
| 98 | { OMatrix::Realloc(n,1,force);}
 | 
|---|
| 99 | 
 | 
|---|
| 100 | 
 | 
|---|
| 101 | #endif /* VECTOR_SEEN */
 | 
|---|