My Project
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)
 
intvecivAddShift (intvec *a, intvec *b, int s)
 
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 169 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_max(const int a, const int b)
Definition: auxiliary.h:124
static int si_min(const int a, const int b)
Definition: auxiliary.h:125
int i
Definition: cfEzgcd.cc:132
CanonicalForm b
Definition: cfModGcd.cc:4103
Definition: intvec.h:23
int cols() const
Definition: intvec.h:95
int rows() const
Definition: intvec.h:96
#define NULL
Definition: omList.c:12

◆ ivAddShift()

intvec * ivAddShift ( intvec a,
intvec b,
int  s 
)

Definition at line 279 of file intvec.cc.

280{
281 if (a->cols() != b->cols()) return NULL;
282 if (a->cols() == 1)
283 {
284 int i;
285 intvec * iv;
286 int ma = si_max(a->rows(),b->rows()+s);
287 iv=new intvec(ma);
288 for (i=a->rows()-1;i>=0;i--)
289 (*iv)[i] = (*a)[i];
290 for(i=b->rows()+s-1;i>=s;i--)
291 (*iv)[i] += (*b)[i-s];
292 return iv;
293 }
294 return NULL;
295}
const CanonicalForm int s
Definition: facAbsFact.cc:51

◆ ivConcat()

intvec * ivConcat ( intvec a,
intvec b 
)

Definition at line 822 of file intvec.cc.

823{
824 int ac=a->cols();
825 int c = ac + b->cols(); int r = si_max(a->rows(),b->rows());
826 intvec * ab = new intvec(r,c,0);
827
828 int i,j;
829 for (i=1; i<=a->rows(); i++)
830 {
831 for(j=1; j<=ac; j++)
832 IMATELEM(*ab,i,j) = IMATELEM(*a,i,j);
833 }
834 for (i=1; i<=b->rows(); i++)
835 {
836 for(j=1; j<=b->cols(); j++)
837 IMATELEM(*ab,i,j+ac) = IMATELEM(*b,i,j);
838 }
839 return ab;
840}
int j
Definition: facHensel.cc:110
#define IMATELEM(M, I, J)
Definition: intvec.h:85

◆ ivCopy()

intvec * ivCopy ( const intvec o)
inline

Definition at line 145 of file intvec.h.

146{
147 if( o != NULL )
148 return new intvec(o);
149 return NULL;
150}

◆ ivMult()

intvec * ivMult ( intvec a,
intvec b 
)

Definition at line 349 of file intvec.cc.

350{
351 int i, j, k, sum,
352 ra = a->rows(), ca = a->cols(),
353 rb = b->rows(), cb = b->cols();
354 intvec * iv;
355 if (ca != rb) return NULL;
356 iv = new intvec(ra, cb, 0);
357 for (i=0; i<ra; i++)
358 {
359 for (j=0; j<cb; j++)
360 {
361 sum = 0;
362 for (k=0; k<ca; k++)
363 sum += (*a)[i*ca+k]*(*b)[k*cb+j];
364 (*iv)[i*cb+j] = sum;
365 }
366 }
367 return iv;
368}
int k
Definition: cfEzgcd.cc:99

◆ ivSolveKern()

intvec * ivSolveKern ( intvec imat,
int  ready 
)

Definition at line 442 of file intvec.cc.

443{
444 int d=imat->cols();
445 int kdim=d-dimtr;
446 intvec *perm = new intvec(dimtr+1);
447 intvec *kern = new intvec(kdim,d,0);
448 intvec *res;
449 int c, cp, r, t;
450
451 t = kdim;
452 c = 1;
453 for (r=1;r<=dimtr;r++)
454 {
455 while (IMATELEM(*imat,r,c)==0) c++;
456 (*perm)[r] = c;
457 c++;
458 }
459 c = d;
460 for (r=dimtr;r>0;r--)
461 {
462 cp = (*perm)[r];
463 if (cp!=c)
464 {
465 ivKernFromRow(kern, imat, perm, t, r, c);
466 t -= (c-cp);
467 if (t==0)
468 break;
469 c = cp-1;
470 }
471 else
472 c--;
473 }
474 if (kdim>1)
475 res = ivOptimizeKern(kern);
476 else
477 res = ivTranp(kern);
478 delete kern;
479 delete perm;
480 return res;
481}
CanonicalForm res
Definition: facAbsFact.cc:60
static intvec * ivOptimizeKern(intvec *)
Definition: intvec.cc:669
static void ivKernFromRow(intvec *, intvec *, intvec *, int, int, int)
Definition: intvec.cc:613
intvec * ivTranp(intvec *o)
Definition: intvec.cc:327

