Changeset 514 in Sophya for trunk/SophyaLib/NTools/poly.h


Ignore:
Timestamp:
Oct 25, 1999, 6:43:04 PM (26 years ago)
Author:
ansari
Message:

elimination des OVector/OMatrix au profit des TVector/TMatrix cmv 25/10/99

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/NTools/poly.h

    r508 r514  
    11// This may look like C code, but it is really -*- C++ -*-
    22//
    3 // $Id: poly.h,v 1.2 1999-10-25 10:36:11 ansari Exp $
     3// $Id: poly.h,v 1.3 1999-10-25 16:40:01 ansari Exp $
    44//
    5 
    65
    76// Des polynomes avec des operations de bases et surtout des fits.
     
    109#define POLY_SEEN
    1110
     11#include "objfio.h"
    1212#include <stdio.h>
    1313#include "peida.h"
    14 #include "cvector.h"
     14#include "tvector.h"
     15#include "ppersist.h"
     16#include "anydataobj.h"
     17
     18namespace PlanckDPC {
    1519
    1620class Poly2;
    1721
    18 class Poly : public OVector {
     22//////////////////////////////////////////////////////////////////////////
     23class Poly : public Vector {
     24  friend class ObjFileIO<Poly>;
    1925public:
    2026  Poly(int degre = 0);
     27  Poly(Poly const& a);
    2128
    2229  enum {classId = ClassId_Poly1};
    23   int_4                 ClassId() const         { return classId; }
    24   static PPersist*      Create() {return new Poly;}
     30  int_4  ClassId() const         { return classId; }
    2531
    2632  inline int Degre() const {UpdateDegIfDirty(); return deg;}
    2733
    28   inline void Realloc(int n, bool force=false) {OVector::Realloc(n+1,force);}
    29 
    30   inline double operator[](int i) const {return data[i];}
    31   inline double& operator[](int i) {dirty = 1; return data[i];}
     34  inline void Realloc(int n, bool force=false) {Vector::Realloc(n+1,force);}
     35
     36  inline double operator[](int i) const {return Element(i);}
     37  inline double& operator[](int i) {dirty = 1; return Element(i);}
    3238  // Retourne le coefficient de degre i
    3339
     
    4147  // Derive le polynome dans un autre
    4248
    43   int    Roots(OVector& roots) const;
     49  int    Roots(Vector& roots) const;
    4450  // retourne les racines si on peut les calculer...
    4551
     
    4955  int    Root2(double& r1, double& r2) const;
    5056  // special degre 2
    51 
    52   friend Poly operator* (Poly const& a, Poly const& b);
    53   friend Poly operator+ (Poly const& a, Poly const& b);
    54   friend Poly operator- (Poly const& a, Poly const& b);
    5557
    5658  Poly& operator = (Poly const& b);
     
    5860  Poly& operator -= (Poly const& b);
    5961
    60   friend Poly operator* (double a, Poly const& b);
    61 
    6262  Poly& operator *= (double a);
     63
     64  Poly Mult(Poly const& b) const;
    6365
    6466  Poly power(int n) const;
     
    6668  Poly2 operator() (Poly2 const& b) const;
    6769
    68   void ReadSelf(PInPersist&);
    69   void WriteSelf(POutPersist&) const;
    70 
    7170  void Print(ostream& s) const;
    72   friend ostream& operator << (ostream& s, const Poly& a);
    73 
    74   double Fit(OVector const& x, OVector const& y, int degre);
     71
     72  double Fit(Vector const& x, Vector const& y, int degre);
    7573  // Fit d'un polynome de degre donne sur les x et y.
    7674
    77   double Fit(OVector const& x, OVector const& y, OVector const& erry2, int degre,
    78             OVector& errCoef);
     75  double Fit(Vector const& x, Vector const& y, Vector const& erry2, int degre,
     76            Vector& errCoef);
    7977  // En plus, on fournit les carres des erreurs sur y et on a les erreurs
    8078  // sur les coefficients dans un vecteur.
     
    8785};
    8886
     87inline Poly operator* (Poly const& a, Poly const& b)
     88  { return a.Mult(b); }
     89
     90inline Poly operator+ (Poly const& a, Poly const& b)
     91 { Poly c((a.Degre() > b.Degre())?(a.Degre()+1):(b.Degre()+1));
     92   c = a; c += b; return c; }
     93
     94inline Poly operator- (Poly const& a, Poly const& b)
     95  { Poly c((a.Degre() > b.Degre())?(a.Degre()+1):(b.Degre()+1));
     96    c = a; c -= b; return c; }
     97
     98inline Poly operator* (double a, Poly const& b)
     99  { Poly c(b); c *= a; return c; }
     100
     101inline ostream& operator << (ostream& s, const Poly& a)
     102  { a.Print(s); return s; }
     103
     104//////////////////////////////////////////////////////////////////////////
     105inline POutPersist& operator << (POutPersist& os, Poly & obj)
     106  { ObjFileIO<Poly> fio(&obj);  fio.Write(os);  return(os); }
     107inline PInPersist& operator >> (PInPersist& is, Poly & obj)
     108  { ObjFileIO<Poly> fio(&obj);  fio.Read(is);  return(is); }
     109// Classe pour la gestion de persistance
     110// ObjFileIO<Poly>
     111
     112//////////////////////////////////////////////////////////////////////////
    89113int binomial(int n, int p);
    90114
    91 
    92 class Poly2 : public OVector {  // Ca pourrait etre une matrice mais
    93                                   // la encore, un vecteur est utile pour les
    94                                   // fits.
    95 
     115//////////////////////////////////////////////////////////////////////////
     116class Poly2 : public Vector {
     117  friend class ObjFileIO<Poly2>;
    96118public:
    97119  Poly2(int degreX=0, int degreY=0);
     
    101123
    102124  enum {classId = ClassId_Poly2};
    103   int_4                 ClassId() const         { return classId; }
    104   static PPersist*      Create() {return new Poly2;}
     125  int_4 ClassId() const         { return classId; }
    105126
    106127  inline int DegX() const {UpdateDegIfDirty(); return degX;}
     
    123144
    124145  inline double Coef(int dx, int dy) const {
    125     return (dx>maxDegX || dy>maxDegY) ? 0 : data[IndCoef(dx,dy)];
     146    return (dx>maxDegX || dy>maxDegY) ? 0 : Element(IndCoef(dx,dy));
    126147  }
    127148  inline double& Coef(int dx, int dy) {
    128149    if (dx>maxDegX || dy>maxDegY) THROW(rangeCheckErr);
    129     dirty = 1; return data[IndCoef(dx,dy)];
     150    dirty = 1; return Element(IndCoef(dx,dy));
    130151  }
    131152  // retourne le coefficient de degre (dx,dy)
    132153
    133   double Fit(OVector const& x, OVector const& y, OVector const& z,
     154  double Fit(Vector const& x, Vector const& y, Vector const& z,
    134155             int degreX, int degreY);
    135   double Fit(OVector const& x, OVector const& y, OVector const& z,
    136              OVector const& errz2, int degreX, int degreY,
    137              OVector& errCoef);
     156  double Fit(Vector const& x, Vector const& y, Vector const& z,
     157             Vector const& errz2, int degreX, int degreY,
     158             Vector& errCoef);
    138159  // degres partiels imposes. cf Poly::Fit sinon
    139160
    140161
    141   double Fit(OVector const& x, OVector const& y, OVector const& z,
     162  double Fit(Vector const& x, Vector const& y, Vector const& z,
    142163             int degre);
    143   double Fit(OVector const& x, OVector const& y, OVector const& z,
    144              OVector const& errz2, int degre,
    145              OVector& errCoef);
     164  double Fit(Vector const& x, Vector const& y, Vector const& z,
     165             Vector const& errz2, int degre,
     166             Vector& errCoef);
    146167  // degre total impose. cf Poly::Fit sinon
    147168
     
    151172  Poly2& operator -= (Poly2 const& b);
    152173
    153   friend Poly2 operator + (Poly2 const& a, Poly2 const& b);
    154   friend Poly2 operator - (Poly2 const& a, Poly2 const& b);
    155   friend Poly2 operator * (Poly2 const& a, Poly2 const& b);
     174  Poly2& operator *= (double a);
     175
     176  Poly2 Mult(Poly2 const& b) const;
    156177
    157178  Poly2 power(int n) const;
    158 
    159   Poly2& operator *= (double a);
    160   friend Poly2 operator * (double a, Poly2 const& b);
    161179
    162180  Poly2 operator() (Poly const& px, Poly const& py) const;
     
    165183  void Realloc(int degreX, int degreY);
    166184
    167   void ReadSelf(PInPersist&);
    168   void WriteSelf(POutPersist&) const;
    169 
    170185  void Print(ostream& s) const;
    171   friend ostream& operator << (ostream& s, const Poly2& a);
    172186
    173187private:
     
    182196};
    183197
     198inline Poly2 operator* (Poly2 const& a, Poly2 const& b)
     199  { return a.Mult(b); }
     200
     201inline Poly2 operator+ (Poly2 const& a, Poly2 const& b)
     202  { Poly2 c(a); c += b; return c; }
     203
     204inline Poly2 operator- (Poly2 const& a, Poly2 const& b)
     205  { Poly2 c(a); c -= b; return c; }
     206
     207inline Poly2 operator * (double a, Poly2 const& b)
     208  { Poly2 c(b); c *= a; return c; }
     209
     210inline ostream& operator << (ostream& s, const Poly2& a)
     211  { a.Print(s); return s; }
     212
     213//////////////////////////////////////////////////////////////////////////
     214inline POutPersist& operator << (POutPersist& os, Poly2 & obj)
     215  { ObjFileIO<Poly2> fio(&obj);  fio.Write(os);  return(os); }
     216inline PInPersist& operator >> (PInPersist& is, Poly2 & obj)
     217  { ObjFileIO<Poly2> fio(&obj);  fio.Read(is);  return(is); }
     218// Classe pour la gestion de persistance
     219// ObjFileIO<Poly2>
     220
     221
     222} // Fin du namespace
     223
    184224#endif // POLY_SEEN
Note: See TracChangeset for help on using the changeset viewer.