begin process at 2012 05 29 19:39:41
  Trouver un code source :
 
dans
 
Accueil > Forum > 

C++ & C++ .NET

 > 

Algorithme

 > 

Maths

 > 

Gérer mieux la memoire


Derniers messages déposésPoser une question dans le forum ou lancer une discussion

Gérer mieux la memoire

mercredi 26 juillet 2006 à 08:08:57 | Gérer mieux la memoire

Stiko

salut,
j'utilise une classe faite en C++ pour les calculs matriciels de grand taille la classe est le suivant:
c'est le fichier .h
[code]
/*
 Matrix.h
*/

#ifndef __TMATRIX H__
#define __TMATRIX H__
 
#include <iostream>
#include <math.h>
using namespace std;
 
class TMatrixException /* Exception class for TFloatMatix */
{
    public:
      enum Exception
      {
           DIM_TOO_SMALL ,
           NOT_SAME_DIM ,
           NOT_SQUARE ,
           NOT_MULTIPLICABLE,
           NOT_UNI_COLUMN
      };
 
      TMatrixException(Exception);
      Exception Err;
};
 
template <class T> class TMatrix
{
    public:
      /* ---------------------- Attributes --------------------------- */
      T *M;                              /* Linear matrix data storage */
      T **P;                            /* Pointers on each rows */
      int dimR;                        /* Number of rows ( column size ) */
      int dimC;                       /* Number of columns ( row size ) */
         
     /* ----------------------- Builders --------------------------- */
      TMatrix(int );                             /* for square matrix */
      TMatrix(int dimRow=10, int dimCol=1);        /* Default, For NxM matrix */
      TMatrix(const TMatrix<T>&);               /* Copy */
      ~TMatrix();                             /* de-allocate memory */
 
      /* -------------------- Utils procedures ----------------------- */
      void clear();                            /* Reset to 0 all elements */
      void destroy();                          /* de-allocate memory */
      TMatrix<T> resize(int,int);             /* Set a new dimension */
      void resize(int dim=2);                /* The same, for square */
      void in(T*);                         /* Input data in a matrix */
      ostream& out(ostream&) const;          /* Display matrix on std::out */
 
     /* ------------- Functions and procedure on this object ------- */
      TMatrix ones();
      TMatrix<T> zeros();
      TMatrix cofactor();                  /* Return cofactor matrix */
      T cofactor(int, int);               /* 1 element cofactor */
      T determinant();                  /* Determinant of a matrix */
      void transpose();                   /* Transpose a matrix*/
      TMatrix<T> transpose1();          /* Transpose a matrix that returns a Mtarix*/
      void reverse();                /* Reverse a matrix */
      void TC();                    /* Transpose and cofactor matrix */
      TMatrix<T> mean();           /* mean value of array*/
      T norm();                      /*matrix norms*/
      TMatrix<T> fill( const TMatrix<T>&  ,const int ) ;
     /* ---------------------- Operators ---------------------------- */
      TMatrix<T>& operator=(const TMatrix<T>&);
     
      TMatrix<T> operator-()                  ;
      TMatrix<T> operator+(const TMatrix<T>&) ;
      TMatrix<T> operator-(const TMatrix<T>&) ;
      TMatrix<T> operator*(const TMatrix<T>&) ;
      TMatrix<T> operator*(const T);
      TMatrix<T> operator*=(const T);
      TMatrix<T> operator*=(const TMatrix<T>&  );
      TMatrix<T> operator/(const T );
      TMatrix<T> colonne(const int );
      T det3x3();                            /* return the determinant of a 3x3 matrix */
      T det2x2();                            /* return the determinant of a 2x2 matrix */
      TMatrix<T> mul(const TMatrix<T>&);  /* Multiply two matrices */
};
 
template <class T>
ostream& operator<< (ostream& o, const TMatrix<T>& m)
{return m.out(o);}
 
template <class T>
istream& operator>> (istream&, TMatrix<T>&);
#endif
//===========================================================================

[/code]

c'est le programme .CPP
[code]
 
// DernierMatrice11-7-06.cpp : définit le point d'entrée pour l'application console.
//

#include "stdafx.h"
#include <algorithm>
#include <fstream>
#include <string>
#include <sstream>
#include <functional>
#include "Matrix.h"
using namespace std;

