1 /* linalgdata - allocation support for basic linear algebra routines. */
2 /* Copyright (c) 1990, by Luke Tierney */
12 extern PTR
la_allocate(size_t, size_t);
13 extern void la_free_alloc(PTR
);
14 extern void xlfail(char *);
16 /************************************************************************/
18 /** Storage Allocation Functions **/
20 /************************************************************************/
23 *allocate(size_t n
, size_t m
)
25 char *p
= (char *) la_allocate(n
, m
);
26 if (p
== nil
) xlfail("allocation failed");
33 if (p
!= nil
) la_free_alloc((PTR
) p
);
39 return((IVector
) allocate(n
, sizeof(int)));
45 return((double *) allocate(n
, sizeof(double)));
48 CVector
cvector(size_t n
)
50 return((CVector
) allocate(n
, sizeof(Complex
)));
54 free_vector(double *v
)
56 free_alloc((char *)v
);
59 IMatrix
imatrix(size_t n
, size_t m
)
62 IMatrix mat
= (IMatrix
) allocate(n
, sizeof(IVector
));
63 for (i
= 0; i
< n
; i
++) mat
[i
] = (IVector
) allocate(m
, sizeof(int));
68 rmatrix(size_t n
, size_t m
)
71 RMatrix mat
= (RMatrix
) allocate(n
, sizeof(RVector
));
72 for (i
= 0; i
< n
; i
++) mat
[i
] = (RVector
) allocate(m
, sizeof(double));
77 cmatrix(size_t n
, size_t m
)
80 CMatrix mat
= (CMatrix
) allocate(n
, sizeof(CVector
));
81 for (i
= 0; i
< n
; i
++) mat
[i
] = (CVector
) allocate(m
, sizeof(Complex
));
86 free_matrix(double **mat
, int n
) /* Matrix?? Not RMatrix?? */
90 if (mat
!= nil
) for (i
= 0; i
< n
; i
++) free_alloc((char *)mat
[i
]);
91 free_alloc((char *)mat
);