◆ ivSub()

intvec * ivSub ( intvec a,
intvec b 
)

Definition at line 297 of file intvec.cc.

298{
299 intvec * iv;
300 int mn, ma, i;
301 if (a->cols() != b->cols()) return NULL;
302 mn = si_min(a->rows(),b->rows());
303 ma = si_max(a->rows(),b->rows());
304 if (a->cols() == 1)
305 {
306 iv = new intvec(ma);
307 for (i=0; i<mn; i++) (*iv)[i] = (*a)[i] - (*b)[i];
308 if (ma > mn)
309 {
310 if (ma == a->rows())
311 {
312 for(i=mn; i<ma; i++) (*iv)[i] = (*a)[i];
313 }
314 else
315 {
316 for(i=mn; i<ma; i++) (*iv)[i] = -(*b)[i];
317 }
318 }
319 return iv;
320 }
321 if (mn != ma) return NULL;
322 iv = new intvec(a);
323 for (i=0; i<mn*a->cols(); i++) { (*iv)[i] -= (*b)[i]; }
324 return iv;
325}

◆ ivTrace()

int ivTrace ( intvec o)

Definition at line 339 of file intvec.cc.

340{
341 int i, s = 0, m = si_min(o->rows(),o->cols()), c = o->cols();
342 for (i=0; i<m; i++)
343 {
344 s += (*o)[i*c+i];
345 }
346 return s;
347}
int m
Definition: cfEzgcd.cc:128

◆ ivTranp()

intvec * ivTranp ( intvec o)

Definition at line 327 of file intvec.cc.

328{
329 int i, j, r = o->rows(), c = o->cols();
330 intvec * iv= new intvec(c, r, 0);
331 for (i=0; i<r; i++)
332 {
333 for (j=0; j<c; j++)
334 (*iv)[j*r+i] = (*o)[i*c+j];
335 }
336 return iv;
337}

◆ ivTriangIntern()

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

Definition at line 404 of file intvec.cc.

405{
406 int rpiv, colpos=0, rowpos=0;
407 int ia=ready, ie=all;
408
409 do
410 {
411 rowpos++;
412 do
413 {
414 colpos++;
415 rpiv = ivColPivot(imat, colpos, rowpos, ia, ie);
416 } while (rpiv==0);
417 if (rpiv>ia)
418 {
419 if (rowpos!=rpiv)
420 {
421 ivSaveRow(imat, rpiv);
422 ivFreeRow(imat, rowpos, rpiv);
423 ivSetRow(imat, rowpos, colpos);
424 rpiv = rowpos;
425 }
426 ia++;
427 if (ia==imat->cols())
428 {
429 ready = ia;
430 all = ie;
431 return;
432 }
433 }
434 ivReduce(imat, rpiv, colpos, ia, ie);
435 ivZeroElim(imat, colpos, ia, ie);
436 } while (ie>ia);
437 ready = ia;
438 all = ie;
439}
static int ivColPivot(intvec *, int, int, int, int)
Definition: intvec.cc:484
static void ivSetRow(intvec *, int, int)
Definition: intvec.cc:513
static void ivFreeRow(intvec *, int, int)
Definition: intvec.cc:522
static void ivZeroElim(intvec *, int, int, int &)
Definition: intvec.cc:564
static void ivSaveRow(intvec *, int)
Definition: intvec.cc:505
static void ivReduce(intvec *, int, int, int, int)
Definition: intvec.cc:533