42 #if defined(__cplusplus)
50 #define m_move mesch_m_move
53 #if defined(__MWERKS__) && !defined(_MSC_VER)
56 #include <sys/types.h>
103 extern char *malloc(), *calloc(), *realloc();
105 extern void *malloc(
size_t),
106 *calloc(
size_t,
size_t),
107 *realloc(
void *,
size_t);
120 #define NEW(type) ((type *)calloc(1,sizeof(type)))
123 #define NEW_A(num,type) ((type *)calloc((unsigned)(num),sizeof(type)))
126 #define RENEW(var,num,type) \
127 ((var)=(type *)((var) ? \
128 realloc((char *)(var),(unsigned)(num)*sizeof(type)) : \
129 calloc((unsigned)(num),sizeof(type))))
131 #define MEMCOPY(from,to,n_items,type) \
132 MEM_COPY((char *)(from),(char *)(to),(unsigned)(n_items)*sizeof(type))
136 #define NEW(type) ((type *)calloc((size_t)1,(size_t)sizeof(type)))
139 #define NEW_A(num,type) ((type *)calloc((size_t)(num),(size_t)sizeof(type)))
142 #define RENEW(var,num,type) \
143 ((var)=(type *)((var) ? \
144 realloc((char *)(var),(size_t)((num)*sizeof(type))) : \
145 calloc((size_t)(num),(size_t)sizeof(type))))
147 #define MEMCOPY(from,to,n_items,type) \
148 MEM_COPY((char *)(from),(char *)(to),(unsigned)(n_items)*sizeof(type))
154 #define max(a,b) ((a) > (b) ? (a) : (b))
157 #define min(a,b) ((a) > (b) ? (b) : (a))
213 #define M_FREE(mat) ( m_free(mat), (mat)=(MAT *)NULL )
214 #define V_FREE(vec) ( v_free(vec), (vec)=(VEC *)NULL )
215 #define PX_FREE(px) ( px_free(px), (px)=(PERM *)NULL )
216 #define IV_FREE(iv) ( iv_free(iv), (iv)=(IVEC *)NULL )
225 #define v_entry(x,i) (((i) < 0 || (i) >= (x)->dim) ? \
226 error(E_BOUNDS,"v_entry"), 0.0 : (x)->ve[i] )
229 #define v_set_val(x,i,val) ((x)->ve[i] = ((i) < 0 || (i) >= (x)->dim) ? \
230 error(E_BOUNDS,"v_set_val"), 0.0 : (val))
233 #define v_add_val(x,i,val) ((x)->ve[i] += ((i) < 0 || (i) >= (x)->dim) ? \
234 error(E_BOUNDS,"v_add_val"), 0.0 : (val))
237 #define v_sub_val(x,i,val) ((x)->ve[i] -= ((i) < 0 || (i) >= (x)->dim) ? \
238 error(E_BOUNDS,"v_sub_val"), 0.0 : (val))
241 #define m_entry(A,i,j) (((i) < 0 || (i) >= (A)->m || \
242 (j) < 0 || (j) >= (A)->n) ? \
243 error(E_BOUNDS,"m_entry"), 0.0 : (A)->me[i][j] )
246 #define m_set_val(A,i,j,val) ((A)->me[i][j] = ((i) < 0 || (i) >= (A)->m || \
247 (j) < 0 || (j) >= (A)->n) ? \
248 error(E_BOUNDS,"m_set_val"), 0.0 : (val) )
251 #define m_add_val(A,i,j,val) ((A)->me[i][j] += ((i) < 0 || (i) >= (A)->m || \
252 (j) < 0 || (j) >= (A)->n) ? \
253 error(E_BOUNDS,"m_add_val"), 0.0 : (val) )
256 #define m_sub_val(A,i,j,val) ((A)->me[i][j] -= ((i) < 0 || (i) >= (A)->m || \
257 (j) < 0 || (j) >= (A)->n) ? \
258 error(E_BOUNDS,"m_sub_val"), 0.0 : (val) )
262 #define v_entry(x,i) ((x)->ve[i])
265 #define v_set_val(x,i,val) ((x)->ve[i] = (val))
268 #define v_add_val(x,i,val) ((x)->ve[i] += (val))
271 #define v_sub_val(x,i,val) ((x)->ve[i] -= (val))
274 #define m_entry(A,i,j) ((A)->me[i][j])
277 #define m_set_val(A,i,j,val) ((A)->me[i][j] = (val) )
280 #define m_add_val(A,i,j,val) ((A)->me[i][j] += (val) )
283 #define m_sub_val(A,i,j,val) ((A)->me[i][j] -= (val) )
336 int fin_int(FILE *
fp,
char *s,
int low,
int high);
343 double fin_double(FILE *
fp,
char *s,
double low,
double high);
355 #define v_output(vec) v_foutput(stdout,vec)
356 #define v_input(vec) v_finput(stdin,vec)
357 #define m_output(mat) m_foutput(stdout,mat)
358 #define m_input(mat) m_finput(stdin,mat)
359 #define px_output(px) px_foutput(stdout,px)
360 #define px_input(px) px_finput(stdin,px)
361 #define iv_output(iv) iv_foutput(stdout,iv)
362 #define iv_input(iv) iv_finput(stdin,iv)
365 #define finput(fp,prompt,fmt,var) \
366 ( ( isatty(fileno(fp)) ? fprintf(stderr,prompt) : skipjunk(fp) ), \
368 #define input(prompt,fmt,var) finput(stdin,prompt,fmt,var)
369 #define fprompter(fp,prompt) \
370 ( isatty(fileno(fp)) ? fprintf(stderr,prompt) : skipjunk(fp) )
371 #define prompter(prompt) fprompter(stdin,prompt)
372 #define y_or_n(s) fy_or_n(stdin,s)
373 #define in_int(s,lo,hi) fin_int(stdin,s,lo,hi)
374 #define in_double(s,lo,hi) fin_double(stdin,s,lo,hi)
403 #define m_copy(in,out) _m_copy(in,out,0,0)
404 #define v_copy(in,out) _v_copy(in,out,0)
441 #ifdef PROTOTYPES_IN_STRUCT
485 #define in_prod(a,b) _in_prod(a,b,0)
510 #define v_norm1(x) _v_norm1(x,VNULL)
511 #define v_norm2(x) _v_norm2(x,VNULL)
512 #define v_norm_inf(x) _v_norm_inf(x,VNULL)
562 #define set_row(mat,row,vec) _set_row(mat,row,vec,0)
564 #define set_col(mat,col,vec) _set_col(mat,col,vec,0)
631 #define VNULL ((VEC *)NULL)
632 #define MNULL ((MAT *)NULL)
633 #define PNULL ((PERM *)NULL)
634 #define IVNULL ((IVEC *)NULL)
635 #define BDNULL ((BAND *)NULL)
685 #if defined(__cplusplus)
static double order(void *v)
void __sub__(Real *, Real *, Real *, int)
VEC * v_map(double(*f)(), VEC *, VEC *)
PERM * px_mlt(PERM *px1, PERM *px2, PERM *out)
IVEC * iv_add(IVEC *ix, IVEC *iy, IVEC *out)
VEC * v_slash(VEC *, VEC *, VEC *)
void iv_foutput(FILE *fp, IVEC *ix)
MAT * px_rows(PERM *px, MAT *A, MAT *out)
double _v_norm1(VEC *x, VEC *scale)
VEC * vm_mlt(MAT *, VEC *, VEC *)
IVEC * iv_resize(IVEC *, int)
PERM * px_transp(PERM *px, u_int i, u_int j)
VEC * v_linlist(VEC *out, VEC *v1, double a1,...)
double v_min(VEC *, int *)
void iv_dump(FILE *fp, IVEC *ix)
BAND * bd_resize(BAND *, int, int, int)
double m_norm_frob(MAT *A)
VEC * v_sub(VEC *, VEC *, VEC *)
void px_foutput(FILE *fp, PERM *px)
MAT * _set_col(MAT *A, u_int i, VEC *out, u_int j0)
VEC * v_move(VEC *in, int, int, VEC *out, int)
VEC * _v_map(double(*f)(), void *, VEC *, VEC *)
int fin_int(FILE *fp, char *s, int low, int high)
int px_get_vars(int dim,...)
int iv_free_vars(IVEC **,...)
MAT * vm_move(VEC *in, int, MAT *out, int, int, int, int)
PERM * px_copy(PERM *in, PERM *out)
void __smlt__(Real *, double, Real *, int)
MAT * m_resize(MAT *, int, int)
VEC * px_vec(PERM *, VEC *, VEC *)
void m_foutput(FILE *fp, MAT *A)
MAT * m_sub(MAT *A, MAT *B, MAT *out)
IVEC * iv_sub(IVEC *ix, IVEC *iy, IVEC *out)
MAT * m_add(MAT *A, MAT *B, MAT *out)
BAND * bd_copy(BAND *in, BAND *out)
MAT * m_transp(MAT *A, MAT *out)
VEC * v_sort(VEC *, PERM *)
VEC * get_row(MAT *, u_int, VEC *)
double _v_norm2(VEC *x, VEC *scale)
MAT * mtrm_mlt(MAT *A, MAT *B, MAT *out)
MAT * sub_mat(MAT *A, u_int, u_int, u_int, u_int, MAT *out)
int iv_resize_vars(int new_dim,...)
int px_free_vars(PERM **,...)
PERM * px_finput(FILE *fp, PERM *out)
void m_dump(FILE *fp, MAT *a)
int m_get_vars(int m, int n,...)
int v_resize_vars(int new_dim,...)
BAND * mat2band(MAT *A, int lb, int ub, BAND *bA)
IVEC * iv_finput(FILE *fp, IVEC *out)
double v_max(VEC *, int *)
MAT * swap_rows(MAT *, int, int, int, int)
BAND * bd_transp(BAND *in, BAND *out)
double fin_double(FILE *fp, char *s, double low, double high)
int iv_get_vars(int dim,...)
MAT * sm_mlt(double s, MAT *A, MAT *out)
int m_resize_vars(int m, int n,...)
VEC * v_lincomb(int, VEC **, Real *, VEC *)
MAT * band2mat(BAND *bA, MAT *A)
VEC * _v_copy(VEC *in, VEC *out, u_int i0)
BAND * bd_get(int, int, int)
IVEC * iv_sort(IVEC *ix, PERM *order)
int v_free_vars(VEC **,...)
PERM * px_resize(PERM *, int)
VEC * v_add(VEC *, VEC *, VEC *)
void mrandlist(Real *x, int len)
MAT * _set_row(MAT *A, u_int j, VEC *out, u_int i0)
int fy_or_n(FILE *fp, char *s)
int v_get_vars(int dim,...)
VEC * vm_mltadd(VEC *x, VEC *y, MAT *A, double s, VEC *out)
MAT * m_finput(FILE *fp, MAT *out)
int px_resize_vars(int new_dim,...)
void v_dump(FILE *fp, VEC *x)
MAT * mmtr_mlt(MAT *A, MAT *B, MAT *out)
IVEC * iv_copy(IVEC *in, IVEC *out)
MAT * m_mlt(MAT *A, MAT *B, MAT *out)
void px_dump(FILE *, PERM *px)
int m_free_vars(MAT **,...)
IVEC * iv_move(IVEC *in, int, int, IVEC *out, int)
MAT * swap_cols(MAT *, int, int, int, int)
MAT * px_cols(PERM *px, MAT *A, MAT *out)
void __mltadd__(Real *, Real *, double, int)
MAT * ms_mltadd(MAT *A, MAT *B, double s, MAT *out)
void __zero__(Real *, int)
MAT * _m_copy(MAT *in, MAT *out, u_int i0, u_int j0)
VEC * mv_mltadd(VEC *x, VEC *y, MAT *A, double s, VEC *out)
void __add__(Real *, Real *, Real *, int)
VEC * v_mltadd(VEC *, VEC *, double, VEC *)
VEC * pxinv_vec(PERM *, VEC *, VEC *)
VEC * mv_mlt(MAT *, VEC *, VEC *)
double m_norm_inf(MAT *A)
VEC * mv_move(MAT *in, int, int, int, int, VEC *out, int)
double __ip__(Real *, Real *, int)
VEC * sub_vec(VEC *, int, int, VEC *)
VEC * sv_mlt(double, VEC *, VEC *)
PERM * px_inv(PERM *px, PERM *out)
VEC * v_star(VEC *, VEC *, VEC *)
double _in_prod(VEC *x, VEC *y, u_int i0)
VEC * get_col(MAT *, u_int, VEC *)
double _v_norm_inf(VEC *x, VEC *scale)
void v_foutput(FILE *fp, VEC *x)
VEC * v_finput(FILE *fp, VEC *out)
VEC * v_resize(VEC *, int)
int const size_t const size_t n