/* EXPORT->CreateDVector: Allocate space for double vector v[1..size] */ DVector CreateDVector(MemHeap *x, int size) { DVector v; int *i; v = (DVector)New(x,DVectorElemSize(size)); i = (int *) v; *i = size; return v; }
/* EXPORT->CreateDTriMat: Allocate space for double matrix m[1..size][1..i] */ DTriMat CreateDTriMat(MemHeap *x,int size) { int *i,j; DVector *m; char *p; p = (char *) New(x,DTriMatElemSize(size)); i = (int *)p; *i = size; m = (DVector *)p; p += (size+1)*sizeof(DVector); for (j=1;j<=size; j++) { i = (int *) p; *i = j; m[j] = (DVector) p; p += DVectorElemSize(j); } return m; }
/* EXPORT->CreateDMatrix: Allocate space for double matrix m[1..nrows][1..ncols] */ DMatrix CreateDMatrix(MemHeap *x, int nrows,int ncols) { size_t vsize; int *i,j; DVector *m; char *p; p = (char *) New(x,DMatrixElemSize(nrows,ncols)); i = (int *) p; *i = nrows; vsize = DVectorElemSize(ncols); m = (DVector *) p; p += MRound((nrows+1)*sizeof(DVector)); for (j=1; j<=nrows; j++, p += vsize) { i = (int *) p; *i = ncols; m[j] = (DVector) p; } return m; }
size_t DMatrixElemSize(int nrows,int ncols) { return MRound(DVectorElemSize(ncols) * nrows + (nrows+1)*sizeof(DVector)); }
size_t DTriMatElemSize(int size) { return size*(DVectorElemSize(0)*2 + (size+1)*sizeof(double))/2 + (size+1)*sizeof(DVector); }