TMatrixException::TMatrixException(Exception e) : Err(e)
{
    if (e==DIM_TOO_SMALL)
    {
        cout <<"ERR: DIM TOO SMALL"<<endl<<endl;
        system("pause");
        return;//exit(0);
    }
    if (e==NOT_SAME_DIM)
    {
        cout <<"FR: Additionner ou soustraire uniquement des ";
        cout <<"matrices de meme taille"<<endl;
        system("pause");
        return;//exit(0);
    }
    if (e==NOT_SQUARE)
    {
        cout <<"FR: Tentative d'utilisation d'une fonction reservee aux ";
        cout <<"matrices carrees sur une matrice non-carree."<<endl;
        system("pause");
        return;//exit(0);
    }
    if (e==NOT_MULTIPLICABLE)
    {
        cout <<"FR: Pour multiplier, le nombre de colonnes de la ";
        cout <<"premiere matrice doit etre egal au nombre de lignes ";
        cout <<"de la deuxieme."<<endl;
        system("pause");
        return;//exit(0);
    }
     if (e== NOT_UNI_COLUMN )
     {
        cout <<"FR: Pour faire cette operation, il faut que la matrice a  ";
        cout <<"une seulle colonne  ";
        system("pause");
        return;//exit(0);
     }
    else
    {
        cout <<"UNKNOW EXCEPTION"<<endl;
        system("pause");
        return ;//exit(0);
    }
}
//---------------------------------------------------------------------------
 
template <class T>
TMatrix<T>::TMatrix(int dimRow=10, int dimCol=1)
{
    if (dimRow<1 || dimCol<1)
        throw TMatrixException(TMatrixException::DIM_TOO_SMALL);
 
    dimR=dimRow;
    dimC=dimCol;
    
    M=new T[dimR*dimC*sizeof(T)];
    P=new T*[dimR*sizeof(T*)];
 
    T *ref;
    ref=M;
    for (int i=0; i<dimR; i++)
    {
        P[i]=ref;
        ref+=dimC;
    }
    clear();
}
//---------------------------------------------------------------------------
 
template <class T>
TMatrix<T>::TMatrix(int dim)
{
    if (dim<1)
        throw TMatrixException(TMatrixException::DIM_TOO_SMALL);
 
    dimR=dim;
    dimC=dim;
     
   
    M=new T[dimR*dimC*sizeof(T)];
    P=new T*[dimR*sizeof(T*)];
 
    T *ref;
    ref=M;
    for (int i=0; i<dimR; i++)
    {
        P[i]=ref;
        ref+=dimC;
    }
    clear();
}
//---------------------------------------------------------------------------
 
template <class T>
TMatrix<T>::TMatrix(const TMatrix<T>& m)
{
    dimR=m.dimR;
    dimC=m.dimC;
    M=m.M;
    P=m.P;
}
//---------------------------------------------------------------------------
 
template <class T>
TMatrix<T>::~TMatrix()
{
    /*delete[] M;
    delete[] P;*/
}
//---------------------------------------------------------------------------
 
template <class T>
void TMatrix<T>::destroy()
{   
    delete[] M;
    delete[] P;
}
//---------------------------------------------------------------------------
 
template <class T>
void TMatrix<T>::clear()
{
    for (int i=0; i<dimR; i++)
        for (int j=0; j<dimC; j++)
            P[i][j]=0;
}
//---------------------------------------------------------------------------
 
template <class T>
TMatrix<T> TMatrix<T>::resize(int rw, int cl)
{
    TMatrix<T> m(rw,cl);
    if (dimR*dimC <= rw*cl)
    {
        for (int i=0; i<dimR;i++)
            for (int j=0; j<dimC; j++)
                m.P[i][j]=P[i][j];
        for (int i2=dimR; i2<rw; i2++)
            for (int j2=dimC; j2<cl; j2++)
                m.P[i2][j2]=0;
    }
    else
    {
        for (int i=0; i<rw;i++)
            for (int j=0; j<cl; j++)
                m.P[i][j]=P[i][j];
    }
    *this=m;
    return *this;
}
//---------------------------------------------------------------------------
 
template <class T>
void TMatrix<T>::resize(int dim)
{
    TMatrix<T> m(dim);
    if (dimR*dimC <= dim*dim)
    {
        for (int i=0; i<dimR;i++)
            for (int j=0; j<dimC; j++)
                m.P[i][j]=P[i][j];
        for (int i2=dimR; i2<dim; i2++)
            for (int j2=dimC; j2<dim; j2++)
                m.P[i2][j2]=0;
    }
    else
    {
        for (int i=0; i<dim;i++)
            for (int j=0; j<dim; j++)
                m.P[i][j]=P[i][j];
    }
    *this=m;
}
//---------------------------------------------------------------------------
 
template <class T>
void TMatrix<T>::in(T *data)
{
    for (int i=0; i<dimR;i++)
        for (int j=0; j<dimC; j++)
            P[i][j]=data[dimC*i+j];
}
//---------------------------------------------------------------------------
 
