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