NEURON
matrix.h
Go to the documentation of this file.
1 
2 /**************************************************************************
3 **
4 ** Copyright (C) 1993 David E. Steward & Zbigniew Leyk, all rights reserved.
5 **
6 ** Meschach Library
7 **
8 ** This Meschach Library is provided "as is" without any express
9 ** or implied warranty of any kind with respect to this software.
10 ** In particular the authors shall not be liable for any direct,
11 ** indirect, special, incidental or consequential damages arising
12 ** in any way from use of the software.
13 **
14 ** Everyone is granted permission to copy, modify and redistribute this
15 ** Meschach Library, provided:
16 ** 1. All copies contain this copyright notice.
17 ** 2. All modified copies shall carry a notice stating who
18 ** made the last modification and the date of such modification.
19 ** 3. No charge is made for this software or works derived from it.
20 ** This clause shall not be construed as constraining other software
21 ** distributed on the same medium as this software, nor is a
22 ** distribution fee considered a charge.
23 **
24 ***************************************************************************
25 
26 Date Author Modification
27 18 Feb 2000 Gary Holt Removed definition of u_int since it's now
28  handled in config.h. Was causing compilation
29  warnings unnecessarily.
30 */
31 
32 /*
33  Type definitions for general purpose maths package
34 */
35 
36 #ifndef MATRIXH
37 
38 /* RCS id: $Id: matrix.h 616 2004-04-24 21:28:33Z hines $ */
39 
40 #define MATRIXH
41 
42 #if defined(__cplusplus)
43 extern "C" {
44 #endif
45 
46 #include "machine.h"
47 #include "err.h"
48 #include "meminfo.h"
49 
50 #define m_move mesch_m_move
51 #define OUT mesch_out
52 
53 #if defined(__MWERKS__) && !defined(_MSC_VER)
54 #include <types.h>
55 #else
56 #include <sys/types.h>
57 #endif
58 /* unsigned integer type */
59 /* This is no longer needed; it's defined in config.h if the compiler hasn't
60  * defined it already. */
61 /* #ifndef U_INT_DEF */
62 /* typedef unsigned int u_int; */
63 /* #define U_INT_DEF */
64 /* #endif */
65 
66 /* vector definition */
67 typedef struct {
68  u_int dim, max_dim;
69  Real *ve;
70  } VEC;
71 
72 /* matrix definition */
73 typedef struct {
74  u_int m, n;
75  u_int max_m, max_n, max_size;
76  Real **me,*base; /* base is base of alloc'd mem */
77  } MAT;
78 
79 /* band matrix definition */
80 typedef struct {
81  MAT *mat; /* matrix */
82  int lb,ub; /* lower and upper bandwidth */
83  } BAND;
84 
85 
86 /* permutation definition */
87 typedef struct {
88  u_int size, max_size, *pe;
89  } PERM;
90 
91 /* integer vector definition */
92 typedef struct {
93  u_int dim, max_dim;
94  int *ive;
95  } IVEC;
96 
97 
98 #if 1
99 #include <stdlib.h>
100 #else
101 #ifndef MALLOCDECL
102 #ifndef ANSI_C
103 extern char *malloc(), *calloc(), *realloc();
104 #else
105 extern void *malloc(size_t),
106  *calloc(size_t,size_t),
107  *realloc(void *,size_t);
108 #endif
109 #endif
110 #endif
111 
112 #ifndef ANSI_C
113 extern void m_version();
114 #else
115 void m_version( void );
116 #endif
117 
118 #ifndef ANSI_C
119 /* allocate one object of given type */
120 #define NEW(type) ((type *)calloc(1,sizeof(type)))
121 
122 /* allocate num objects of given type */
123 #define NEW_A(num,type) ((type *)calloc((unsigned)(num),sizeof(type)))
124 
125  /* re-allocate arry to have num objects of the given 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))))
130 
131 #define MEMCOPY(from,to,n_items,type) \
132  MEM_COPY((char *)(from),(char *)(to),(unsigned)(n_items)*sizeof(type))
133 
134 #else
135 /* allocate one object of given type */
136 #define NEW(type) ((type *)calloc((size_t)1,(size_t)sizeof(type)))
137 
138 /* allocate num objects of given type */
139 #define NEW_A(num,type) ((type *)calloc((size_t)(num),(size_t)sizeof(type)))
140 
141  /* re-allocate arry to have num objects of the given 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))))
146 
147 #define MEMCOPY(from,to,n_items,type) \
148  MEM_COPY((char *)(from),(char *)(to),(unsigned)(n_items)*sizeof(type))
149 
150 #endif
151 
152 /* type independent min and max operations */
153 #ifndef max
154 #define max(a,b) ((a) > (b) ? (a) : (b))
155 #endif
156 #ifndef min
157 #define min(a,b) ((a) > (b) ? (b) : (a))
158 #endif
159 
160 
161 #undef TRUE
162 #define TRUE 1
163 #undef FALSE
164 #define FALSE 0
165 
166 
167 /* for input routines */
168 #define MAXLINE 81
169 
170 
171 /* Dynamic memory allocation */
172 
173 /* Should use M_FREE/V_FREE/PX_FREE in programs instead of m/v/px_free()
174  as this is considerably safer -- also provides a simple type check ! */
175 
176 #ifndef ANSI_C
177 
178 extern VEC *v_get(), *v_resize();
179 extern MAT *m_get(), *m_resize();
180 extern PERM *px_get(), *px_resize();
181 extern IVEC *iv_get(), *iv_resize();
182 extern int m_free(),v_free();
183 extern int px_free();
184 extern int iv_free();
185 extern BAND *bd_get(), *bd_resize();
186 extern int bd_free();
187 
188 #else
189 
190 /* get/resize vector to given dimension */
191 extern VEC *v_get(int), *v_resize(VEC *,int);
192 /* get/resize matrix to be m x n */
193 extern MAT *m_get(int,int), *m_resize(MAT *,int,int);
194 /* get/resize permutation to have the given size */
195 extern PERM *px_get(int), *px_resize(PERM *,int);
196 /* get/resize an integer vector to given dimension */
197 extern IVEC *iv_get(int), *iv_resize(IVEC *,int);
198 /* get/resize a band matrix to given dimension */
199 extern BAND *bd_get(int,int,int), *bd_resize(BAND *,int,int,int);
200 
201 /* free (de-allocate) (band) matrices, vectors, permutations and
202  integer vectors */
203 extern int iv_free(IVEC *);
204 extern int m_free(MAT *),v_free(VEC *),px_free(PERM *);
205 extern int bd_free(BAND *);
206 
207 #endif
208 
209 
210 /* MACROS */
211 
212 /* macros that also check types and sets pointers to NULL */
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 )
217 
218 #define MAXDIM 2001
219 
220 
221 /* Entry level access to data structures */
222 #ifdef DEBUG
223 
224 /* returns x[i] */
225 #define v_entry(x,i) (((i) < 0 || (i) >= (x)->dim) ? \
226  error(E_BOUNDS,"v_entry"), 0.0 : (x)->ve[i] )
227 
228 /* x[i] <- val */
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))
231 
232 /* x[i] <- x[i] + 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))
235 
236 /* x[i] <- x[i] - 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))
239 
240 /* returns A[i][j] */
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] )
244 
245 /* A[i][j] <- val */
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) )
249 
250 /* A[i][j] <- A[i][j] + 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) )
254 
255 /* A[i][j] <- A[i][j] - 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) )
259 #else
260 
261 /* returns x[i] */
262 #define v_entry(x,i) ((x)->ve[i])
263 
264 /* x[i] <- val */
265 #define v_set_val(x,i,val) ((x)->ve[i] = (val))
266 
267 /* x[i] <- x[i] + val */
268 #define v_add_val(x,i,val) ((x)->ve[i] += (val))
269 
270  /* x[i] <- x[i] - val */
271 #define v_sub_val(x,i,val) ((x)->ve[i] -= (val))
272 
273 /* returns A[i][j] */
274 #define m_entry(A,i,j) ((A)->me[i][j])
275 
276 /* A[i][j] <- val */
277 #define m_set_val(A,i,j,val) ((A)->me[i][j] = (val) )
278 
279 /* A[i][j] <- A[i][j] + val */
280 #define m_add_val(A,i,j,val) ((A)->me[i][j] += (val) )
281 
282 /* A[i][j] <- A[i][j] - val */
283 #define m_sub_val(A,i,j,val) ((A)->me[i][j] -= (val) )
284 
285 #endif
286 
287 
288 /* I/O routines */
289 #ifndef ANSI_C
290 
291 extern void v_foutput(),m_foutput(),px_foutput();
292 extern void iv_foutput();
293 extern VEC *v_finput();
294 extern MAT *m_finput();
295 extern PERM *px_finput();
296 extern IVEC *iv_finput();
297 extern int fy_or_n(), fin_int(), yn_dflt(), skipjunk();
298 extern double fin_double();
299 
300 #else
301 
302 /* print x on file fp */
303 void v_foutput(FILE *fp,VEC *x),
304  /* print A on file fp */
305  m_foutput(FILE *fp,MAT *A),
306  /* print px on file fp */
307  px_foutput(FILE *fp,PERM *px);
308 /* print ix on file fp */
309 void iv_foutput(FILE *fp,IVEC *ix);
310 
311 /* Note: if out is NULL, then returned object is newly allocated;
312  Also: if out is not NULL, then that size is assumed */
313 
314 /* read in vector from fp */
315 VEC *v_finput(FILE *fp,VEC *out);
316 /* read in matrix from fp */
317 MAT *m_finput(FILE *fp,MAT *out);
318 /* read in permutation from fp */
319 PERM *px_finput(FILE *fp,PERM *out);
320 /* read in int vector from fp */
321 IVEC *iv_finput(FILE *fp,IVEC *out);
322 
323 /* fy_or_n -- yes-or-no to question in string s
324  -- question written to stderr, input from fp
325  -- if fp is NOT a tty then return y_n_dflt */
326 int fy_or_n(FILE *fp,char *s);
327 
328 /* yn_dflt -- sets the value of y_n_dflt to val */
329 int yn_dflt(int val);
330 
331 /* fin_int -- return integer read from file/stream fp
332  -- prompt s on stderr if fp is a tty
333  -- check that x lies between low and high: re-prompt if
334  fp is a tty, error exit otherwise
335  -- ignore check if low > high */
336 int fin_int(FILE *fp,char *s,int low,int high);
337 
338 /* fin_double -- return double read from file/stream fp
339  -- prompt s on stderr if fp is a tty
340  -- check that x lies between low and high: re-prompt if
341  fp is a tty, error exit otherwise
342  -- ignore check if low > high */
343 double fin_double(FILE *fp,char *s,double low,double high);
344 
345 /* it skips white spaces and strings of the form #....\n
346  Here .... is a comment string */
347 int skipjunk(FILE *fp);
348 
349 #endif
350 
351 
352 /* MACROS */
353 
354 /* macros to use stdout and stdin instead of explicit fp */
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)
363 
364 /* general purpose input routine; skips comments # ... \n */
365 #define finput(fp,prompt,fmt,var) \
366  ( ( isatty(fileno(fp)) ? fprintf(stderr,prompt) : skipjunk(fp) ), \
367  fscanf(fp,fmt,var) )
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)
375 
376 /* Copying routines */
377 #ifndef ANSI_C
378 extern MAT *_m_copy(), *m_move(), *vm_move();
379 extern VEC *_v_copy(), *v_move(), *mv_move();
380 extern PERM *px_copy();
381 extern IVEC *iv_copy(), *iv_move();
382 extern BAND *bd_copy();
383 
384 #else
385 
386 /* copy in to out starting at out[i0][j0] */
387 extern MAT *_m_copy(MAT *in,MAT *out,u_int i0,u_int j0),
388  * m_move(MAT *in, int, int, int, int, MAT *out, int, int),
389  *vm_move(VEC *in, int, MAT *out, int, int, int, int);
390 /* copy in to out starting at out[i0] */
391 extern VEC *_v_copy(VEC *in,VEC *out,u_int i0),
392  * v_move(VEC *in, int, int, VEC *out, int),
393  *mv_move(MAT *in, int, int, int, int, VEC *out, int);
394 extern PERM *px_copy(PERM *in,PERM *out);
395 extern IVEC *iv_copy(IVEC *in,IVEC *out),
396  *iv_move(IVEC *in, int, int, IVEC *out, int);
397 extern BAND *bd_copy(BAND *in,BAND *out);
398 
399 #endif
400 
401 
402 /* MACROS */
403 #define m_copy(in,out) _m_copy(in,out,0,0)
404 #define v_copy(in,out) _v_copy(in,out,0)
405 
406 
407 /* Initialisation routines -- to be zero, ones, random or identity */
408 #ifndef ANSI_C
409 extern VEC *v_zero(), *v_rand(), *v_ones();
410 extern MAT *m_zero(), *m_ident(), *m_rand(), *m_ones();
411 extern PERM *px_ident();
412 extern IVEC *iv_zero();
413 #else
414 extern VEC *v_zero(VEC *), *v_rand(VEC *), *v_ones(VEC *);
415 extern MAT *m_zero(MAT *), *m_ident(MAT *), *m_rand(MAT *),
416  *m_ones(MAT *);
417 extern PERM *px_ident(PERM *);
418 extern IVEC *iv_zero(IVEC *);
419 #endif
420 
421 /* Basic vector operations */
422 #ifndef ANSI_C
423 extern VEC *sv_mlt(), *mv_mlt(), *vm_mlt(), *v_add(), *v_sub(),
424  *px_vec(), *pxinv_vec(), *v_mltadd(), *v_map(), *_v_map(),
425  *v_lincomb(), *v_linlist();
426 extern double v_min(), v_max(), v_sum();
427 extern VEC *v_star(), *v_slash(), *v_sort();
428 extern double _in_prod(), __ip__();
429 extern void __mltadd__(), __add__(), __sub__(),
430  __smlt__(), __zero__();
431 #else
432 
433 extern VEC *sv_mlt(double,VEC *,VEC *), /* out <- s.x */
434  *mv_mlt(MAT *,VEC *,VEC *), /* out <- A.x */
435  *vm_mlt(MAT *,VEC *,VEC *), /* out^T <- x^T.A */
436  *v_add(VEC *,VEC *,VEC *), /* out <- x + y */
437  *v_sub(VEC *,VEC *,VEC *), /* out <- x - y */
438  *px_vec(PERM *,VEC *,VEC *), /* out <- P.x */
439  *pxinv_vec(PERM *,VEC *,VEC *), /* out <- P^{-1}.x */
440  *v_mltadd(VEC *,VEC *,double,VEC *), /* out <- x + s.y */
441 #ifdef PROTOTYPES_IN_STRUCT
442  *v_map(double (*f)(double),VEC *,VEC *),
443  /* out[i] <- f(x[i]) */
444  *_v_map(double (*f)(void *,double),void *,VEC *,VEC *),
445 #else
446  *v_map(double (*f)(),VEC *,VEC *), /* out[i] <- f(x[i]) */
447  *_v_map(double (*f)(),void *,VEC *,VEC *),
448 #endif
449  *v_lincomb(int,VEC **,Real *,VEC *),
450  /* out <- sum_i s[i].x[i] */
451  *v_linlist(VEC *out,VEC *v1,double a1,...);
452  /* out <- s1.x1 + s2.x2 + ... */
453 
454 /* returns min_j x[j] (== x[i]) */
455 extern double v_min(VEC *, int *),
456  /* returns max_j x[j] (== x[i]) */
457  v_max(VEC *, int *),
458  /* returns sum_i x[i] */
459  v_sum(VEC *);
460 
461 /* Hadamard product: out[i] <- x[i].y[i] */
462 extern VEC *v_star(VEC *, VEC *, VEC *),
463  /* out[i] <- x[i] / y[i] */
464  *v_slash(VEC *, VEC *, VEC *),
465  /* sorts x, and sets order so that sorted x[i] = x[order[i]] */
466  *v_sort(VEC *, PERM *);
467 
468 /* returns inner product starting at component i0 */
469 extern double _in_prod(VEC *x,VEC *y,u_int i0),
470  /* returns sum_{i=0}^{len-1} x[i].y[i] */
471  __ip__(Real *,Real *,int);
472 
473 /* see v_mltadd(), v_add(), v_sub() and v_zero() */
474 extern void __mltadd__(Real *,Real *,double,int),
475  __add__(Real *,Real *,Real *,int),
476  __sub__(Real *,Real *,Real *,int),
477  __smlt__(Real *,double,Real *,int),
478  __zero__(Real *,int);
479 
480 #endif
481 
482 
483 /* MACRO */
484 /* usual way of computing the inner product */
485 #define in_prod(a,b) _in_prod(a,b,0)
486 
487 /* Norms */
488 /* scaled vector norms -- scale == NULL implies unscaled */
489 #ifndef ANSI_C
490 
491 extern double _v_norm1(), _v_norm2(), _v_norm_inf(),
493 
494 #else
495  /* returns sum_i |x[i]/scale[i]| */
496 extern double _v_norm1(VEC *x,VEC *scale),
497  /* returns (scaled) Euclidean norm */
498  _v_norm2(VEC *x,VEC *scale),
499  /* returns max_i |x[i]/scale[i]| */
500  _v_norm_inf(VEC *x,VEC *scale);
501 
502 /* unscaled matrix norms */
503 extern double m_norm1(MAT *A), m_norm_inf(MAT *A), m_norm_frob(MAT *A);
504 
505 #endif
506 
507 
508 /* MACROS */
509 /* unscaled vector norms */
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)
513 
514 /* Basic matrix operations */
515 #ifndef ANSI_C
516 
517 extern MAT *sm_mlt(), *m_mlt(), *mmtr_mlt(), *mtrm_mlt(), *m_add(), *m_sub(),
518  *sub_mat(), *m_transp(), *ms_mltadd();
519 
520 extern BAND *bd_transp();
521 extern MAT *px_rows(), *px_cols(), *swap_rows(), *swap_cols(),
522  *_set_row(), *_set_col();
523 extern VEC *get_row(), *get_col(), *sub_vec(),
524  *mv_mltadd(), *vm_mltadd();
525 
526 #else
527 
528 extern MAT *sm_mlt(double s,MAT *A,MAT *out), /* out <- s.A */
529  *m_mlt(MAT *A,MAT *B,MAT *out), /* out <- A.B */
530  *mmtr_mlt(MAT *A,MAT *B,MAT *out), /* out <- A.B^T */
531  *mtrm_mlt(MAT *A,MAT *B,MAT *out), /* out <- A^T.B */
532  *m_add(MAT *A,MAT *B,MAT *out), /* out <- A + B */
533  *m_sub(MAT *A,MAT *B,MAT *out), /* out <- A - B */
535  *m_transp(MAT *A,MAT *out), /* out <- A^T */
536  /* out <- A + s.B */
537  *ms_mltadd(MAT *A,MAT *B,double s,MAT *out);
538 
539 
540 extern BAND *bd_transp(BAND *in, BAND *out); /* out <- A^T */
541 extern MAT *px_rows(PERM *px,MAT *A,MAT *out), /* out <- P.A */
542  *px_cols(PERM *px,MAT *A,MAT *out), /* out <- A.P^T */
543  *swap_rows(MAT *,int,int,int,int),
544  *swap_cols(MAT *,int,int,int,int),
545  /* A[i][j] <- out[j], j >= j0 */
546  *_set_col(MAT *A,u_int i,VEC *out,u_int j0),
547  /* A[i][j] <- out[i], i >= i0 */
548  *_set_row(MAT *A,u_int j,VEC *out,u_int i0);
549 
550 extern VEC *get_row(MAT *,u_int,VEC *),
552  *sub_vec(VEC *,int,int,VEC *),
553  /* out <- x + s.A.y */
554  *mv_mltadd(VEC *x,VEC *y,MAT *A,double s,VEC *out),
555  /* out^T <- x^T + s.y^T.A */
556  *vm_mltadd(VEC *x,VEC *y,MAT *A,double s,VEC *out);
557 #endif
558 
559 
560 /* MACROS */
561 /* row i of A <- vec */
562 #define set_row(mat,row,vec) _set_row(mat,row,vec,0)
563 /* col j of A <- vec */
564 #define set_col(mat,col,vec) _set_col(mat,col,vec,0)
565 
566 
567 /* Basic permutation operations */
568 #ifndef ANSI_C
569 
570 extern PERM *px_mlt(), *px_inv(), *px_transp();
571 extern int px_sign();
572 
573 #else
574 
575 extern PERM *px_mlt(PERM *px1,PERM *px2,PERM *out), /* out <- px1.px2 */
576  *px_inv(PERM *px,PERM *out), /* out <- px^{-1} */
577  /* swap px[i] and px[j] */
578  *px_transp(PERM *px,u_int i,u_int j);
579 
580  /* returns sign(px) = +1 if px product of even # transpositions
581  -1 if ps product of odd # transpositions */
582 extern int px_sign(PERM *);
583 
584 #endif
585 
586 
587 /* Basic integer vector operations */
588 #ifndef ANSI_C
589 
590 extern IVEC *iv_add(), *iv_sub(), *iv_sort();
591 
592 #else
593 
594 extern IVEC *iv_add(IVEC *ix,IVEC *iy,IVEC *out), /* out <- ix + iy */
595  *iv_sub(IVEC *ix,IVEC *iy,IVEC *out), /* out <- ix - iy */
596  /* sorts ix & sets order so that sorted ix[i] = old ix[order[i]] */
597  *iv_sort(IVEC *ix, PERM *order);
598 
599 #endif
600 
601 
602 /* miscellaneous functions */
603 
604 #ifndef ANSI_C
605 
606 extern double square(), cube(), mrand();
607 extern void smrand(), mrandlist();
608 extern void m_dump(), px_dump(), v_dump(), iv_dump();
609 extern MAT *band2mat();
610 extern BAND *mat2band();
611 
612 #else
613 
614 double square(double x), /* returns x^2 */
615  cube(double x), /* returns x^3 */
616  mrand(void); /* returns random # in [0,1) */
617 
618 void smrand(int seed), /* seeds mrand() */
619  mrandlist(Real *x, int len); /* generates len random numbers */
620 
621 void m_dump(FILE *fp,MAT *a), px_dump(FILE *,PERM *px),
622  v_dump(FILE *fp,VEC *x), iv_dump(FILE *fp, IVEC *ix);
623 
624 MAT *band2mat(BAND *bA, MAT *A);
625 BAND *mat2band(MAT *A, int lb,int ub, BAND *bA);
626 
627 #endif
628 
629 
630 /* miscellaneous constants */
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)
636 
637 
638 
639 /* varying number of arguments */
640 
641 #ifdef ANSI_C
642 #include <stdarg.h>
643 
644 /* prototypes */
645 
646 int v_get_vars(int dim,...);
647 int iv_get_vars(int dim,...);
648 int m_get_vars(int m,int n,...);
649 int px_get_vars(int dim,...);
650 
651 int v_resize_vars(int new_dim,...);
652 int iv_resize_vars(int new_dim,...);
653 int m_resize_vars(int m,int n,...);
654 int px_resize_vars(int new_dim,...);
655 
656 int v_free_vars(VEC **,...);
657 int iv_free_vars(IVEC **,...);
658 int px_free_vars(PERM **,...);
659 int m_free_vars(MAT **,...);
660 
661 #elif VARARGS
662 /* old varargs is used */
663 
664 #include <varargs.h>
665 
666 /* prototypes */
667 
668 int v_get_vars();
669 int iv_get_vars();
670 int m_get_vars();
671 int px_get_vars();
672 
673 int v_resize_vars();
674 int iv_resize_vars();
675 int m_resize_vars();
676 int px_resize_vars();
677 
678 int v_free_vars();
679 int iv_free_vars();
680 int px_free_vars();
681 int m_free_vars();
682 
683 #endif
684 
685 #if defined(__cplusplus)
686 }
687 #endif
688 
689 #endif
690 
691 
static Frame * fp
Definition: code.cpp:161
static double order(void *v)
Definition: cvodeobj.cpp:239
#define Real
Definition: machine.h:189
uint32_t u_int
Definition: machine.h:38
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)
Definition: ivecop.c:219
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)
Definition: ivecop.c:96
PERM * px_transp(PERM *px, u_int i, u_int j)
Definition: pxop.c:208
VEC * v_linlist(VEC *out, VEC *v1, double a1,...)
Definition: vecop.c:269
double v_min(VEC *, int *)
void iv_dump(FILE *fp, IVEC *ix)
Definition: ivecop.c:326
BAND * bd_resize(BAND *, int, int, int)
Definition: bdfactor.c:95
double m_norm_frob(MAT *A)
Definition: norm.c:181
double mrand(void)
Definition: init.c:148
VEC * v_sub(VEC *, VEC *, VEC *)
void px_foutput(FILE *fp, PERM *px)
Definition: matrixio.c:422
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)
Definition: otherio.c:85
int px_get_vars(int dim,...)
Definition: memory.c:551
int iv_free_vars(IVEC **,...)
Definition: memory.c:683
IVEC * iv_get(int)
VEC * v_rand(VEC *)
MAT * vm_move(VEC *in, int, MAT *out, int, int, int, int)
Definition: copy.c:188
PERM * px_copy(PERM *in, PERM *out)
Definition: copy.c:79
void __smlt__(Real *, double, Real *, int)
MAT * m_resize(MAT *, int, int)
Definition: memory.c:262
VEC * px_vec(PERM *, VEC *, VEC *)
int bd_free(BAND *)
Definition: bdfactor.c:74
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)
double square(double x)
MAT * m_add(MAT *A, MAT *B, MAT *out)
BAND * bd_copy(BAND *in, BAND *out)
Definition: bdfactor.c:156
MAT * m_transp(MAT *A, MAT *out)
VEC * v_sort(VEC *, PERM *)
Definition: vecop.c:466
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,...)
Definition: memory.c:601
VEC * v_get(int)
int px_free_vars(PERM **,...)
Definition: memory.c:703
PERM * px_finput(FILE *fp, PERM *out)
Definition: matrixio.c:185
void m_dump(FILE *fp, MAT *a)
PERM * px_get(int)
int m_get_vars(int m, int n,...)
Definition: memory.c:535
int v_resize_vars(int new_dim,...)
Definition: memory.c:583
int skipjunk(FILE *fp)
Definition: matrixio.c:47
double v_sum(VEC *)
Definition: vecop.c:545
MAT * m_rand(MAT *)
PERM * px_ident(PERM *)
Definition: init.c:108
BAND * mat2band(MAT *A, int lb, int ub, BAND *bA)
Definition: bdfactor.c:218
IVEC * iv_finput(FILE *fp, IVEC *out)
Definition: ivecop.c:245
double v_max(VEC *, int *)
MAT * swap_rows(MAT *, int, int, int, int)
BAND * bd_transp(BAND *in, BAND *out)
Definition: bdfactor.c:253
double fin_double(FILE *fp, char *s, double low, double high)
Definition: otherio.c:124
int iv_get_vars(int dim,...)
Definition: memory.c:519
int iv_free(IVEC *)
Definition: ivecop.c:67
MAT * sm_mlt(double s, MAT *A, MAT *out)
int m_resize_vars(int m, int n,...)
Definition: memory.c:617
VEC * v_lincomb(int, VEC **, Real *, VEC *)
MAT * band2mat(BAND *bA, MAT *A)
Definition: bdfactor.c:187
VEC * _v_copy(VEC *in, VEC *out, u_int i0)
BAND * bd_get(int, int, int)
MAT * m_ident(MAT *)
int v_free(VEC *)
IVEC * iv_zero(IVEC *)
Definition: init.c:55
IVEC * iv_sort(IVEC *ix, PERM *order)
Definition: ivecop.c:359
double cube(double x)
int v_free_vars(VEC **,...)
Definition: memory.c:663
PERM * px_resize(PERM *, int)
Definition: memory.c:399
MAT * m_zero(MAT *)
VEC * v_ones(VEC *)
Definition: init.c:256
double m_norm1(MAT *A)
VEC * v_add(VEC *, VEC *, VEC *)
void mrandlist(Real *x, int len)
int px_free(PERM *)
Definition: memory.c:201
void smrand(int seed)
MAT * _set_row(MAT *A, u_int j, VEC *out, u_int i0)
Definition: submat.c:98
MAT * m_ones(MAT *)
Definition: init.c:271
int fy_or_n(FILE *fp, char *s)
Definition: otherio.c:49
int v_get_vars(int dim,...)
Definition: memory.c:502
VEC * vm_mltadd(VEC *x, VEC *y, MAT *A, double s, VEC *out)
Definition: matop.c:467
MAT * m_finput(FILE *fp, MAT *out)
Definition: matrixio.c:73
int px_resize_vars(int new_dim,...)
Definition: memory.c:634
void v_dump(FILE *fp, VEC *x)
MAT * mmtr_mlt(MAT *A, MAT *B, MAT *out)
#define m_move
Definition: matrix.h:50
int yn_dflt(int val)
Definition: otherio.c:76
IVEC * iv_copy(IVEC *in, IVEC *out)
MAT * m_mlt(MAT *A, MAT *B, MAT *out)
VEC * v_zero(VEC *)
void px_dump(FILE *, PERM *px)
int m_free_vars(MAT **,...)
Definition: memory.c:722
IVEC * iv_move(IVEC *in, int, int, IVEC *out, int)
Definition: ivecop.c:150
MAT * swap_cols(MAT *, int, int, int, int)
MAT * px_cols(PERM *px, MAT *A, MAT *out)
void __mltadd__(Real *, Real *, double, int)
int px_sign(PERM *)
Definition: pxop.c:269
MAT * ms_mltadd(MAT *A, MAT *B, double s, MAT *out)
Definition: matop.c:383
void __zero__(Real *, int)
Definition: machine.c:133
MAT * _m_copy(MAT *in, MAT *out, u_int i0, u_int j0)
void m_version(void)
Definition: version.c:38
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)
Definition: copy.c:160
double __ip__(Real *, Real *, int)
Definition: machine.c:40
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)
Definition: norm.c:104
void v_foutput(FILE *fp, VEC *x)
VEC * v_finput(FILE *fp, VEC *out)
Definition: matrixio.c:295
VEC * v_resize(VEC *, int)
Definition: memory.c:441
MAT * m_get(int, int)
int m_free(MAT *)
#define i
Definition: md1redef.h:12
#define A(i)
Definition: multisplit.cpp:63
#define B(i)
Definition: multisplit.cpp:64
int const size_t const size_t n
Definition: nrngsl.h:11
size_t j
#define MAT
Definition: ocmatrix.h:5
#define PERM
Definition: ocmatrix.h:7
Definition: matrix.h:80
MAT * mat
Definition: matrix.h:81
int lb
Definition: matrix.h:82
Definition: matrix.h:92
int * ive
Definition: matrix.h:94
u_int dim
Definition: matrix.h:93
Definition: matrix.h:73
u_int m
Definition: matrix.h:74
u_int max_m
Definition: matrix.h:75
Real * base
Definition: matrix.h:76
Definition: matrix.h:87
u_int max_size
Definition: matrix.h:88
Definition: matrix.h:67
u_int dim
Definition: matrix.h:68
Real * ve
Definition: matrix.h:69