Borderbasix

zpspecial.hpp
Go to the documentation of this file.
1 #ifndef ALREADY_zpspecial
2 #define ALREADY_zpspecial
3 
4 #ifdef MON_PREMIER
5 
6 #ifdef tableop
9 
10 void inittableop()
11 {
12  for(int i=0;i<MON_PREMIER;i++)
13  {
14  tableplus[i].rep=i;
15  tableplus[MON_PREMIER+i].rep=i;
16  }
17  for(int i=0;i<MON_PREMIER;i++)
18  {
19  tablemoins[i].rep=i;
20  tablemoins[MON_PREMIER+i].rep=MON_PREMIER-i;
21  }
22 }
23 template<>
26 {
27  rep=tableplus[rep+z.rep].rep;
28  return *this;
29 }
30 template<>
33  {
34  return tableplus[rep+b.rep];
35  }
36 template<>
39 {
40  rep=tablemoins[rep+z.rep].rep;
41  return *this;
42 }
43 
44 #else
45 
46 
47 template<>
50  {
51  int tmp=rep;
52  if(tmp) cout<<"";
53  (tmp += z.rep);
54  if(tmp>=MON_PREMIER) tmp-=MON_PREMIER;
55  rep=tmp;
56  //if(rep<0) {cout<<"+="<<endl;exit(1);};
57  return *this;
58  }
59 
60 template<>
63  {
64  Z<MON_PREMIER,short int> res; int tmp=rep;
65  tmp+=b.rep; if (tmp>MON_PREMIER) tmp-=MON_PREMIER;
66  res.rep=tmp;
67  //if(res.rep<0) {cout<<"+"<<endl;exit(1);};
68 return res;}
69 
70 template<>
73  {
74  //cout<<",kkln,nk"<<rep<<endl;
75  //cout<<"desert"<<z.rep<<endl;
76  int tmp=rep;
77  tmp -= z.rep;
78  if(tmp<0) tmp+=MON_PREMIER;
79  rep=tmp;
80  //if(rep<0) {cout<<"+="<<endl;exit(1);};
81  return *this;
82  }
83 
84 template<>
87  {
88  Z<MON_PREMIER,short int> res; int tmp=rep;
89  tmp=(tmp-b.rep); if (tmp<0) tmp+=MON_PREMIER;
90  res.rep=tmp;
91  //if(res.rep<0) {cout<<"+"<<endl;exit(1);};
92 return res;}
93 
94 #endif
95 
96 template<>
98 {int tmp=rep; rep=(short int)((tmp * z.rep)% MON_PREMIER); return *this;}
99 
100 
101 template<>
102 inline
104 {
105  int tmp=rep;
107  res.rep=(tmp*b.rep)%MON_PREMIER;
108  return res;
109 }
110 
111 template<>
113 {
114  static int flag=1;
115  static int *inverse=NULL;
116 #ifdef PETITFERMAT
117  static int expon[MON_PREMIER];
118 #endif //
119  // int r=z.rep, a=z.rep, b=p,u1=0,u2=0, q;
120  if (flag)
121  {
122  inverse=(int*)malloc(MON_PREMIER*sizeof(int));
123 
124  cout<<"je malloc tout ca"<<endl;
125  for(int i=0;i<MON_PREMIER;i++)
126  inverse[i]=-1;
127  // {
128 // int inversez;
129 // for(inversez=0;((inversez*i % p)!=1);inversez++);
130 // inverse[i]=inversez;
131 // }
132  flag=0;
133  }
134  //cout<<"z.rep "<<z.rep<<endl;
135  if(z==0)
136  {std::cerr<<"division by zero"<<endl;exit(-10);}
137  if(inverse[(short int)z.rep]==-1)
138  {
139  int inversez;
140 #ifndef PETITFERMAT
141  {
142  for(inversez=0;((inversez*z.rep % MON_PREMIER)!=1);inversez++);
143  int bez_1_1=1,bez_1_2=0;
144  int bez_2_1=0,bez_2_2=1;
145 
146  }
147 #else
148  int comp=1;
149  expon[1]=z.rep;
150  for(;comp*2<MON_PREMIER;comp*=2)
151  expon[2*comp]=(expon[comp]*expon[comp]) %MON_PREMIER;
152  inversez=expon[comp];
153  for(int total=comp;total<MON_PREMIER-2;total+=comp)
154  {
155  for(;comp+total>MON_PREMIER-2;comp/=2);
156  inversez=(inversez * expon[comp]) %MON_PREMIER;
157  }
158 #endif //
159  inverse[z.rep]=inversez;
160  }
161  flag=rep *inverse[z.rep];
162  rep =flag % MON_PREMIER;
163  flag=0;
164  return *this;
165 }
166 
167 //void convert(Z<MON_PREMIER,int> &toto,char * chaine)
168 //{
169 // toto=Z<MON_PREMIER,int>(chaine);
170 //}
171 template<typename T>
172 void convert(Z<MON_PREMIER,T> &toto,char * chaine)
173 {
174  toto=Z<MON_PREMIER,T>(chaine);
175 }
176 
177 template<typename T>
178 int
179 dpivotL(
180  const int jcol, /* in */
181  const Z<MON_PREMIER,T> u, /* in - diagonal pivoting threshold */
182  int *usepr, /* re-use the pivot sequence given by perm_r/iperm_r */
183  int *perm_r, /* may be modified */
184  int *iperm_r, /* in - inverse of perm_r */
185  int *iperm_c, /* in - used to find diagonal of Pc*A*Pc' */
186  int *pivrow, /* out */
187  GlobalLU_t<Z<MON_PREMIER,T> > *Glu /* modified - global LU data structures */
188  )
189 {
190 /*
191  * Purpose
192  * =======
193  * Performs the numerical pivoting on the current column of L,
194  * and the CDIV operation.
195  *
196  * Pivot policy:
197  * (1) Compute thresh = u * max_(i>=j) abs(A_ij);
198  * (2) IF user specifies pivot row k and abs(A_kj) >= thresh THEN
199  * pivot row = k;
200  * ELSE IF abs(A_jj) >= thresh THEN
201  * pivot row = j;
202  * ELSE
203  * pivot row = m;
204  *
205  * Note: If you absolutely want to use a given pivot order, then set u=0.0.
206  *
207  * Return value: 0 success;
208  * i > 0 U(i,i) is exactly zero.
209  *
210  */
211  int fsupc; /* first column in the supernode */
212  int nsupc; /* no of columns in the supernode */
213  int nsupr; /* no of rows in the supernode */
214  int lptr; /* points to the starting subscript of the supernode */
215  int pivptr, old_pivptr, diag, diagind;
216  Z<MON_PREMIER,T> pivmax, rtemp, thresh;
217  Z<MON_PREMIER,T> temp;
218  Z<MON_PREMIER,T> *lu_sup_ptr;
219  Z<MON_PREMIER,T> *lu_col_ptr;
220  int *lsub_ptr;
221  int isub, icol, k, itemp;
222  int *lsub, *xlsub;
223  Z<MON_PREMIER,T> *lusup;
224  int *xlusup;
225  extern SuperLUStat_t SuperLUStat;
226  flops_t *ops = SuperLUStat.ops;
227 
228  /* Initialize pointers */
229  lsub = Glu->lsub;
230  xlsub = Glu->xlsub;
231  lusup = Glu->lusup;
232  xlusup = Glu->xlusup;
233  fsupc = (Glu->xsup)[(Glu->supno)[jcol]];
234  nsupc = jcol - fsupc; /* excluding jcol; nsupc >= 0 */
235  lptr = xlsub[fsupc];
236  nsupr = xlsub[fsupc+1] - lptr;
237  lu_sup_ptr = &lusup[xlusup[fsupc]]; /* start of the current supernode */
238  lu_col_ptr = &lusup[xlusup[jcol]]; /* start of jcol in the supernode */
239  lsub_ptr = &lsub[lptr]; /* start of row indices of the supernode */
240 
241 #ifdef DEBUG
242 if ( jcol == MIN_COL ) {
243  printf("Before cdiv: col %d\n", jcol);
244  for (k = nsupc; k < nsupr; k++)
245  printf(" lu[%d] %f\n", lsub_ptr[k], lu_col_ptr[k]);
246 }
247 #endif
248 
249  /* Determine the largest abs numerical value for partial pivoting;
250  Also search for user-specified pivot, and diagonal element. */
251  if ( *usepr ) *pivrow = iperm_r[jcol];
252  diagind = iperm_c[jcol];
253  pivmax =(Z<MON_PREMIER,T>)0;
254  pivptr = nsupc;
255  diag = EMPTY;
256  old_pivptr = nsupc;
257  for (isub = nsupc; isub < nsupr; ++isub) {
258  rtemp = lu_col_ptr[isub];
259 
260  if ( rtemp != 0 ) {
261  pivmax = rtemp;
262  pivptr = isub;
263  break;
264  }
265  if ( *usepr && lsub_ptr[isub] == *pivrow ) old_pivptr = isub;
266  if ( lsub_ptr[isub] == diagind ) diag = isub;
267  }
268  //cout<<"comparaison dans dpivvotL "<<pivmax<<endl;
269  /* Test for singularity */
270  if ( pivmax ==0) {
271  *pivrow = lsub_ptr[nsupc];
272  //cout<<"degenere et pivrow "<<*pivrow<<endl;
273  perm_r[*pivrow] = jcol;
274  *usepr = 0;
275  return (jcol+1);
276  }
277 
278  thresh = u * pivmax;
279 
280  /* Choose appropriate pivotal element by our policy. */
281  if ( *usepr ) {
282  //fabs!!!!
283  rtemp = lu_col_ptr[old_pivptr];
284  //fabs!!!!!!!!!!!!!!!!! faire gaffe en generic
285  if ( rtemp != (Z<MON_PREMIER,T>)0 )
286  pivptr = old_pivptr;
287  else
288  *usepr = 0;
289  }
290  if ( *usepr == 0 ) {
291  /* Use diagonal pivot? */
292  if ( diag >= 0 ) { /* diagonal exists */
293  rtemp = lu_col_ptr[diag];
294  if ( rtemp != (Z<MON_PREMIER,T>)0 ) pivptr = diag;
295  }
296  *pivrow = lsub_ptr[pivptr];
297  }
298 
299  /* Record pivot row */
300  // cout<<"piv row "<<*pivrow<<" jcol "<<jcol<<endl;
301  perm_r[*pivrow] = jcol;
302 
303  /* Interchange row subscripts */
304  if ( pivptr != nsupc ) {
305  itemp = lsub_ptr[pivptr];
306  lsub_ptr[pivptr] = lsub_ptr[nsupc];
307  lsub_ptr[nsupc] = itemp;
308 
309  /* Interchange numerical values as well, for the whole snode, such
310  * that L is indexed the same way as A.
311  */
312  for (icol = 0; icol <= nsupc; icol++) {
313  itemp = pivptr + icol * nsupr;
314  temp = lu_sup_ptr[itemp];
315  lu_sup_ptr[itemp] = lu_sup_ptr[nsupc + icol*nsupr];
316  lu_sup_ptr[nsupc + icol*nsupr] = temp;
317  }
318  } /* if */
319 
320  /* cdiv operation */
321  ops[FACT] += nsupr - nsupc;
322  temp = (Z<MON_PREMIER,T>)1 / lu_col_ptr[nsupc];
323  for (k = nsupc+1; k < nsupr; k++)
324  lu_col_ptr[k] *= temp;
325 
326  return 0;
327 }
328 int Iszero(const Z<MON_PREMIER,short int> & c)
329 {return c==(short int)0;}
330 
331 template<typename T>
332 inline int Iszero(const Z<MON_PREMIER,T> & c)
333 {return c==(T)0;}
334 
335 
336 #endif
337 #endif //ALREADY_zpspecial
Z< p, T > & operator-=(const Z< p, T > z)
Definition: Zp.hpp:46
long flag
Definition: alp_f2c.H:52
void inverse(int *&, int)
void * malloc(YYSIZE_T)
#define MON_PREMIER
Definition: solver_bb_mod.cpp:43
Z< p, T > operator-(const Z< p, T > &b) const
Definition: Zp.hpp:71
Z< p, T > & operator+=(const Z< p, T > z)
Definition: Zp.hpp:38
MSKint32t k
Definition: mosek.h:2713
Definition: Zp.hpp:19
void convert(C &, char *)
Z< p, T > & operator/=(const Z< p, T > z)
Definition: Zp.C:19
MSKrealt * c
Definition: mosek.h:2678
Z< p, T > & operator*=(const Z< p, T > z)
Definition: Zp.hpp:53
MSKint32t MSKint32t MSKint32t i
Definition: mosek.h:2278
int Iszero(const Scl< MPQ > &c)
Definition: Iszero.hpp:14
Z< p, T > operator+(const Z< p, T > &b) const
Definition: Zp.hpp:63
T rep
Definition: Zp.hpp:25
int dpivotL(const int jcol, const macrev_Z u, int *usepr, int *perm_r, int *iperm_r, int *iperm_c, int *pivrow, GlobalLU_t< macrev_Z > *Glu)
Definition: dpivmacrev_z.hpp:6
Z< p, T > operator*(const Z< p, T > &b) const
Definition: Zp.hpp:84
Home  |  Download & InstallContributions