Data Structures | Macros | Functions
intvec.h File Reference
#include <string.h>
#include "misc/auxiliary.h"
#include "omalloc/omalloc.h"
#include "omalloc/omallocClass.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

◆ IMATELEM

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

Definition at line 85 of file intvec.h.

◆ ivTest

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

Definition at line 158 of file intvec.h.

Function Documentation

◆ ivAdd()

intvec* ivAdd ( intvec a,
intvec b 
)

Definition at line 249 of file intvec.cc.

250 {
251  intvec * iv;
252  int mn, ma, i;
253  if (a->cols() != b->cols()) return NULL;
254  mn = si_min(a->rows(),b->rows());
255  ma = si_max(a->rows(),b->rows());
256  if (a->cols() == 1)
257  {
258  iv = new intvec(ma);
259  for (i=0; i<mn; i++) (*iv)[i] = (*a)[i] + (*b)[i];
260  if (ma > mn)
261  {
262  if (ma == a->rows())
263  {
264  for(i=mn; i<ma; i++) (*iv)[i] = (*a)[i];
265  }
266  else
267  {
268  for(i=mn; i<ma; i++) (*iv)[i] = (*b)[i];
269  }
270  }
271  return iv;
272  }
273  if (mn != ma) return NULL;
274  iv = new intvec(a);
275  for (i=0; i<mn*a->cols(); i++) { (*iv)[i] += (*b)[i]; }
276  return iv;
277 }
static int si_min(const int a, const int b)
Definition: auxiliary.h:139
int rows() const
Definition: intvec.h:96
Definition: intvec.h:19
static int si_max(const int a, const int b)
Definition: auxiliary.h:138
int i
Definition: cfEzgcd.cc:125
#define NULL
Definition: omList.c:12
int cols() const
Definition: intvec.h:95

◆ ivConcat()

intvec* ivConcat ( intvec a,
intvec b 
)

Definition at line 804 of file intvec.cc.

805 {
806  int ac=a->cols();
807  int c = ac + b->cols(); int r = si_max(a->rows(),b->rows());
808  intvec * ab = new intvec(r,c,0);
809 
810  int i,j;
811  for (i=1; i<=a->rows(); i++)
812  {
813  for(j=1; j<=ac; j++)
814  IMATELEM(*ab,i,j) = IMATELEM(*a,i,j);
815  }
816  for (i=1; i<=b->rows(); i++)
817  {
818  for(j=1; j<=b->cols(); j++)
819  IMATELEM(*ab,i,j+ac) = IMATELEM(*b,i,j);
820  }
821  return ab;
822 }
int j
Definition: facHensel.cc:105
int rows() const
Definition: intvec.h:96
Definition: intvec.h:19
static int si_max(const int a, const int b)
Definition: auxiliary.h:138
int i
Definition: cfEzgcd.cc:125
int cols() const
Definition: intvec.h:95
#define IMATELEM(M, I, J)
Definition: intvec.h:85

◆ ivCopy()

intvec* ivCopy ( const intvec o)
inline

Definition at line 135 of file intvec.h.

136 {
137  if( o != NULL )
138  return new intvec(o);
139  return NULL;
140 }
Definition: intvec.h:19
#define NULL
Definition: omList.c:12

◆ ivMult()

intvec* ivMult ( intvec a,
intvec b 
)

Definition at line 331 of file intvec.cc.

332 {
333  int i, j, k, sum,
334  ra = a->rows(), ca = a->cols(),
335  rb = b->rows(), cb = b->cols();
336  intvec * iv;
337  if (ca != rb) return NULL;
338  iv = new intvec(ra, cb, 0);
339  for (i=0; i<ra; i++)
340  {
341  for (j=0; j<cb; j++)
342  {
343  sum = 0;
344  for (k=0; k<ca; k++)
345  sum += (*a)[i*ca+k]*(*b)[k*cb+j];
346  (*iv)[i*cb+j] = sum;
347  }
348  }
349  return iv;
350 }
int j
Definition: facHensel.cc:105
int rows() const
Definition: intvec.h:96
int k
Definition: cfEzgcd.cc:92
Definition: intvec.h:19
int i
Definition: cfEzgcd.cc:125
#define NULL
Definition: omList.c:12
int cols() const
Definition: intvec.h:95

◆ ivSolveKern()

intvec* ivSolveKern ( intvec imat,
int  ready 
)

Definition at line 424 of file intvec.cc.

