home *** CD-ROM | disk | FTP | other *** search
- rror(E_MEM,"px_get");
- else if (mem_info_is_on()) {
- mem_bytes(TYPE_PERM,0,size*sizeof(u_int));
- }
-
- for ( i=0; i<size; i++ )
- permute->pe[i] = i;
-
- return (permute);
- }
-
- /* v_get -- gets a VEC of dimension 'dim'
- -- Note: initialized to zero */
- VEC *v_get(size)
- int size;
- {
- VEC *vector;
-
- if (size < 0)
- error(E_NEG,"v_get");
-
- if ((vector=NEW(VEC)) == (VEC *)NULL )
- error(E_MEM,"v_get");
- else if (mem_info_is_on()) {
- mem_bytes(TYPE_VEC,0,sizeof(VEC));
- mem_numvar(TYPE_VEC,1);
- }
-
- vector->dim = vector->max_dim = size;
- if ((vector->ve=NEW_A(size,Real)) == (Real *)NULL )
- {
- free(vector);
- error(E_MEM,"v_get");
- }
- else if (mem_info_is_on()) {
- mem_bytes(TYPE_VEC,0,size*sizeof(Real));
- }
-
- return (vector);
- }
-
- /* m_free -- returns MAT & asoociated memory back to memory heap */
- int m_free(mat)
- MAT *mat;
- {
- #ifdef SEGMENTED
- int i;
- #endif
-
- if ( mat==(MAT *)NULL || (int)(mat->m) < 0 ||
- (int)(mat->n) < 0 )
- /* don't trust it */
- return (-1);
-
- #ifndef SEGMENTED
- if ( mat->base != (Real *)NULL ) {
- if (mem_info_is_on()) {
- mem_bytes(TYPE_MAT,mat->max_m*mat->max_n*sizeof(Real),0);
- }
- free((char *)(mat->base));
- }
- #else
- for ( i = 0; i < mat->max_m; i++ )
- if ( mat->me[i] != (Real *)NULL ) {
- if (mem_info_is_on()) {
- mem_bytes(TYPE_MAT,mat->max_n*sizeof(Real),0);
- }
- free((char *)(mat->me[i]));
- }
- #endif
- if ( mat->me != (Real **)NULL ) {
- if (mem_info_is_on()) {
- mem_bytes(TYPE_MAT,mat->max_m*sizeof(Real *),0);
- }
- free((char *)(mat->me));
- }
-
- if (mem_info_is_on()) {
- mem_bytes(TYPE_MAT,sizeof(MAT),0);
- mem_numvar(TYPE_MAT,-1);
- }
- free((char *)mat);
-
- return (0);
- }
-
-
-
- /* px_free -- returns PERM & asoociated memory back to memory heap */
- int px_free(px)
- PERM *px;
- {
- if ( px==(PERM *)NULL || (int)(px->size) < 0 )
- /* don't trust it */
- return (-1);
-
- if ( px->pe == (u_int *)NULL ) {
- if (mem_info_is_on()) {
- mem_bytes(TYPE_PERM,sizeof(PERM),0);
- mem_numvar(TYPE_PERM,-1);
- }
- free((char *)px);
- }
- else
- {
- if (mem_info_is_on()) {
- mem_bytes(TYPE_PERM,sizeof(PERM)+px->max_size*sizeof(u_int),0);
- mem_numvar(TYPE_PERM,-1);
- }
- free((char *)px->pe);
- free((char *)px);
- }
-
- return (0);
- }
-
-
-
- /* v_free -- returns VEC & asoociated memory back to memory heap */
- int v_free(vec)
- VEC *vec;
- {
- if ( vec==(VEC *)NULL || (int)(vec->dim) < 0 )
- /* don't trust it */
- return (-1);
-
- if ( vec->ve == (Real *)NULL ) {
- if (mem_info_is_on()) {
- mem_bytes(TYPE_VEC,sizeof(VEC),0);
- mem_numvar(TYPE_VEC,-1);
- }
- free((char *)vec);
- }
- else
- {
- if (mem_info_is_on()) {
- mem_bytes(TYPE_VEC,sizeof(VEC)+vec->max_dim*sizeof(Real),0);
- mem_numvar(TYPE_VEC,-1);
- }
- free((char *)vec->ve);
- free((char *)vec);
- }
-
- return (0);
- }
-
-
-
- /* m_resize -- returns the matrix A of size new_m x new_n; A is zeroed
- -- if A == NULL on entry then the effect is equivalent to m_get() */
- MAT *m_resize(A,new_m,new_n)
- MAT *A;
- int new_m, new_n;
- {
- int i;
- int new_max_m, new_max_n, new_size, old_m, old_n;
-
- if (new_m < 0 || new_n < 0)
- error(E_NEG,"m_resize");
-
- if ( ! A )
- return m_get(new_m,new_n);
-
- /* nothing was changed */
- if (new_m == A->m && new_n == A->n)
- return A;
-
- old_m = A->m; old_n = A->n;
- if ( new_m > A->max_m )
- { /* re-allocate A->me */
- if (mem_info_is_on()) {
- mem_bytes(TYPE_MAT,A->max_m*sizeof(Real *),
- new_m*sizeof(Real *));
- }
-
- A->me = RENEW(A->me,new_m,Real *);
- if ( ! A->me )
- error(E_MEM,"m_resize");
- }
- new_max_m = max(new_m,A->max_m);
- new_max_n = max(new_n,A->max_n);
-
- #ifndef SEGMENTED
- new_size = new_max_m*new_max_n;
- if ( new_size > A->max_size )
- { /* re-allocate A->base */
- if (mem_info_is_on()) {
- mem_bytes(TYPE_MAT,A->max_m*A->max_n*sizeof(Real),
- new_size*sizeof(Real));
- }
-
- A->base = RENEW(A->base,new_size,Real);
- if ( ! A->base )
- error(E_MEM,"m_resize");
- A->max_size = new_size;
- }
-
- /* now set up A->me[i] */
- for ( i = 0; i < new_m; i++ )
- A->me[i] = &(A->base[i*new_n]);
-
- /* now shift data in matrix */
- if ( old_n > new_n )
- {
- for ( i = 1; i < min(old_m,new_m); i++ )
- MEM_COPY((char *)&(A->base[i*old_n]),
- (char *)&(A->base[i*new_n]),
- sizeof(Real)*new_n);
- }
- else if ( old_n < new_n )
- {
- for ( i = (int)(min(old_m,new_m))-1; i > 0; i-- )
- { /* copy & then zero extra space */
- MEM_COPY((char *)&(A->base[i*old_n]),
- (char *)&(A->base[i*new_n]),
- sizeof(Real)*old_n);
- __zero__(&(A->base[i*new_n+old_n]),(new_n-old_n));
- }
- __zero__(&(A->base[old_n]),(new_n-old_n));
- A->max_n = new_n;
- }
- /* zero out the new rows.. */
- for ( i = old_m; i < new_m; i++ )
- __zero__(&(A->base[i*new_n]),new_n);
- #else
- if ( A->max_n < new_n )
- {
- Real *tmp;
-
- for ( i = 0; i < A->max_m; i++ )
- {
- if (mem_info_is_on()) {
- mem_bytes(TYPE_MAT,A->max_n*sizeof(Real),
- new_max_n*sizeof(Real));
- }
-
- if ( (tmp = RENEW(A->me[i],new_max_n,Real)) == NULL )
- error(E_MEM,"m_resize");
- else {
- A->me[i] = tmp;
- }
- }
- for ( i = A->max_m; i < new_max_m; i++ )
- {
- if ( (tmp = NEW_A(new_max_n,Real)) == NULL )
- error(E_MEM,"m_resize");
- else {
- A->me[i] = tmp;
-
- if (mem_info_is_on()) {
- mem_bytes(TYPE_MAT,0,new_max_n*sizeof(Real));
- }
- }
- }
- }
- else if ( A->max_m < new_m )
- {
- for ( i = A->max_m; i < new_m; i++ )
- if ( (A->me[i] = NEW_A(new_max_n,Real)) == NULL )
- error(E_MEM,"m_resize");
- else if (mem_info_is_on()) {
- mem_bytes(TYPE_MAT,0,new_max_n*sizeof(Real));
- }
-
- }
-
- if ( old_n < new_n )
- {
- for ( i = 0; i < old_m; i++ )
- __zero__(&(A->me[i][old_n]),new_n-old_n);
- }
-
- /* zero out the new rows.. */
- for ( i = old_m; i < new_m; i++ )
- __zero__(A->me[i],new_n);
- #endif
-
- A->max_m = new_max_m;
- A->max_n = new_max_n;
- A->max_size = A->max_m*A->max_n;
- A->m = new_m; A->n = new_n;
-
- return A;
- }
-
- /* px_resize -- returns the permutation px with size new_size
- -- px is set to the identity permutation */
- PERM *px_resize(px,new_size)
- PERM *px;
- int new_size;
- {
- int i;
-
- if (new_size < 0)
- error(E_NEG,"px_resize");
-
- if ( ! px )
- return px_get(new_size);
-
- /* nothing is changed */
- if (new_size == px->size)
- return px;
-
- if ( new_size > px->max_size )
- {
- if (mem_info_is_on()) {
- mem_bytes(TYPE_PERM,px->max_size*sizeof(u_int),
- new_size*sizeof(u_int));
- }
- px->pe = RENEW(px->pe,new_size,u_int);
- if ( ! px->pe )
- error(E_MEM,"px_resize");
- px->max_size = new_size;
- }
- if ( px->size <= new_size )
- /* extend permutation */
- for ( i = px->size; i < new_size; i++ )
- px->pe[i] = i;
- else
- for ( i = 0; i < new_size; i++ )
- px->pe[i] = i;
-
- px->size = new_size;
-
- return px;
- }
-
- /* v_resize -- returns the vector x with dim new_dim
- -- x is set to the zero vector */
- VEC *v_resize(x,new_dim)
- VEC *x;
- int new_dim;
- {
-
- if (new_dim < 0)
- error(E_NEG,"v_resize");
-
- if ( ! x )
- return v_get(new_dim);
-
- /* nothing is changed */
- if (new_dim == x->dim)
- return x;
-
- if ( x->max_dim == 0 ) /* assume that it's from sub_vec */
- return v_get(new_dim);
-
- if ( new_dim > x->max_dim )
- {
- if (mem_info_is_on()) {
- mem_bytes(TYPE_VEC,x->max_dim*sizeof(Real),
- new_dim*sizeof(Real));
- }
-
- x->ve = RENEW(x->ve,new_dim,Real);
- if ( ! x->ve )
- error(E_MEM,"v_resize");
- x->max_dim = new_dim;
- }
-
- if ( new_dim > x->dim )
- __zero__(&(x->ve[x->dim]),new_dim - x->dim);
- x->dim = new_dim;
-
- return x;
- }
-
-
-
-
- /* Varying number of arguments */
- /* other functions of this type are in sparse.c and zmemory.c */
-
-
-
- #ifdef ANSI_C
-
-
- /* To allocate memory to many arguments.
- The function should be called:
- v_get_vars(dim,&x,&y,&z,...,NULL);
- where
- int dim;
- VEC *x, *y, *z,...;
- The last argument should be NULL !
- dim is the length of vectors x,y,z,...
- returned value is equal to the number of alloegister Real *dp1, *dp2, *out;
- register int len;
- {
- register int i;
- for ( i = 0; i < len; i++ )
- out[i] = dp1[i] + dp2[i];
- }
-
- /* __sub__ -- subtract arrays c.f. v_sub() */
- void __sub__(dp1,dp2,out,len)
- register Real *dp1, *dp2, *out;
- register int len;
- {
- register int i;
- for ( i = 0; i < len; i++ )
- out[i] = dp1[i] - dp2[i];
- }
-
- /* __zero__ -- zeros an array of floating point numbers */
- void __zero__(dp,len)
- register Real *dp;
- register int len;
- {
- #ifdef CHAR0ISDBL0
- /* if a floating point zero is equivalent to a string of nulls */
- MEM_ZERO((char *)dp,len*sizeof(Real));
- #else
- /* else, need to zero the array entry by entry */
- int i;
- for ( i = 0; i < len; i++ )
- dp[i] = 0.0;
- #endif
- }
-
- FileDataŵmatlab Ç Eÿÿÿø☓? ]⇧
- /**************************************************************************
- **
- **