Data Structures | Macros | Functions
intvec.h File Reference
#include <string.h>
#include <omalloc/omalloc.h>
#include <reporter/reporter.h>

Go to the source code of this file.

Data Structures

class  intvec
 

Macros

#define IMATELEM(M, I, J)   (M)[(I-1)*(M).cols()+J-1]
 
#define ivTest(v)   do {} while (0)
 

Functions

intvecivCopy (const intvec *o)
 
intvecivAdd (intvec *a, intvec *b)
 
intvecivSub (intvec *a, intvec *b)
 
intvecivTranp (intvec *o)
 
int ivTrace (intvec *o)
 
intvecivMult (intvec *a, intvec *b)
 
void ivTriangIntern (intvec *imat, int &ready, int &all)
 
intvecivSolveKern (intvec *imat, int ready)
 
intvecivConcat (intvec *a, intvec *b)
 

Macro Definition Documentation

#define IMATELEM (   M,
  I,
 
)    (M)[(I-1)*(M).cols()+J-1]

Definition at line 76 of file intvec.h.

#define ivTest (   v)    do {} while (0)

Definition at line 156 of file intvec.h.

Function Documentation

intvec* ivAdd ( intvec a,
intvec b 
)

Definition at line 262 of file intvec.cc.

263 {
264  intvec * iv;
265  int mn, ma, i;
266  if (a->cols() != b->cols()) return NULL;
267  mn = si_min(a->rows(),b->rows());
268  ma = si_max(a->rows(),b->rows());
269  if (a->cols() == 1)
270  {
271  iv = new intvec(ma);
272  for (i=0; i<mn; i++) (*iv)[i] = (*a)[i] + (*b)[i];
273  if (ma > mn)
274  {
275  if (ma == a->rows())
276  {
277  for(i=mn; i<ma; i++) (*iv)[i] = (*a)[i];
278  }
279  else
280  {
281  for(i=mn; i<ma; i++) (*iv)[i] = (*b)[i];
282  }
283  }
284  return iv;
285  }
286  if (mn != ma) return NULL;
287  iv = new intvec(a);
288  for (i=0; i<mn*a->cols(); i++) { (*iv)[i] += (*b)[i]; }
289  return iv;
290 }
static int si_min(const int a, const int b)
Definition: auxiliary.h:167
Definition: intvec.h:16
static int si_max(const int a, const int b)
Definition: auxiliary.h:166
int i
Definition: cfEzgcd.cc:123
#define NULL
Definition: omList.c:10
int cols() const
Definition: intvec.h:86
int rows() const
Definition: intvec.h:87
intvec* ivConcat ( intvec a,
intvec b 
)

Definition at line 817 of file intvec.cc.

818 {
819  int ac=a->cols();
820  int c = ac + b->cols(); int r = si_max(a->rows(),b->rows());
821  intvec * ab = new intvec(r,c,0);
822 
823  int i,j;
824  for (i=1; i<=a->rows(); i++)
825  {
826  for(j=1; j<=ac; j++)
827  IMATELEM(*ab,i,j) = IMATELEM(*a,i,j);
828  }
829  for (i=1; i<=b->rows(); i++)
830  {
831  for(j=1; j<=b->cols(); j++)
832  IMATELEM(*ab,i,j+ac) = IMATELEM(*b,i,j);
833  }
834  return ab;
835 }
const ring r
Definition: syzextra.cc:208
Definition: intvec.h:16
int j
Definition: myNF.cc:70
static int si_max(const int a, const int b)
Definition: auxiliary.h:166
int i
Definition: cfEzgcd.cc:123
int cols() const
Definition: intvec.h:86
int rows() const
Definition: intvec.h:87
#define IMATELEM(M, I, J)
Definition: intvec.h:76
intvec* ivCopy ( const intvec o)
inline

Definition at line 132 of file intvec.h.

133 {
134  if( o != NULL )
135  return new intvec(o);
136 
137  return NULL;
138 }
Definition: intvec.h:16
#define NULL
Definition: omList.c:10
intvec* ivMult ( intvec a,
intvec b 
)

Definition at line 344 of file intvec.cc.

345 {
346  int i, j, k, sum,
347  ra = a->rows(), ca = a->cols(),
348  rb = b->rows(), cb = b->cols();
349  intvec * iv;
350  if (ca != rb) return NULL;
351  iv = new intvec(ra, cb, 0);
352  for (i=0; i<ra; i++)
353  {
354  for (j=0; j<cb; j++)
355  {
356  sum = 0;
357  for (k=0; k<ca; k++)
358  sum += (*a)[i*ca+k]*(*b)[k*cb+j];
359  (*iv)[i*cb+j] = sum;
360  }
361  }
362  return iv;
363 }
int k
Definition: cfEzgcd.cc:93
Definition: intvec.h:16
int j
Definition: myNF.cc:70
int i
Definition: cfEzgcd.cc:123
#define NULL
Definition: omList.c:10
int cols() const
Definition: intvec.h:86
int rows() const
Definition: intvec.h:87
intvec* ivSolveKern ( intvec imat,
int  ready 
)

Definition at line 437 of file intvec.cc.