425 {
426  int d=imat->cols();
427  int kdim=d-dimtr;
428  intvec *perm = new intvec(dimtr+1);
429  intvec *kern = new intvec(kdim,d,0);
430  intvec *res;
431  int c, cp, r, t;
432 
433  t = kdim;
434  c = 1;
435  for (r=1;r<=dimtr;r++)
436  {
437  while (IMATELEM(*imat,r,c)==0) c++;
438  (*perm)[r] = c;
439  c++;
440  }
441  c = d;
442  for (r=dimtr;r>0;r--)
443  {
444  cp = (*perm)[r];
445  if (cp!=c)
446  {
447  ivKernFromRow(kern, imat, perm, t, r, c);
448  t -= (c-cp);
449  if (t==0)
450  break;
451  c = cp-1;
452  }
453  else
454  c--;
455  }
456  if (kdim>1)
457  res = ivOptimizeKern(kern);
458  else
459  res = ivTranp(kern);
460  delete kern;
461  delete perm;
462  return res;
463 }
static intvec * ivOptimizeKern(intvec *)
Definition: intvec.cc:651
intvec * ivTranp(intvec *o)
Definition: intvec.cc:309
Definition: intvec.h:19
CanonicalForm res
Definition: facAbsFact.cc:64
static void ivKernFromRow(intvec *, intvec *, intvec *, int, int, int)
Definition: intvec.cc:595
int cols() const
Definition: intvec.h:95
#define IMATELEM(M, I, J)
Definition: intvec.h:85

◆ ivSub()

intvec* ivSub ( intvec a,
intvec b 
)

Definition at line 279 of file intvec.cc.

280 {
281  intvec * iv;
282  int mn, ma, i;
283  if (a->cols() != b->cols()) return NULL;
284  mn = si_min(a->rows(),b->rows());
285  ma = si_max(a->rows(),b->rows());
286  if (a->cols() == 1)
287  {
288  iv = new intvec(ma);
289  for (i=0; i<mn; i++) (*iv)[i] = (*a)[i] - (*b)[i];
290  if (ma > mn)
291  {
292  if (ma == a->rows())
293  {
294  for(i=mn; i<ma; i++) (*iv)[i] = (*a)[i];
295  }
296  else
297  {
298  for(i=mn; i<ma; i++) (*iv)[i] = -(*b)[i];
299  }
300  }
301  return iv;
302  }
303  if (mn != ma) return NULL;
304  iv = new intvec(a);
305  for (i=0; i<mn*a->cols(); i++) { (*iv)[i] -= (*b)[i]; }
306  return iv;
307 }
static int si_min(const int a, const int b)
Definition: auxiliary.h:139
int rows() const
Definition: intvec.h:96
Definition: intvec.h:19
static int si_max(const int a, const int b)
Definition: auxiliary.h:138
int i
Definition: cfEzgcd.cc:125
#define NULL
Definition: omList.c:12
int cols() const
Definition: intvec.h:95

◆ ivTrace()

int ivTrace ( intvec o)

Definition at line 321 of file intvec.cc.

322 {
323  int i, s = 0, m = si_min(o->rows(),o->cols()), c = o->cols();
324  for (i=0; i<m; i++)
325  {
326  s += (*o)[i*c+i];
327  }
328  return s;
329 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
static int si_min(const int a, const int b)
Definition: auxiliary.h:139
int rows() const
Definition: intvec.h:96
int m
Definition: cfEzgcd.cc:121
int i
Definition: cfEzgcd.cc:125
int cols() const
Definition: intvec.h:95

◆ ivTranp()

intvec* ivTranp ( intvec o)

Definition at line 309 of file intvec.cc.

310 {
311  int i, j, r = o->rows(), c = o->cols();
312  intvec * iv= new intvec(c, r, 0);
313  for (i=0; i<r; i++)
314  {
315  for (j=0; j<c; j++)
316  (*iv)[j*r+i] = (*o)[i*c+j];
317  }
318  return iv;
319 }
int j
Definition: facHensel.cc:105
int rows() const
Definition: intvec.h:96
Definition: intvec.h:19
int i
Definition: cfEzgcd.cc:125
int cols() const
Definition: intvec.h:95

◆ ivTriangIntern()

void ivTriangIntern ( intvec imat,
int &  ready,
int &  all 
)

Definition at line 386 of file intvec.cc.

387 {
388  int rpiv, colpos=0, rowpos=0;
389  int ia=ready, ie=all;
390 
391  do
392  {
393  rowpos++;
394  do
395  {
396  colpos++;
397  rpiv = ivColPivot(imat, colpos, rowpos, ia, ie);
398  } while (rpiv==0);
399  if (rpiv>ia)
400  {
401  if (rowpos!=rpiv)
402  {
403  ivSaveRow(imat, rpiv);
404  ivFreeRow(imat, rowpos, rpiv);
405  ivSetRow(imat, rowpos, colpos);
406  rpiv = rowpos;
407  }
408  ia++;
409  if (ia==imat->cols())
410  {
411  ready = ia;
412  all = ie;
413  return;
414  }
415  }
416  ivReduce(imat, rpiv, colpos, ia, ie);
417  ivZeroElim(imat, colpos, ia, ie);
418  } while (ie>ia);
419  ready = ia;
420  all = ie;
421 }
static void ivZeroElim(intvec *, int, int, int &)
Definition: intvec.cc:546
static void ivFreeRow(intvec *, int, int)
Definition: intvec.cc:504
static void ivSaveRow(intvec *, int)
Definition: intvec.cc:487
static int ivColPivot(intvec *, int, int, int, int)
Definition: intvec.cc:466
static void ivReduce(intvec *, int, int, int, int)
Definition: intvec.cc:515
static void ivSetRow(intvec *, int, int)
Definition: intvec.cc:495
int cols() const
Definition: intvec.h:95