1 /* linalgdata - allocation support for basic linear algebra routines. */
2 /* Copyright (c) 1990, by Luke Tierney */
12 extern PTR
la_allocate(int, int);
13 extern void la_free_alloc(PTR
);
14 extern void xlfail(char *);
17 /************************************************************************/
19 /** Storage Allocation Functions **/
21 /************************************************************************/
24 *allocate(unsigned n
, unsigned m
)
26 char *p
= (char *) la_allocate(n
, m
);
27 if (p
== nil
) xlfail("allocation failed");
34 if (p
!= nil
) la_free_alloc((PTR
) p
);
40 return((IVector
) allocate(n
, sizeof(int)));
46 return((double *) allocate(n
, sizeof(double)));
52 return((CVector
) allocate(n
, sizeof(Complex
)));
56 free_vector(double *v
)
58 free_alloc((char *)v
);
61 IMatrix
imatrix(unsigned n
, unsigned m
)
64 IMatrix mat
= (IMatrix
) allocate(n
, sizeof(IVector
));
65 for (i
= 0; i
< n
; i
++) mat
[i
] = (IVector
) allocate(m
, sizeof(int));
70 rmatrix(unsigned n
, unsigned m
)
73 RMatrix mat
= (RMatrix
) allocate(n
, sizeof(RVector
));
74 for (i
= 0; i
< n
; i
++) mat
[i
] = (RVector
) allocate(m
, sizeof(double));
79 cmatrix(unsigned n
, unsigned m
)
82 CMatrix mat
= (CMatrix
) allocate(n
, sizeof(CVector
));
83 for (i
= 0; i
< n
; i
++) mat
[i
] = (CVector
) allocate(m
, sizeof(Complex
));
88 free_matrix(double **mat
, int n
) /* Matrix?? Not RMatrix?? */
92 if (mat
!= nil
) for (i
= 0; i
< n
; i
++) free_alloc((char *)mat
[i
]);
93 free_alloc((char *)mat
);