template <class T>
ostream& TMatrix<T>::out(ostream& o) const
{
    for (int i=0; i<dimR; i++)
    {
        for (int j=0; j<dimC; j++)
            o <<P[i][j]<<" ";
        o <<endl;
    }
    return o;
}
//---------------------------------------------------------------------------

template <class T>
TMatrix<T> TMatrix<T>::ones()
{
    for (int i=0; i<dimR;i++)
        for (int j=0; j<dimC; j++)
            P[i][j]=1;
    return *this;
}   
//---------------------------------------------------------------------------

template <class T>
TMatrix<T> TMatrix<T>::zeros()
{
    for (int i=0; i<dimR;i++)
        for (int j=0; j<dimC; j++)
            P[i][j]=0;
    return *this;
}   

//---------------------------------------------------------------------------
template <class T>
TMatrix<T> TMatrix<T>::colonne(const int f)
{
 TMatrix<T> r(dimR,1);

    for (int i=0; i<dimR; i++)
    {
            r.P[i][0]=P[i][f];
    }
            return r;
}
//---------------------------------------------------------------------------
template <class T>
TMatrix<T> TMatrix<T>::fill( const TMatrix<T>& m , int f)
{  
if (m.dimC>1)
        throw TMatrixException(TMatrixException::NOT_UNI_COLUMN);
 
TMatrix<T> r(dimR,dimC);
    for (int i=0; i<dimR; i++)
                 P[i][f]=m.P[i][0];
    
           
    
            return *this;
}
//---------------------------------------------------------------------------

template <class T>
 TMatrix<T> TMatrix<T>::mean() //TMatrix<T>
{
    T *tab= new T [dimC];//=new double [5];
    int dimI=1;
    for (int j=0; j<dimC; j++)
        tab[j]=0;
    for (int i=0; i<dimR;i++)
        for (int j=0; j<dimC; j++)
             tab[j]+= P[i][j];
                    
        TMatrix<T> r(dimI,dimC);
    for (int i=0; i<dimI; i++)
        for (int j=0; j<dimC; j++)
        r.P[0][j]= tab[j]/float(dimR);
    
    return r;        
}   
//---------------------------------------------------------------------------
template <class T>
T TMatrix<T>::norm()
{
     double Add=0;
    
    for (int i=0; i<dimR; i++)
    {
        for (int j=0; j<dimC; j++)
          Add+= pow(P[i][j],2);
    }
double norm= sqrt(Add);
    return norm;

}
//---------------------------------------------------------------------------

template <class T>
TMatrix<T>& TMatrix<T>::operator=(const TMatrix<T>& m)
{
    dimR=m.dimR;
    dimC=m.dimC;
    M=m.M;
    P=m.P;
    return *this;
}
//---------------------------------------------------------------------------
 
template <class T>
TMatrix<T> TMatrix<T>::operator-()
{
    TMatrix<T> r(dimR,dimC);
    r=*this * T(-1);
    return r;
}
//---------------------------------------------------------------------------
 
template <class T>
TMatrix<T> TMatrix<T>::operator+(const TMatrix<T>& m)
{
    if (dimR!=m.dimR || dimC!=m.dimC)
        throw TMatrixException(TMatrixException::NOT_SAME_DIM);
 
    TMatrix<T> r(dimR,dimC);
    for (int i=0; i<dimR; i++)
        for (int j=0; j<dimC; j++)
            r.P[i][j]=P[i][j]+m.P[i][j];
    return r;
}
//---------------------------------------------------------------------------
 
template <class T>
TMatrix<T> TMatrix<T>::operator-(const TMatrix<T>& m)
{
    if (dimR!=m.dimR || dimC!=m.dimC)
        throw TMatrixException(TMatrixException::NOT_SAME_DIM);
 
    TMatrix<T> r(dimR,dimC);
    for (int i=0; i<dimR; i++)
        for (int j=0; j<dimC; j++)
            r.P[i][j]=P[i][j]-m.P[i][j];
    return r;
}
//---------------------------------------------------------------------------
 
template <class T>
TMatrix<T> TMatrix<T>::operator*(const TMatrix<T>& m)
{
    if (dimC!=m.dimR)
        throw TMatrixException(TMatrixException::NOT_MULTIPLICABLE);
 
    TMatrix<T> r(dimR,m.dimC);
    r=this->mul(m);
    return r;
}
//---------------------------------------------------------------------------
 
