Borderbasix

resolve.hpp
Go to the documentation of this file.
1 //#include<g2c.h>
2 //struct doublecomplex
3 //{
4 // double r;
5 // double i;
6 //};
7 typedef double doublereal;
8 typedef long int logical;
9 
10 #include "linalg/clapack.h"
11 #include<complex>
12 #include"borderbasix/linalg/Lapack.H"
13 #include"borderbasix/linalg/Eigen.H"
14 #include<stdlib.h>
15 //extern "C" {
16  //bon je sais la decalration ci apres est un peu crade mais bon
17  //entre f2c et g2c tout n'est pas tjrs compatible alors comme ca
18  //meme avec le -Wall on cloue le bec a gcc.. :-0
19 // void ztrsen_(...);
20 // void zgebal_(...);
21 // void zgees_(...);
22 // void dgees_(...);
23  // void dgees_(char *JOBVS,char *SORT,bool (*SELECT)(double,double),int *N,double *A,int *LDA,int *SDIM,double *WR,double *WI,double *VS, int *LDVS,double *WORK,int *LWORK,double *BWORK,int *info);
24  // void zgees_(char *JOBVS,char *SORT,logical (*SELECT)(doublecomplex *), tla_int *N,doublecomplex *A,tla_int *LDA,tla_int *SDIM,doublecomplex *W,doublecomplex *VS,tla_int *LDVS,doublecomplex *WORK,tla_int *LWORK,doublereal * RWORK,tla_int *BWORK,tla_int *info);
25 //}
26 
27 //wrapper au dessus de lapack pour calculer
28 //une decomposition d schur
29 //de la matrice qui doit etre un lapack<double>
30 template<typename Mat>
31 Mat wraplapack_dgees(const Mat &M)
32 {
33  typedef typename Mat::rep_t rept;
34  rept m=M.rep,res;
35  bool (*SELECT)(double,double)=(bool (*)(double,double))1;
36  double *bwork=(double*)malloc(m.nbcol()*sizeof(void (*)(void)));
37  double *wr=(double*)malloc(m.nbrow()*sizeof(double));
38  double *wi=(double*)malloc(m.nbrow()*sizeof(double));
39  Mat Mres(m.nbrow(),m.nbrow());
40  double *work=(double*)malloc(10*sizeof(double)*m.nbrow());
41  int info,n,i,l,lres,lwork,sdim;
42  double* tab =(double*)malloc(m.nbcol()*m.nbrow()*sizeof(double));
43  double* tabres =(double*)malloc(m.nbcol_*m.nbrow_*sizeof(double));
44  n=m.nbrow();l=m.nbrow();lres=m.nbrow();lwork=10*m.nbrow();
45  for(i=0;i<m.nbcol_*m.nbrow_;i++) tab[i]=m.tab_[i];
46  dgees_("V","N",SELECT,&n,tab,&l,&sdim,wr,wi,tabres,&lres,work,
47  &lwork,bwork,&info);
48  (Mres.rep).reserve(m.nbcol_,m.nbcol_);
49  for(i=0;i<m.nbcol_*m.nbrow_;i++) (Mres.rep).tab_[i]=tabres[i];
50  free(wr);
51  free(wi);
52  free(work);
53  free(tab);
54  free(tabres);
55  return Mres;
56 }
57 //fonction qui sert a rien.. :-)
58 
59 extern "C"{
60 long int select_true(doublecomplex *toto)
61 {
62  static long int rep=1;
63  return rep;
64 }
65 }
66 
67 //la meme que wraplapack_dgees
68 //sauf qu'elle marche sur le matrice du type
69 //lapack<complex<double> >
70 //Si PbS sous linux verifie la fonction dznrm2!!!
71 //Elle est pas compliee de maniere adequate dans la distrib semir
72 template<typename Mat>
73 Mat wraplapack_zgees(Mat M)
74 {
75  typedef typename Mat::rep_t rept;
76  float toto;
77  rept m=M.rep;
78  logical (*SELECT)(doublecomplex *)=select_true;
79  doublecomplex *w=(doublecomplex *)malloc(m.nbrow_*sizeof(doublecomplex));
80  double *rwork=(double*)malloc(m.nbrow_*sizeof(double));
81  logical *bwork=(logical*)malloc(m.nbrow_*sizeof(logical));
82  Mat Mres(m.nbrow_,m.nbrow_);
83  doublecomplex* work=
84  (doublecomplex*)malloc(10*sizeof(doublecomplex)*m.nbrow_);
85  int info,n,l,lres,lwork,sdim;
86  unsigned int i;
87  doublecomplex* tab =
88  (doublecomplex*)calloc(m.nbcol_*m.nbrow_,sizeof(doublecomplex));
89  doublecomplex* tabres =
90  (doublecomplex*)calloc(m.nbcol_*m.nbrow_,sizeof(doublecomplex));
91  char *JOBS="V",*SORT="N";
92 
93  n=m.nbrow_;l=m.nbrow_;lres=m.nbrow_;lwork=5*m.nbrow_;
94 
95  for(i=0;i<m.nbcol_*m.nbrow_;i++) {
96  tab[i].r=m.tab_[i].real();
97  tab[i].i=m.tab_[i].imag();
98  toto=tab[i].r;
99  }
100  zgees_(JOBS,SORT,SELECT,&n,tab,&l,&sdim,
101  w,tabres,&lres,work,&lwork,rwork,bwork,&info);
102  (Mres.rep).reserve(m.nbcol_,m.nbcol_);//matrice carree exclusivement!!
103  for(i=0;i<m.nbcol_*m.nbrow_;i++)
104  {
105  (Mres.rep).tab_[i]=complex<double>(tab[i].r,tab[i].i);
106  toto=*(((float*)tabres)+i+2);
107  }
108  cout<<"info "<<info<<endl;
109  //cout<<Mres<<endl<<endl;
110  for(i=0;i<m.nbcol_*m.nbrow_;i++)
111  {
112  (Mres.rep).tab_[i]=complex<double>(tabres[i].r,tabres[i].i);
113  }
114  free(w);
115  free(rwork);
116  free(work);
117  free(bwork);
118  free(tab);
119  free(tabres);
120  return Mres;
121 }
122 
123 //debut de l'implementation de l'algo de Corless dans
124 //ISSAC 97
125 
126 //trigo simultanee sur des doubles
127 template<typename Mat>
128 void trigsim(list<Mat> &lmat)
129 {
130  //on supose que la list n'est pas vide!!!
131  Mat Shurvect=wraplapack_dgees(lmat.front());
132  Mat invShurvect;
133  Shurvect.transpose();//on est reel jusque la
134  invShurvect=Shurvect;
135  Shurvect.transpose();
136  typename list<Mat>::iterator iter;
137  for(iter=lmat.begin();iter!=lmat.end();iter++)
138  {
139  Mat tmp=invShurvect*(*iter)*Shurvect;
140  *iter=tmp;
141  }
142 }
143 //un wrap de lapack rien d'important
144 template<typename Mat>
145 void wraplapack_ztrsen(Mat &M,logical * select,doublereal *res)
146 {
147  char *JOBS="E",*COMPQ="N";
148  int N=M.nbcol(),LDT=M.nbcol();
150  malloc(M.nbcol()*M.nbcol()*sizeof(doublecomplex));
151  doublecomplex *Q=NULL;
152  doublecomplex *W=(doublecomplex*)malloc(M.nbcol()*sizeof(doublecomplex));
153  int m=1,LDQ=1;
154  doublereal S=1,SEP=2;
155  doublecomplex *WORK=(doublecomplex*)malloc(2*N*N*sizeof(doublecomplex));
156  int LWORK=2*N*N,info;
157  //maintenant on initialise le tableau T
158  for(int i=0;i<N*N;i++)
159  {
160  T[i].r=(M.rep).tab_[i].real();
161  T[i].i=(M.rep).tab_[i].imag();
162  }
163  ztrsen_(JOBS,COMPQ,select,&N,T,&LDT,Q,&LDQ,W,&m,&S,&SEP,WORK,&LWORK,&info);
164  *res=S;
165  free(WORK);
166  free(W);
167  free(T);
168 }
169 //evalue le conditionnement non clsuetrise de
170 //chacunes des valeurs propres de la matrice
171 
172 template<typename Mat>
173 doublereal cond_number(Mat &Combilin,int i)
174 {
175  doublereal res;
176  logical *select;
177  select=(logical*)calloc(Combilin.nbcol(),sizeof(logical));
178  select[i]=1;
179  wraplapack_ztrsen(Combilin,select,&res);
180  return res;
181 }
182 //
183 //creation des clusters
184 //utilisation de l'heuritique de Stetter!!
185 //
186 
187 template<typename Mat,typename typcond>
188 int getcluster(Mat &M,typcond *cond)
189 {
190  double EPSILON=1e-16;
191  doublecomplex *truncnum=(doublecomplex*)
192  malloc(M.nbcol()*sizeof(doublecomplex));
193  int *digits=(int*)malloc(M.nbcol()*sizeof(int));
194  double normM=0;
195  char tampon1[60],tampon2[60],*rien;
196  int comp=0;
197  for(int i=0;i<M.nbcol();i++)
198  normM=max(sqrt((M(i,i)*conj(M(i,i))).real()),normM);
199  for(int i=0;i<M.nbcol();i++)
200  {
201  // cout<<"cond[i]"<<cond[i]<<endl;
202  double lambda=1.0/cond[i]*EPSILON*normM;
203  double nbdigits=(1/lambda);
204  int k;
205  for(k=1;nbdigits>1;k++,nbdigits/=10);//
206  //cout<<"nbdigits "<<nbdigits<<endl;;
207  nbdigits=k;
208  digits[i]=k;
209  //rajout des tests de taille apres
210  snprintf(tampon1,60,"%%.%dg\0",(k>16)?16:k);
211  //cout<<tampon1<<endl;
212  snprintf(tampon2,60,tampon1,M(i,i).real());
213  //cout<<tampon2<<endl;
214  truncnum[i].r=strtod(tampon2,&rien);
215  snprintf(tampon2,60,tampon1,M(i,i).imag());
216  //cout<<tampon2<<endl;
217  truncnum[i].i=strtod(tampon2,&rien);
218  }
219  for(int i=0;i<M.nbcol();i++)
220  {
221  //if(cond[i]>=0)
222  {
223  // cout<<"toto"<<endl;
224  cond[i]=-i;
225  for(int j=0;j<M.nbcol();j++)
226  {
227  double val=1.0;
228  //cout<<"digitis_i "<<digits[i]<<" "<<digits[j]<<endl;
229  for(int k=0;k<min(digits[i],digits[j]);k++,val*=10);
230  //cout<<"val "<<val<<endl;
231  //cout<<"la diference "<<abs(truncnum[j].r-truncnum[i].r)<<endl;
232  //cout<<" en complex "<<abs(truncnum[j].i-truncnum[i].i)<<endl;
233  // cout<<"prod "<<abs(truncnum[j].r-truncnum[i].r)*val<<endl;
234  if ((abs(truncnum[j].r-truncnum[i].r)*val<1.0)
235  &&(abs(truncnum[j].i-truncnum[i].i)*val<1.0))
236  {
237  typcond stock=cond[j];
238  for(int k=0;k<M.nbcol();k++)
239  if(cond[k]==stock) cond[k]=-i;
240  //on merge les cluster
241  //truncnum[i].r=-1;
242  // cout<<"clustering ok plus d'un"<<endl;
243  }
244  }
245  }
246  }
247  //cout<<"cond"<<endl;
248  //for(int k=0;k<M.nbcol();k++)
249  // cout<<cond[k]<<endl;
250  free(truncnum);
251  return M.nbcol();//cluster numerotes de -1 a ...
252 }
253 
254 //
255 //appliquation des clusters crees avec la fonction d'avant
256 //
257 
258 template<typename Mat>
259 void docluster(Mat &M,Mat &Shurvect,doublereal * cond,int i)
260 {
261  //0n recherche tous les -i dans le tableau cond et apres on
262  //fait un cluster avec eux......
263  logical *select=(logical*)malloc(M.nbcol()*sizeof(logical));
264  int N=M.nbcol(),LDT=M.nbcol(),LDQ=M.nbcol();
265  int m,info,LWORK=N*N*2;
266  int flag=0;
267  double *stockcond=(double*)malloc(N*sizeof(double));
268  double *WORK=(double*)malloc(2*sizeof(double)*LWORK);
269  double S,SEP;
270  doublecomplex *stockW=(doublecomplex*)malloc(N*sizeof(doublecomplex));
272  doublecomplex *tmpM=(doublecomplex*)malloc(N*N*sizeof(doublecomplex));
273  doublecomplex *tmpQ=(doublecomplex*)malloc(N*N*sizeof(doublecomplex));
274  for(int k=0;k<N*N;k++)
275  {
276  tmpM[k].r=(M.rep).tab_[k].real();
277  tmpM[k].i=(M.rep).tab_[k].imag();
278  }
279  for(int k=0;k<N*N;k++)
280  {
281  tmpQ[k].r=(Shurvect.rep).tab_[k].real();
282  tmpQ[k].i=(Shurvect.rep).tab_[k].imag();
283  }
284 
285  for(int k=0;k<M.nbcol();k++)
286  {
287  stockW[k].r=M(k,k).real();
288  stockW[k].i=M(k,k).imag();
289  }
290  //cout<<"icisel "<<i<<endl;
291  for(int k=1;k<=M.nbcol();k++)
292  {
293  flag+=(select[k]=(cond[k]==-i)?1l:0l);
294  // cout<<"select "<<k<<" "<<select[k]<<endl;
295  }
296  //on fait la selection
297  if (flag)
298  {
299  // cout<<"avant reorde"<<M<<endl;
300  ztrsen_("B","V",select,&N,tmpM,&LDT,tmpQ,
301  &LDQ,W,&m,&S,&SEP,WORK,&LWORK,&info);
302  for(int k=0;k<N*N;k++)
303  (M.rep).tab_[k]=complex<double>(tmpM[k].r,tmpM[k].i);
304  for(int k=0;k<N*N;k++)
305  (Shurvect.rep).tab_[k]=complex<double>(tmpQ[k].r,tmpQ[k].i);
306  //cout<<"apres reord"<<M<<endl;
307  //donc maintenant on a reordonne les vp du cluster i
308  //il faut maintenant reconnaitre qui est qui pour
309  //remettre a jour cond
310  for(int k=0;k<N;k++)
311  {
312  //on prends pour valeur celle qui minimise la difference
313  double mindiff=abs(
314  (W[0].r-stockW[k].r)*(W[0].r-stockW[k].r)
315  +(W[0].i-stockW[k].i)*(W[0].i-stockW[k].i)
316  );
317  int stockpos=0;
318  for(int l=0;l<N;l++)
319  if(abs((W[l].r-stockW[k].r)*(W[l].r-stockW[k].r)+
320  (W[l].i-stockW[k].i)*(W[l].i-stockW[k].i)<mindiff)
321  )
322  {
323  mindiff=abs((W[l].r-stockW[k].r)*(W[l].r-stockW[k].r)
324  +(W[l].i-stockW[k].i)*(W[l].i-stockW[k].i)
325  );
326  stockpos=l;
327  }
328  stockcond[stockpos]=cond[k];
329  }
330  for(int k=0;k<N;k++)
331  cond[k]=stockcond[k];
332  }
333  free(select);
334  free(stockcond);
335  free(WORK);
336  free(stockW);
337  free(W);
338 
339 }
340 
341 //
342 //fonction de reordenement en enbtier
343 //
344 
345 template<typename Mat>
346 void reorder(Mat &Combilin,Mat &Shurvect,Mat &invShurvect)
347 {
348  doublereal *cond;
349  int i,nbcluster;
350  cond=(doublereal*)malloc(sizeof(doublereal)*Combilin.nbcol());
351  for(i=0;i<Combilin.nbcol();i++)
352  {
353  cond[i]=cond_number(Combilin,i);
354  //cout<<"coond "<<i<<" "<<cond[i]<<endl;
355  }
356  //cout<<"nbcluster"<<endl;
357  nbcluster=getcluster(Combilin,cond);
358  //cout<<"docluster"<<endl;
359  for(i=0;i<nbcluster;i++)
360  docluster(Combilin,Shurvect,cond,i);
361  //Shurvect.transpose();
362  for(i=0;i<invShurvect.nbrow();i++)
363  for(int j=0;j<invShurvect.nbcol();j++)
364  invShurvect(i,j)=conj(Shurvect(j,i));
365  //Shurvect.transpose();
366  free(cond);
367 }
368 
369 //
370 //trigonlisation simultanne d'une liste de matrices
371 //complexe de type lapack<complex<double>>
372 //
373 
374 template<typename Mat>
375 void compltrigsim(list<Mat> &lmat)
376 {
377  //on supose que la list n'est pas vide!!!
378  int sum=0;
379  Mat Shurvect,Combilin,tmp;
380  Mat invShurvect;
381  //<ugly>
382  double *tab=(double*)malloc(lmat.size()*sizeof(double));
383  //<\ugly>
384  typename list<Mat>::iterator iterComb=lmat.begin();
385  for(int i=0;i<lmat.size();i++)
386  tab[i]=rand()% 32003;
387  for(int i=0;i<lmat.size();i++)
388  {
389  sum+=tab[i];
390  // cout<<"tab["<<i<<"] "<<tab[i]<<endl;
391  }
392  iterComb++;
393  //cout<<"completrigsim"<<endl;
394  Combilin=lmat.front();
395  for(int i=0;iterComb!=lmat.end();iterComb++,i++)
396  {
397  Combilin+=tab[i]*(*iterComb);
398  }
399  Combilin/=sum;
400  //cout<<Combilin<<endl;
401  Shurvect=wraplapack_zgees(Combilin);
402  Shurvect.transpose();
403  invShurvect=Shurvect;
404  Shurvect.transpose();
405  //tmp=invShurvect*Combilin*Shurvect;
406  //Combilin=tmp;
407  //cout<<"apres trigo "<<endl<<Combilin<<endl;
408  for(int i=0;i<invShurvect.nbrow();i++)
409  for(int j=0;j<invShurvect.nbcol();j++)
410  invShurvect(i,j)=conj(invShurvect(i,j));
411  //cout<<"reorder"<<endl;
412  tmp=invShurvect*Combilin*Shurvect;
413  Combilin=tmp;
414  //cout<<"apres trigo "<<endl<<Combilin<<endl;
415  reorder(Combilin,Shurvect,invShurvect);
416 
417  typename list<Mat>::iterator iter;
418  for(iter=lmat.begin();iter!=lmat.end();iter++)
419  {
420  Mat tmp=invShurvect;
421  tmp*=(*iter);
422  tmp*=Shurvect;
423  *iter=tmp;
424  }
425 }
426 
427 //
428 //resolution une fois le boulot fait!!
429 //on a plus qu'a lire sur la diagonale
430 //
431 
432 template<typename Mat,typename Complex_Mat>
433 void solvefromcompltrigsim(const list<Mat> &lmat,Complex_Mat &res)
434 {
435  int increment,i;
436  typename list<Mat>::const_iterator iter,deb=lmat.begin();
437  for(i=0;i<deb->nbrow();i++)
438  {
439  int comp=0;
440  for(iter=lmat.begin();iter!=lmat.end();iter++)
441  {
442  res(i,comp,(*iter)(i,i));
443  comp++;
444  }
445  }
446 }
447 //
448 //la meme mais en reel
449 //c plus dur parce que il peut ya vavoir de blocs 2x2
450 //
451 template<typename Mat,typename Complex_Mat>
452 void solvefromtrigsim(const list<Mat> &lmat,Complex_Mat &res)
453 {
454  int increment,i;
455  typename list<Mat>::const_iterator iter,deb=lmat.begin();
456  for(i=0;i<deb->nbrow();)
457  {
458  if ((*deb)(i+1,i)+(*deb)(i,i)==(*deb)(i,i))//cas reel
459  {
460  int comp=0;
461  increment=1;
462  for(iter=lmat.begin();iter!=lmat.end();iter++)
463  {
464  res(i,comp)=(*iter)(i,i);
465  comp++;
466  }
467  }
468  else //cas complex
469  {
470  int comp=0;
471  increment=2;
472  Complex_Mat tmp(2,2),tmpShu(2,2),invtmpShu(2,2);
473  tmp(0,0)=(*deb)(i,i);
474  tmp(1,0)=(*deb)(i+1,i);
475  tmp(1,1)=(*deb)(i+1,i+1);
476  tmp(0,1)=(*deb)(i,i+1);
477  tmpShu=wraplapack_zgees(tmp);
478  tmpShu.transpose();
479  invtmpShu=tmpShu;
480  tmpShu.transpose();
481  invtmpShu(0,0)=conj(invtmpShu(0,0));
482  invtmpShu(1,0)=conj(invtmpShu(1,0));
483  invtmpShu(1,1)=conj(invtmpShu(1,1));
484  invtmpShu(0,1)=conj(invtmpShu(0,1));
485  for(iter=lmat.begin();iter!=lmat.end();iter++)
486  {
487  tmp(0,0)=(*iter)(i,i);
488  tmp(1,0)=(*iter)(i+1,i);
489  tmp(1,1)=(*iter)(i+1,i+1);
490  tmp(0,1)=(*iter)(i,i+1);
491  tmp=invtmpShu*tmp*tmpShu;
492  res(i,comp)=tmp(0,0);
493  res(i+1,comp)=tmp(1,1);
494  comp++;
495  }
496  }
497  i+=increment;
498  }
499 }
500 
501 template<typename Mat>
503 {
504  typedef typename Mat::rep_t rept;
505  float toto;
506  rept m=M.rep;
507  Mat Mres(m.nbrow(),m.nbrow());
508  int info,n,l,ilo,ihi;
509  unsigned int i;
510  doublecomplex* tab =
511  (doublecomplex*)calloc(m.nbcol_*m.nbrow_,sizeof(doublecomplex));
512  doublereal *scale =
513  (doublereal*)calloc(m.nbcol_,sizeof(doublereal));
514  char *JOBS="B";
515 
516  n=m.nbrow_;l=m.nbrow_;
517 
518  for(i=0;i<m.nbcol_*m.nbrow_;i++) {
519  tab[i].r=m.tab_[i].real();
520  tab[i].i=m.tab_[i].imag();
521 
522  //cout<<"tab["<<2*i<<"]";
523  //cout<<tab[i].r<<" "<<tab[i].i<<endl;
524  toto=tab[i].r;
525  //cout<<"tentative toto"<<toto<<endl;
526  }
527  //cout<<"avant lapack"<<endl;
528  //cout<<"int "<<sizeof(int)<<endl<<"int *"<<sizeof(int*)<<endl;
529  //cout<<"fun "<<sizeof(int (*)(void *))<<endl<<"DOUBLE "<<sizeof(double)<<endl;
530  zgebal_(JOBS,&n,tab,&l,&ilo,&ihi,scale,&info);
531  // cout<<"apres lapack"<<tab<<" info "<<info<<" ilo "<<ilo<<" ihi "<<ihi<<endl;
532  (Mres.rep).reserve(n,n);//matrice carree exclusivement!!
533  for(unsigned int i=0;i<m.nbcol_*m.nbrow_;i++)
534  {
535  (Mres.rep).tab_[i]=complex<double>(tab[i].r,tab[i].i);
536  //cout<<"tab["<<2*i<<"]";
537  cout<<tab[i].r<<" "<<tab[i].i<<endl;
538  // cout<<"scale "<<scale[i/n]<<endl;
539  }
540  // cout<<"info "<<info<<endl;
541  //cout<<Mres<<endl<<endl;
542 
543 
544  free(tab);
545  free(scale);
546  return Mres;
547 }
548 
549 //
550 //resoud le system en effectuant une decomposition de Schgur simultannee
551 //telle que decrite dans Corless Trager issac 97
552 //
553 
554 template<typename lmat,typename typres>
555 void GetRootMat(lmat &lres,typres &res)
556 {
557  compltrigsim(lres);
558  {
559  typres tmpres((lres.front()).nbrow(),lres.size());
560  solvefromcompltrigsim(lres,tmpres);
561  res=tmpres;
562  }
563 }
564 
565 template<typename typres,typename Base>
566 void realsolve2(const list<harewell<QQ> > &lmat,const Base &b,typres &res)
567 {
568  int i;
569  list<MatDense<lapack<complex<double > > > >lres;
570 
571  for(list<harewell<QQ> >::const_iterator iter=lmat.begin()
572  ;iter!=lmat.end();iter++)
573  {
574  MatDense<lapack<complex<double> > > tmp(iter->nrow,iter->ncol);
575  (tmp.rep).reserve(iter->nrow,iter->ncol);
576  for(int j=0;j<iter->nrow;j++)
577  for(int k=0;k<iter->ncol;k++)
578  {
579  tmp(j,k)=mpq_get_d(&(*iter)(j,k).rep());
580  //tmp(i,k).imag()=0;
581  //fortement sous optimal
582  }
583  lres.push_back(tmp);
584  }
585  GetRootMat(lres,res);
586 }
587 
588 template<typename typres, typename Base>
589 void realsolve2(const list<harewell<RR> > &lmat,const Base &b,typres &res)
590 {
591  int i;
592  list<MatDense<lapack<complex<double > > > >lres;
593 
594  for(list<harewell<RR> >::const_iterator iter=lmat.begin()
595  ;iter!=lmat.end();iter++)
596  {
597  MatDense<lapack<complex<double> > > tmp(iter->nrow,iter->ncol);
598  (tmp.rep).reserve(iter->nrow,iter->ncol);
599  for(int j=0;j<iter->nrow;j++)
600  for(int k=0;k<iter->ncol;k++)
601  {
602  tmp(j,k)=mpf_get_d((*iter)(j,k).rep());
603  //tmp(i,k).imag()=0;
604  //fortement sous optimal
605  }
606  lres.push_back(tmp);
607  }
608  GetRootMat(lres,res);
609 }
610 
611 template<typename typres,
612  typename typlmat,typename Base>
613 void realsolve3(const typlmat &lmat,const Base &b,typres &res)
614 {
615  int i;
616  list<MatDense<lapack<complex<double > > > >lres;
617 
618  for(typename typlmat::const_iterator iter=lmat.begin()
619  ;iter!=lmat.end();iter++)
620  {
621  MatDense<lapack<complex<double> > > tmp(iter->nrow,iter->ncol);
622  (tmp.rep).reserve(iter->nrow,iter->ncol);
623  for(int j=0;j<iter->nrow;j++)
624  for(int k=0;k<iter->ncol;k++)
625  {
626  tmp(j,k)=mpq_get_d(&(*iter)(j,k).rep());
627  //tmp(i,k).imag()=0;
628  //fortement sous optimal
629  }
630  lres.push_back(tmp);
631  }
632  GetRootMat(lres,res);
633 }
void GetRootMat(lmat &lres, typres &res)
Definition: resolve.hpp:555
#define max(a, b)
Definition: alp_f2c.H:167
void free(void *)
void realsolve3(const typlmat &lmat, const Base &b, typres &res)
Definition: resolve.hpp:613
Mat wraplapack_zgebal(Mat M)
Definition: resolve.hpp:502
int ztrsen_(const char *job, const char *compq, logical *select, tla_int *n, doublecomplex< T > *t, tla_int *ldt, doublecomplex< T > *q, tla_int *ldq, doublecomplex< T > *w, tla_int *m, T *s, T *sep, doublecomplex< T > *work, tla_int *lwork, tla_int *info)
doublereal i
Definition: alp_f2c.H:30
long int select_true(doublecomplex *toto)
Definition: resolve.hpp:60
void wraplapack_ztrsen(Mat &M, logical *select, doublereal *res)
Definition: resolve.hpp:145
void solvefromcompltrigsim(const list< Mat > &lmat, Complex_Mat &res)
Definition: resolve.hpp:433
void solvefromtrigsim(const list< Mat > &lmat, Complex_Mat &res)
Definition: resolve.hpp:452
MSKint32t MSKint32t MSKint32t MSKrealt * val
Definition: mosek.h:2359
Mat wraplapack_dgees(const Mat &M)
Definition: resolve.hpp:31
long flag
Definition: alp_f2c.H:52
void * malloc(YYSIZE_T)
Mat wraplapack_zgees(Mat M)
Definition: resolve.hpp:73
double doublereal
Definition: resolve.hpp:7
MSKconetypee MSKrealt MSKint32t MSKint32t j
Definition: mosek.h:2421
void realsolve2(const list< harewell< QQ > > &lmat, const Base &b, typres &res)
Definition: resolve.hpp:566
MSKint32t k
Definition: mosek.h:2713
void docluster(Mat &M, Mat &Shurvect, doublereal *cond, int i)
Definition: resolve.hpp:259
int getcluster(Mat &M, typcond *cond)
Definition: resolve.hpp:188
typedef void(MSKAPI *MSKexitfunc)(MSKuserhandle_t usrptr
doublereal r
Definition: alp_f2c.H:30
Definition: types.hpp:14
Scl< T > & sqrt(const Scl< T > &b)
Definition: BC.hpp:1103
doublereal cond_number(Mat &Combilin, int i)
Definition: resolve.hpp:173
MSKint32t MSKint32t MSKint32t i
Definition: mosek.h:2278
void compltrigsim(list< Mat > &lmat)
Definition: resolve.hpp:375
void dgees_(char *JOBVS, char *SORT, bool(*SELECT)(double, double), int *N, double *A, int *LDA, int *SDIM, double *WR, double *WI, double *VS, int *LDVS, double *WORK, int *LWORK, double *BWORK, int *info)
#define abs(x)
Definition: f2c.H:161
int zgebal_(...)
MSKrescodee r
Definition: mosek.h:2321
void reorder(Mat &Combilin, Mat &Shurvect, Mat &invShurvect)
Definition: resolve.hpp:346
long int logical
Definition: resolve.hpp:8
int zgees_(const char *jobvs, const char *sort, logical(*select)(doublecomplex< T > *), tla_int *n, doublecomplex< T > *a, tla_int *lda, tla_int *sdim, doublecomplex< T > *w, doublecomplex< T > *vs, tla_int *ldvs, doublecomplex< T > *work, tla_int *lwork, T *rwork, logical *bwork, tla_int *info)
void trigsim(list< Mat > &lmat)
Definition: resolve.hpp:128
Definition: alp_f2c.H:30
long min(long a, long b)
Definition: workspace.hpp:3
Home  |  Download & InstallContributions