lisp-stat-model package (still need to add to ASDF).
[CommonLispStat.git] / lib / linalgdata.c
blobdb1bcc722ccf2eb1c15f0cf22cffff20b9cfb07b
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(size_t, size_t);
13 extern void la_free_alloc(PTR);
14 extern void xlfail(char *);
16 /************************************************************************/
17 /** **/
18 /** Storage Allocation Functions **/
19 /** **/
20 /************************************************************************/
22 static char
23 *allocate(size_t n, size_t m)
25 char *p = (char *) la_allocate(n, m);
26 if (p == nil) xlfail("allocation failed");
27 return(p);
30 static void
31 free_alloc(char *p)
33 if (p != nil) la_free_alloc((PTR) p);
36 IVector
37 ivector(size_t n)
39 return((IVector) allocate(n, sizeof(int)));
42 double
43 *rvector(size_t n)
45 return((double *) allocate(n, sizeof(double)));
48 CVector cvector(size_t n)
50 return((CVector) allocate(n, sizeof(Complex)));
53 void
54 free_vector(double *v)
56 free_alloc((char *)v);
59 IMatrix imatrix(size_t n, size_t m)
61 size_t i;
62 IMatrix mat = (IMatrix) allocate(n, sizeof(IVector));
63 for (i = 0; i < n; i++) mat[i] = (IVector) allocate(m, sizeof(int));
64 return(mat);
67 RMatrix
68 rmatrix(size_t n, size_t m)
70 size_t i;
71 RMatrix mat = (RMatrix) allocate(n, sizeof(RVector));
72 for (i = 0; i < n; i++) mat[i] = (RVector) allocate(m, sizeof(double));
73 return(mat);
76 CMatrix
77 cmatrix(size_t n, size_t m)
79 size_t i;
80 CMatrix mat = (CMatrix) allocate(n, sizeof(CVector));
81 for (i = 0; i < n; i++) mat[i] = (CVector) allocate(m, sizeof(Complex));
82 return(mat);
85 void
86 free_matrix(double **mat, int n) /* Matrix?? Not RMatrix?? */
88 size_t i;
90 if (mat != nil) for (i = 0; i < n; i++) free_alloc((char *)mat[i]);
91 free_alloc((char *)mat);