template <class T>
TMatrix<T> TMatrix<T>::operator*(const T f)
{
    for (int i=0; i<dimR; i++)
        for (int j=0; j<dimC; j++)
            P[i][j]*=f;
    return *this;
}
//---------------------------------------------------------------------------
template <class T>
TMatrix<T> TMatrix<T>::operator/(const T f)
{
    TMatrix<T> r(dimR,dimC);
    for (int i=0; i<dimR; i++)
        for (int j=0; j<dimC; j++)
            r.P[i][j]=P[i][j]/f;
    return r;
}
//---------------------------------------------------------------------------
template <class T>
TMatrix<T> TMatrix<T>::operator*=(const TMatrix<T>& m)
{
    if (dimR!=m.dimR || dimC!=m.dimC)
        throw TMatrixException(TMatrixException::NOT_SAME_DIM);
 
    TMatrix<T> r(dimR,dimC);
    for (int i=0; i<dimR; i++)
        for (int j=0; j<dimC; j++)
            r.P[i][j]=P[i][j]*m.P[i][j];
    return r;
}
//---------------------------------------------------------------------------
 
template <class T>
TMatrix<T> TMatrix<T>::operator*=(const T f)
{
    *this=*this*f;
    return *this;
}
//---------------------------------------------------------------------------
 
template <class T>
TMatrix<T> TMatrix<T>::mul(const TMatrix<T>& m)
{
    TMatrix<T> r(dimR,m.dimC);
    T e=0;
    for (int i=0; i<dimR; i++)
        for (int j=0; j<m.dimC; j++)
        {
            for (int k=0; k<dimC; k++)
                e+=P[i][k]*m.P[k][j];
            r.P[i][j]=e;
            e=0;
        }
    return r;
}
//---------------------------------------------------------------------------
 
template <class T>
void TMatrix<T>::reverse()
{
    if (dimR!=dimC)
        throw TMatrixException(TMatrixException::NOT_SQUARE);
 
    TMatrix<T> r(dimR,dimC);
    r=cofactor();
    r.transpose();
    for (int i=0; i<dimR; i++)
        for (int j=0; j<dimR; j++)
            r.P[i][j]=r.P[i][j]*pow(-1,i+j+2);
    r*=T(1)/determinant();
    *this=r;
}
//---------------------------------------------------------------------------
 
template <class T>
void TMatrix<T>::TC()
{
    if (dimR!=dimC)
        throw TMatrixException(TMatrixException::NOT_SQUARE);
 
    TMatrix<T> r(dimR,dimC);
    r=cofactor();
    r.transpose();
    for (int i=0; i<dimR; i++)
        for (int j=0; j<dimR; j++)
            r.P[i][j]=r.P[i][j]*pow(-1,i+j+2);
    *this=r;
}
//---------------------------------------------------------------------------
template <class T>
void TMatrix<T>::transpose()
{
    TMatrix<T> m(dimC,dimR);
    for (int i=0; i<dimC; i++)
      for (int j=0; j<dimR; j++)
    { m.P[i][j]=P[j][i];}
    *this=m;
}
//---------------------------------------------------------------------------
template <class T>
TMatrix<T> TMatrix<T>::transpose1()
{
    TMatrix<T> m(dimC,dimR);
    for (int i=0; i<dimC; i++)
        for (int j=0; j<dimR; j++)
        { m.P[i][j]=P[j][i];}
    return m;
}
//---------------------------------------------------------------------------
 
template <class T>
T TMatrix<T>::det3x3()
{
    return P[0][0] * ( (P[1][1]*P[2][2])-(P[1][2]*P[2][1]) )
           - P[1][0] * ( (P[0][1]*P[2][2])-(P[0][2]*P[2][1]) )
           + P[2][0] * ( (P[0][1]*P[1][2])-(P[0][2]*P[1][1]) );
}
//---------------------------------------------------------------------------
 
template <class T>
T TMatrix<T>::det2x2()
{
    return P[0][0]*P[1][1] - P[0][1]*P[1][0];
}
//---------------------------------------------------------------------------
 
template <class T>
T TMatrix<T>::determinant()
{
    if (dimR!=dimC)
        throw TMatrixException(TMatrixException::NOT_SQUARE);
 
    if (dimR==2) return det2x2();
    if (dimR==3) return det3x3();
    T d=0;
    for (int i=0; i<dimR; i++)
        d+=P[i][0] * cofactor(i,0);
    return d;
}
//---------------------------------------------------------------------------
 
template <class T>
T TMatrix<T>::cofactor(int ir, int ic)
{
    if (dimR!=dimC)
        throw TMatrixException(TMatrixException::NOT_SQUARE);
 
    return minor(ir,ic) * pow(-1, ir+ic+2);
}
//---------------------------------------------------------------------------
   
