update lift to 29.11.2007 version
[CommonLispStat.git] / lib / linalgdata.c
blob85a9e685fb54fce54b1916c4505733027a2805bb
1 /* linalgdata - allocation support for basic linear algebra routines. */
2 /* Copyright (c) 1990, by Luke Tierney */
4 #include "linalg.h"
6 #ifdef INTPTR
7 typedef int PTR;
8 #else
9 typedef char *PTR;
10 #endif
12 extern PTR la_allocate(int, int);
13 extern void la_free_alloc(PTR);
14 extern void xlfail(char *);
17 /************************************************************************/
18 /** **/
19 /** Storage Allocation Functions **/
20 /** **/
21 /************************************************************************/
23 static char
24 *allocate(unsigned n, unsigned m)
26 char *p = (char *) la_allocate(n, m);
27 if (p == nil) xlfail("allocation failed");
28 return(p);
31 static void
32 free_alloc(char *p)
34 if (p != nil) la_free_alloc((PTR) p);
37 IVector
38 ivector(unsigned n)
40 return((IVector) allocate(n, sizeof(int)));
43 double
44 *rvector(unsigned n)
46 return((double *) allocate(n, sizeof(double)));
49 CVector cvector(n)
50 unsigned n;
52 return((CVector) allocate(n, sizeof(Complex)));
55 void
56 free_vector(double *v)
58 free_alloc((char *)v);
61 IMatrix imatrix(unsigned n, unsigned m)
63 int i;
64 IMatrix mat = (IMatrix) allocate(n, sizeof(IVector));
65 for (i = 0; i < n; i++) mat[i] = (IVector) allocate(m, sizeof(int));
66 return(mat);
69 RMatrix
70 rmatrix(unsigned n, unsigned m)
72 int i;
73 RMatrix mat = (RMatrix) allocate(n, sizeof(RVector));
74 for (i = 0; i < n; i++) mat[i] = (RVector) allocate(m, sizeof(double));
75 return(mat);
78 CMatrix
79 cmatrix(unsigned n, unsigned m)
81 int i;
82 CMatrix mat = (CMatrix) allocate(n, sizeof(CVector));
83 for (i = 0; i < n; i++) mat[i] = (CVector) allocate(m, sizeof(Complex));
84 return(mat);
87 void
88 free_matrix(double **mat, int n) /* Matrix?? Not RMatrix?? */
90 int i;
92 if (mat != nil) for (i = 0; i < n; i++) free_alloc((char *)mat[i]);
93 free_alloc((char *)mat);