438 {
439  int d=imat->cols();
440  int kdim=d-dimtr;
441  intvec *perm = new intvec(dimtr+1);
442  intvec *kern = new intvec(kdim,d,0);
443  intvec *res;
444  int c, cp, r, t;
445 
446  t = kdim;
447  c = 1;
448  for (r=1;r<=dimtr;r++)
449  {
450  while (IMATELEM(*imat,r,c)==0) c++;
451  (*perm)[r] = c;
452  c++;
453  }
454  c = d;
455  for (r=dimtr;r>0;r--)
456  {
457  cp = (*perm)[r];
458  if (cp!=c)
459  {
460  ivKernFromRow(kern, imat, perm, t, r, c);
461  t -= (c-cp);
462  if (t==0)
463  break;
464  c = cp-1;
465  }
466  else
467  c--;
468  }
469  if (kdim>1)
470  res = ivOptimizeKern(kern);
471  else
472  res = ivTranp(kern);
473  delete kern;
474  delete perm;
475  return res;
476 }
static intvec * ivOptimizeKern(intvec *)
Definition: intvec.cc:664
intvec * ivTranp(intvec *o)
Definition: intvec.cc:322
poly res
Definition: myNF.cc:322
const ring r
Definition: syzextra.cc:208
Definition: intvec.h:16
int cols() const
Definition: intvec.h:86
static void ivKernFromRow(intvec *, intvec *, intvec *, int, int, int)
Definition: intvec.cc:608
#define IMATELEM(M, I, J)
Definition: intvec.h:76
intvec* ivSub ( intvec a,
intvec b 
)

Definition at line 292 of file intvec.cc.

293 {
294  intvec * iv;
295  int mn, ma, i;
296  if (a->cols() != b->cols()) return NULL;
297  mn = si_min(a->rows(),b->rows());
298  ma = si_max(a->rows(),b->rows());
299  if (a->cols() == 1)
300  {
301  iv = new intvec(ma);
302  for (i=0; i<mn; i++) (*iv)[i] = (*a)[i] - (*b)[i];
303  if (ma > mn)
304  {
305  if (ma == a->rows())
306  {
307  for(i=mn; i<ma; i++) (*iv)[i] = (*a)[i];
308  }
309  else
310  {
311  for(i=mn; i<ma; i++) (*iv)[i] = -(*b)[i];
312  }
313  }
314  return iv;
315  }
316  if (mn != ma) return NULL;
317  iv = new intvec(a);
318  for (i=0; i<mn*a->cols(); i++) { (*iv)[i] -= (*b)[i]; }
319  return iv;
320 }
static int si_min(const int a, const int b)
Definition: auxiliary.h:167
Definition: intvec.h:16
static int si_max(const int a, const int b)
Definition: auxiliary.h:166
int i
Definition: cfEzgcd.cc:123
#define NULL
Definition: omList.c:10
int cols() const
Definition: intvec.h:86
int rows() const
Definition: intvec.h:87
int ivTrace ( intvec o)

Definition at line 334 of file intvec.cc.

335 {
336  int i, s = 0, m = si_min(o->rows(),o->cols()), c = o->cols();
337  for (i=0; i<m; i++)
338  {
339  s += (*o)[i*c+i];
340  }
341  return s;
342 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
static int si_min(const int a, const int b)
Definition: auxiliary.h:167
int m
Definition: cfEzgcd.cc:119
int i
Definition: cfEzgcd.cc:123
int cols() const
Definition: intvec.h:86
int rows() const
Definition: intvec.h:87
intvec* ivTranp ( intvec o)

Definition at line 322 of file intvec.cc.

323 {
324  int i, j, r = o->rows(), c = o->cols();
325  intvec * iv= new intvec(c, r, 0);
326  for (i=0; i<r; i++)
327  {
328  for (j=0; j<c; j++)
329  (*iv)[j*r+i] = (*o)[i*c+j];
330  }
331  return iv;
332 }
const ring r
Definition: syzextra.cc:208
Definition: intvec.h:16
int j
Definition: myNF.cc:70
int i
Definition: cfEzgcd.cc:123
int cols() const
Definition: intvec.h:86
int rows() const
Definition: intvec.h:87
void ivTriangIntern ( intvec imat,
int ready,
int all 
)

Definition at line 399 of file intvec.cc.

400 {
401  int rpiv, colpos=0, rowpos=0;
402  int ia=ready, ie=all;
403 
404  do
405  {
406  rowpos++;
407  do
408  {
409  colpos++;
410  rpiv = ivColPivot(imat, colpos, rowpos, ia, ie);
411  } while (rpiv==0);
412  if (rpiv>ia)
413  {
414  if (rowpos!=rpiv)
415  {
416  ivSaveRow(imat, rpiv);
417  ivFreeRow(imat, rowpos, rpiv);
418  ivSetRow(imat, rowpos, colpos);
419  rpiv = rowpos;
420  }
421  ia++;
422  if (ia==imat->cols())
423  {
424  ready = ia;
425  all = ie;
426  return;
427  }
428  }
429  ivReduce(imat, rpiv, colpos, ia, ie);
430  ivZeroElim(imat, colpos, ia, ie);
431  } while (ie>ia);
432  ready = ia;
433  all = ie;
434 }
static void ivZeroElim(intvec *, int, int, int &)
Definition: intvec.cc:559
static void ivFreeRow(intvec *, int, int)
Definition: intvec.cc:517
static void ivSaveRow(intvec *, int)
Definition: intvec.cc:500
static int ivColPivot(intvec *, int, int, int, int)
Definition: intvec.cc:479
static void ivReduce(intvec *, int, int, int, int)
Definition: intvec.cc:528
static void ivSetRow(intvec *, int, int)
Definition: intvec.cc:508
int cols() const
Definition: intvec.h:86