template <class T>
TMatrix<T> TMatrix<T>::cofactor()
{
    if (dimR!=dimC)
        throw TMatrixException(TMatrixException::NOT_SQUARE);
 
    TMatrix<T> r(dimR);
    for (int i=0; i<dimR; i++)
        for (int j=0; j<dimR; j++)
            r.P[i][j]=cofactor(i,j);
    return r;
}
//---------------------------------------------------------------------------
 
template <class T>
istream& operator>> (istream& in, TMatrix<T> &m)
{
    int rw,cl;
    cout << "DIM ROW: ";
    in >> rw;
    cout << "DIM COL: ";
    in >> cl;
     
    if (rw<1 && cl<1)
        throw TMatrixException(TMatrixException::DIM_TOO_SMALL);
 
    m.resize(rw,cl);
    T *data=new T[rw*cl];
    T element;
    for (int i=0; i<rw; i++)
        for (int j=0; j<cl; j++)
        {
            cout << i <<','<<j<<':';
            in >> element;
            data[cl*i+j]=element;
        }
     for (int x=0; x<rw; x++)
        for (int y=0; y<cl; y++)
            m.P[x][y]=data[cl*x+y];
    delete [] data;
    return in;
}

 int nbLigne = 0;
 int nbline = 0;
 
main()
{
    int fonction();

    int nbligne=10;
    int nbcolonne=100000;

    double **tab = new double* [nbligne];

    string *tab1=new string [10];

    double *data0 =new double [100000];
    double *data1 =new double [100000];
    double *data2 =new double [100000];
    double *data3 =new double [100000];
    double *data4 =new double [100000];
    double *data5 =new double [100000];
    double *data6 =new double [100000];
    double *data7 =new double [100000];
    double *data8 =new double [100000];
    double *data9 =new double [100000];
    double *data11 =new double [100000];

    int *nb= new int [10];

    tab1[0]="image_aller_0.txt";
    tab1[1]="image_aller_1.txt";
    tab1[2]="image_aller_2.txt";
    tab1[3]="image_aller_3.txt";
    tab1[4]="image_aller_4.txt";
    tab1[5]="image_retour_0.txt";
    tab1[6]="image_retour_1.txt";
    tab1[7]="image_retour_2.txt";
    tab1[8]="image_retour_3.txt";
    tab1[9]="image_retour_4.txt";
    
    
for(int i=0;i<nbligne;i++)
{    
    tab [i] =new double [nbcolonne];
    ifstream fichier( tab1[i].c_str() );
    
    int nbElement = 0;
    
if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
    {
        
       string ligne; // variable contenant chaque ligne lue
  while ( getline( fichier, ligne,';') )
         {
        stringstream s;
        s << ligne;
        double n;
        s >> n;
        tab[i][nbElement]=n;
        nbElement++;
        }

         nbElement=nbElement-1;
         nb[i]=nbElement;
         }
}






    fonction();
    /*for (int j=0;j<nb[0];j++)
    {data11[j]=tab[9][j];
    cout<<"data11["<<j<<"]="<<data11[j]<<endl;}*/
//calcul des images d'aller
for(int i=24*(nb[0]/nbLigne), int j=0;i<nb[0];i++,j++)
    {
        data0[j]=tab[0][i];
    }

for(int i=18*(nb[0]/nbLigne), int j=0;i<nb[0]-6*(nb[0]/nbLigne);i++,j++)
    {
        data1[j]=tab[1][i];
    }
    
for(int i=12*(nb[0]/nbLigne), int j=0;i<nb[0]-12*(nb[0]/nbLigne);i++,j++)
    {
        data2[j]=tab[2][i];
    }

for(int i=6*(nb[0]/nbLigne), int j=0;i<nb[0]-18*(nb[0]/nbLigne);i++,j++)
    {
        data3[j]=tab[3][i];
    }

for(int i=0, int j=0;i<nb[0]-24*(nb[0]/nbLigne);i++,j++)
    {
        data4[j]=tab[4][i];
    }


//calcul des images d'aller
for(int i=24*(nb[0]/nbLigne), int j=0;i<nb[0];i++,j++)
    {
        data5[j]=tab[5][i];
    }

for(int i=18*(nb[0]/nbLigne), int j=0;i<nb[0]-6*(nb[0]/nbLigne);i++,j++)
    {
        data6[j]=tab[6][i];
    }
    
for(int i=12*(nb[0]/nbLigne), int j=0;i<nb[0]-12*(nb[0]/nbLigne);i++,j++)
    {
        data7[j]=tab[7][i];
    }

for(int i=6*(nb[0]/nbLigne), int j=0;i<nb[0]-18*(nb[0]/nbLigne);i++,j++)
    {
        data8[j]=tab[8][i];
    }

for(int i=0, int j=0;i<nb[0]-24*(nb[0]/nbLigne);i++,j++)
    {
        data9[j]=tab[9][i];
    //cout<<"data4["<<j<<"]="<<data4[j]<<endl;
    }

for (i=0; i<nbligne; i++)
    delete [] tab[i];


double BaseDeb0[]={0.388604604904631,0.406601659145942,0.378690501334562,0.287194079690545,0.151164359264193,
            0.071803015062962,0.164350538222389,0.296797179332217,0.38334997634639,0.409525836418349};

double BaseDeb1[]={-0.323649350549774,-0.415607636283671,-0.411387612488962,-0.333930284418496,-0.222511513692899,
        0.198907038265443,0.295558748176889,0.345093175771535,0.311521060527922,0.221826868643937};

double BaseDeb2[]={-0.670820408061754,-0.207550671690524,0.060710285463047,0.175467860721236,0.342103337312563,
        0.314378516305185,0.373036501457469,0.269042406605554,0.205073746200055,-0.054627425664033};

double  BaseDeb3[]={-0.12178458628382,-0.324322138954493,-0.294336964125752,0.080655254257347,0.20264198781655,
        -0.110319603693933,-0.268477620124972,-0.27861221882445,0.174640119162963,0.743912483995695};

double BaseDeb4[]={0.357419420677741,0.116967766567915,-0.322458372355591,-0.252697005439953,0.593422649796283,
        0.386988742706195,0.289990311108721,-0.190522196734433,-0.261592915955397,-0.000225632241136};

double BaseDeb5[]={0.387835479914384,-0.472426972046061,-0.263024747425621,0.300572963862179,0.281961266092815,
        -0.292920124870451,-0.10040664044921,0.412249012263593,0.147553636167751,-0.315852972131101};

double BaseDeb6[]={-0.232892894649326,0.274303457352688,0.069140668314326,-0.498922811704185,0.399528412251487,
        -0.568973419522421,-0.105702986671391,0.328946616074605,-0.091031579887583,0.076122653515312};

double BaseDeb7[]={-0.043700740700225,0.234278105335433,-0.145635777001948,-0.142465914460769,0.142713443772678,
        -0.026476339204742,-0.156393666411569,-0.386796655515969,0.755421457350252,-0.368642597766829};

double BaseDeb8[]={0.185010748856839,-0.531092263105224,0.654417098449992,-0.426670672208321,0.131653353167031,
        0.143286525831791,-0.091305299504505,-0.116947513280103,0.115389066867978,-0.014518277895676};

double BaseDeb9[]={0.059496218389855,-0.140590273388129,0.066195283690816,0.057676418204699,-0.061972012911959,
        -0.530559523333651,0.73961121061749,-0.366254928633776,0.042273129917483,0.026416262209347};

TMatrix <double>  A0(nbLigne-24,nb[0]/nbLigne),sig1(nbLigne-24,nb[0]/nbLigne),c(nbLigne-24,1),
                  A1(nbLigne-24,nb[0]/nbLigne),sig2(nbLigne-24,nb[0]/nbLigne),
                  A2(nbLigne-24,nb[0]/nbLigne),sig3(nbLigne-24,nb[0]/nbLigne),
                  A3(nbLigne-24,nb[0]/nbLigne),sig4(nbLigne-24,nb[0]/nbLigne),
                  A4(nbLigne-24,nb[0]/nbLigne),sig5(nbLigne-24,nb[0]/nbLigne),
                  A5(nbLigne-24,nb[0]/nbLigne),sig6(nbLigne-24,nb[0]/nbLigne),
                  A6(nbLigne-24,nb[0]/nbLigne),sig7(nbLigne-24,nb[0]/nbLigne),
                  A7(nbLigne-24,nb[0]/nbLigne),sig8(nbLigne-24,nb[0]/nbLigne),
                  A8(nbLigne-24,nb[0]/nbLigne),sig9(nbLigne-24,nb[0]/nbLigne),
                  A9(nbLigne-24,nb[0]/nbLigne),sig10(nbLigne-24,nb[0]/nbLigne),
                  B[10],NewBase[10],Somme[10],ImgTot(nbLigne-24,10),NewImg1(nbLigne-24,nb[0]/nbLigne),
                  NewImg2(nbLigne-24,nb[0]/nbLigne),NewImg3(nbLigne-24,nb[0]/nbLigne),
                  NewImg4(nbLigne-24,nb[0]/nbLigne),NewImg5(nbLigne-24,nb[0]/nbLigne),
                  NewImg6(nbLigne-24,nb[0]/nbLigne),NewImg7(nbLigne-24,nb[0]/nbLigne),
                  NewImg8(nbLigne-24,nb[0]/nbLigne),NewImg9(nbLigne-24,nb[0]/nbLigne),
                  NewImg10(nbLigne-24,nb[0]/nbLigne),D(6,1);
//les colonnes de BaseDeb
B[0].in(BaseDeb0);
B[1].in(BaseDeb1);
B[2].in(BaseDeb2);
B[3].in(BaseDeb3);
B[4].in(BaseDeb4);
B[5].in(BaseDeb5);
B[6].in(BaseDeb6);
B[7].in(BaseDeb7);
B[8].in(BaseDeb8);
B[9].in(BaseDeb9);

//la base surlaquelle on va fiar el'orthogonolistaion des images brutes
NewBase[0].in(BaseDeb0);
Somme[0].zeros();
Somme[1].zeros();

for(int i =1;i<10;i++)
{
for(int j=0;j<i;j++)
Somme[i]=Somme[i]+((NewBase[j]*(((B[i].transpose1())*NewBase[j])))/(pow(NewBase[j].norm(),2)));
//cout<<"Somme["<<i<<"]="<<endl;
//cout<<Somme[i]<<endl;

NewBase[i]=B[i]-Somme[i];
//cout<<"NewBase["<<i<<"]="<<endl;
//cout<<NewBase[i]<<endl;
}

for(int i =1;i<10;i++)
{
    (B[i].transpose1()).destroy();
     B[i].destroy();
     Somme[i].destroy();
}

//remplissage des matrices
A0.in(data0);    
A1.in(data1);    
A2.in(data2);
A3.in(data3);
A4.in(data4);
A5.in(data5);
A6.in(data6);
A7.in(data7);
A8.in(data8);
A9.in(data9);

delete [] data0;
delete [] data1;
delete [] data2;
delete [] data3;
delete [] data4;
delete [] data5;
delete [] data6;
delete [] data7;
delete [] data8;
delete [] data9;

//moyenne des matrices
/*A1=A0.mean();        
A3=A2.mean();*/


//Images aller et retour
sig1=A0-c.ones()*A0.mean();
//cout<<"sig1="<<sig1<<endl;

sig2=A1-c.ones()*A1.mean();
//cout<<"sig2="<<sig2<<endl;

sig3=A2-c.ones()*A2.mean();
//cout<<"sig3="<<sig3<<endl;

sig4=A3-c.ones()*A3.mean();
//cout<<"sig4="<<sig4<<endl;

sig5=A4-c.ones()*A4.mean();
//cout<<"sig5="<<sig5<<endl;

sig6=A5-c.ones()*A5.mean();
//cout<<"sig6="<<sig6<<endl;

sig7=A6-c.ones()*A6.mean();
//cout<<"sig7="<<sig7<<endl;

sig8=A7-c.ones()*A7.mean();
//cout<<"sig8="<<sig8<<endl;

sig9=A8-c.ones()*A8.mean();
//cout<<"sig9="<<sig9<<endl;

sig10=A9-c.ones()*A9.mean();
cout<<"sig10="<<sig10<<endl;
//Libérer la memoire
A0.destroy();
A1.destroy();
A2.destroy();
A3.destroy();
A4.destroy();
A5.destroy();
A6.destroy();
A7.destroy();
A8.destroy();
A9.destroy();

/*cout<<"sig10="<<endl;
cout<<sig10<<endl;*/

for(int i =0;i<nb[0]/nbLigne;i++)
{
ImgTot.fill(sig1.colonne(i),0);
ImgTot.fill(sig2.colonne(i),1);
ImgTot.fill(sig3.colonne(i),2);
ImgTot.fill(sig4.colonne(i),3);
ImgTot.fill(sig5.colonne(i),4);
ImgTot.fill(sig6.colonne(i),5);
ImgTot.fill(sig7.colonne(i),6);
ImgTot.fill(sig8.colonne(i),7);
ImgTot.fill(sig9.colonne(i),8);
ImgTot.fill(sig10.colonne(i),9);

/*for(int i =0;i<nb[0]/nbLigne;i++)
cout<<"IMgTot["<<i<<"]="<<endl;*/
//cout<<ImgTot<<endl;
NewImg1.fill(ImgTot*NewBase[0],i);
//NewImg2.fill(ImgTot*NewBase[1],i);
/*NewImg3.fill(ImgTot*NewBase[2],i);
NewImg4.fill(ImgTot*NewBase[3],i);
NewImg5.fill(ImgTot*NewBase[4],i);
NewImg6.fill(ImgTot*NewBase[5],i);
NewImg7.fill(ImgTot*NewBase[6],i);
NewImg8.fill(ImgTot*NewBase[7],i);
NewImg9.fill(ImgTot*NewBase[8],i);
NewImg10.fill(ImgTot*NewBase[9],i);*/
}
//cout<<"NewImg10="<<endl;
//cout<<NewImg2<<endl;
cout<<"IMgTot[]="<<endl;
cout<<ImgTot<<endl;
for (int j=0;j<nbligne;j++)
cout <<"nb["<<j<<"]="<<nb[j]<<endl;
cout <<"nbLigne="<<nbLigne<<endl;
for(int i =1;i<10;i++)
NewBase[i].destroy();
ImgTot.destroy();
//NewImg2.destroy();
sig1.destroy();
sig2.destroy();
sig3.destroy();
sig4.destroy();
sig5.destroy();
sig6.destroy();
sig7.destroy();
sig8.destroy();
sig9.destroy();
sig10.destroy();
}

