/* ** matrices.c 4/99 ** ** Definition and Minipulation of integer and double matrices and vectors. ** vectors are simply C-vectors (with indices starting at zero) and matrices ** are stored Numerical Recepies style -- as a vector of pointers to the ** rows of the matrix [which are themselves just regular C vectors]. ** ** TiGERS, Toric Groebner Basis Enumeration by Reverse Search ** copyright (c) 1999 Birk Huber ** */ #include #include #include "utils.h" #include "matrices.h" /* ** Integer Matrices: ** new_imatrix(int r, int c) -- reserve storage for a rxc matrix of integers ** free_imatrix(*M) -- free storage allocated with new_imatrix() ** ** integer matrix is given by the integers r,c and a vector M of rows ** ** example r=4, c=3 ** _____________________________ ** M= | row0 | row1 | row 2| row 3 | pointers to rows ** ---|--------|-------|---- --| ** | | \ \ ** _____________________________________ ** |e0|e1|e2|e3|e4|e5|e6|e7|e8|e9|e10|e11| vector of elements ** ------------------------------------- ** */ int **new_imatrix(int r, int c){ int **tmp=0; int i,m=r,n=c; /* get space for pointers to rows*/ if ((tmp=(int **)malloc(m*sizeof(int *)))==0){ fprintf(stderr,"memory failure 1 in new_imatrix()\n"); abort(); } /* get space for all entrees -- store in pointer to first row*/ if ((tmp[0]=(int *)malloc(n*m*sizeof(int)))==0){ fprintf(stderr,"memory failure 2 in new_imatrix()\n"); free((void *)tmp); abort(); } /* set remaining row pointers into entry space*/ for(i=1;i