int fonction ()
{

ifstream fichier( "image_aller_0.txt" );
 
    
    if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
    {
        string lign;// variable contenant chaque ligne lue
      while ( getline( fichier, lign,'\n') )
        {
            nbLigne++;
        }
      cout<<"le nombre des lignes ="<<nbLigne<<endl;
    }
    return nbLigne;
}

[/code]

les fichiers "image_aller_0"jusqu'au" image 5" et image -retour.txt sont des fichiers texte composé des chiffres qui seront aprés les membres des matrices.mais pour des matrices de grande taille, le programme sera tres gourmand en mémoire et il prend beaucouq de temps pour finire les calculs.
est ce vous avez des idées pour mieux gerer la mémoire et pour mininmiser le temps necessaire pour le calculs??
Merci
mercredi 26 juillet 2006 à 10:10:52 | Re : Gérer mieux la memoire

turnerom


Salut,



| est ce vous avez des idées pour mieux gerer la mémoire et pour mininmiser le temps necessaire pour le calculs?

--> Utilise nt2 qui fait ca de manière très optimisé !

TuRn3r
mercredi 26 juillet 2006 à 11:10:06 | nt2 ne fonctionne pas avec VS2003

Stiko

je travaille sous VS2003, pour l instant on peut pas faire un link entre NT2 et VS2003.


Cette discussion est classée dans : int, for, nbligne, tmatrix, dimr


Répondre à ce message

Sujets en rapport avec ce message

Gérer miex la memmoire pour le calcul matriciel [ par Stiko ] salut,j'utilise une classe faite en C++ pour les calculs matriciels de grand taille la classe est le suivant:c'est le fichier .h[quote]/* Matrix.h*/#i Allocation dynamique de tableu 2D [ par potitmarron ] Bonjour, J'aimerais savoir comment en C je peux créer un tableau et au fur et à mesure de mes besoins, ajouter des lignes ? Ici j'ai un tableau de x l Besoin d'aide c++ [ par sevio14 ] Quelqu'un peut-il m'aider à faire le programme de l'algorithme d'uzawa? Voici ce que j'ai commencé à définir: #include #include #include #includ Violation d'accès lors de l'écriture... [ par kalala9 ] bonjour, j'ai créé une classe point avec comme donnée membre ses coordonnées XYZ, et sa leur RGB. J'ai ensuite créé dans une autre classe un parallélé Probleme : Sudoku en C [ par seth59222 ] Bonsoir, voila je suis actuellement en première année d'info, donc assez novice et je viens de créer ce petit bout de programme en C qui consiste a ré probleme d'allocation d'une matrice [ par emomar ] salut à tous voila j'ai un probleme avec la fonction remplir voila le code si quelqu'un peut m'aider merci code : [code=cpp]#include #include int n appel de fonction [ par ibnjabal ] Bonjour j'essaie de faire une fonction qui calcule la somme de deux matrice et ça fonctionne bien mais seulement c'est quand j'essaie de le faire dans Programme en c++ [ par noussa44 ] Bonjour à tous et merci d'avance pour vos réponses, J'ai fait un petit code en c++ pou calculer la distance entre des points avec la formule :d² = (x' fonction en c [ par badsha ] j'ai un code qui inverse une matrice et je veux l'appliquer sur plusieurs matrices je n'arrive pas à mettre à l'entrée de la fonction des matrices, je problème d'intégrer mon algorithme [ par baster200x ] Slt tous le mande! je vous adresse pour m'aider à trouver une solution à mon problème! j'ai un outil Open source Nommé [url=http://home.dei.polimi


Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 3,900 sec (4)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales