~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina4/src/math/matrix/mat_alloc.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /**@(#)Matrix allocation: function (various types and shapes)
  2  */
  3 
  4 #include <math.h>
  5 #include <stdio.h>
  6 #include <tina/sys.h>
  7 #include <tina/sysfuncs.h>
  8 #include <tina/math.h>
  9 
 10 Matrix *cmatrix_alloc(int m, int n, Matrix_shape shape, Vartype vtype);
 11 Matrix *smatrix_alloc(int m, int n, Matrix_shape shape, Vartype vtype);
 12 Matrix *imatrix_alloc(int m, int n, Matrix_shape shape, Vartype vtype);
 13 Matrix *fmatrix_alloc(int m, int n, Matrix_shape shape, Vartype vtype);
 14 Matrix *dmatrix_alloc(int m, int n, Matrix_shape shape, Vartype vtype);
 15 Matrix *zmatrix_alloc(int m, int n, Matrix_shape shape, Vartype vtype);
 16 Matrix *pmatrix_alloc(int m, int n, Matrix_shape shape, Vartype vtype);
 17 
 18 Matrix *mat_alloc(int m, int n)
 19 {
 20     Matrix *mat;
 21 
 22     mat = ts_ralloc(Matrix);
 23     mat->m = m;
 24     mat->n = n;
 25     mat->shape = matrix_full;
 26     mat->vtype = float_v;
 27     mat->el.float_v = farray_alloc(0, 0, m, n);
 28     return (mat);
 29 }
 30 
 31 Matrix *matrix_alloc(int m, int n, Matrix_shape shape, Vartype vtype)
 32 {
 33     if (m < 0 || n < 0)
 34     {
 35         error("matrix_alloc: bad size", non_fatal);
 36         return (NULL);
 37     }
 38     if (m == 0 || n == 0)
 39     {
 40         error("matrix_alloc: zero size", warning);
 41         return (NULL);
 42     }
 43     switch (vtype)
 44     {
 45     case char_v:
 46     case uchar_v:
 47         return (cmatrix_alloc(m, n, shape, vtype));
 48     case short_v:
 49     case ushort_v:
 50         return (smatrix_alloc(m, n, shape, vtype));
 51     case int_v:
 52     case uint_v:
 53         return (imatrix_alloc(m, n, shape, vtype));
 54     case float_v:
 55         return (fmatrix_alloc(m, n, shape, vtype));
 56     case double_v:
 57         return (dmatrix_alloc(m, n, shape, vtype));
 58     case complex_v:
 59         return (zmatrix_alloc(m, n, shape, vtype));
 60     case ptr_v:
 61         return (pmatrix_alloc(m, n, shape, vtype));
 62     }
 63     error("matrix_alloc: no such vtype", non_fatal);
 64     return (NULL);
 65 }
 66 
 67 Matrix *cmatrix_alloc(int m, int n, Matrix_shape shape, Vartype vtype)
 68 {
 69     Matrix *mat;
 70 
 71     mat = ts_ralloc(Matrix);
 72     mat->m = m;
 73     mat->n = n;
 74     mat->shape = shape;
 75     mat->vtype = vtype;
 76     switch (shape)
 77     {
 78     case matrix_full:
 79         mat->el.char_v = carray_alloc(0, 0, m, n);
 80         break;
 81     case matrix_lower:
 82     case matrix_symmetric:
 83         mat->el.char_v = clower_alloc(0, m);
 84         break;
 85     case matrix_upper:
 86         mat->el.char_v = cupper_alloc(0, m);
 87         break;
 88     default:                    /** full **/
 89         mat->el.char_v = carray_alloc(0, 0, m, n);
 90         break;
 91     }
 92     return (mat);
 93 }
 94 
 95 Matrix *smatrix_alloc(int m, int n, Matrix_shape shape, Vartype vtype)
 96 {
 97     Matrix *mat;
 98 
 99     mat = ts_ralloc(Matrix);
100     mat->m = m;
101     mat->n = n;
102     mat->shape = shape;
103     mat->vtype = vtype;
104     switch (shape)
105     {
106     case matrix_full:
107         mat->el.short_v = sarray_alloc(0, 0, m, n);
108         break;
109     case matrix_lower:
110     case matrix_symmetric:
111         mat->el.short_v = slower_alloc(0, m);
112         break;
113     case matrix_upper:
114         mat->el.short_v = supper_alloc(0, m);
115         break;
116     default:                    /** full **/
117         mat->el.short_v = sarray_alloc(0, 0, m, n);
118         break;
119     }
120     return (mat);
121 }
122 
123 Matrix *imatrix_alloc(int m, int n, Matrix_shape shape, Vartype vtype)
124 {
125     Matrix *mat;
126 
127     mat = ts_ralloc(Matrix);
128     mat->m = m;
129     mat->n = n;
130     mat->shape = shape;
131     mat->vtype = vtype;
132     switch (shape)
133     {
134     case matrix_full:
135         mat->el.int_v = iarray_alloc(0, 0, m, n);
136         break;
137     case matrix_lower:
138     case matrix_symmetric:
139         mat->el.int_v = ilower_alloc(0, m);
140         break;
141     case matrix_upper:
142         mat->el.int_v = iupper_alloc(0, m);
143         break;
144     default:                    /** full **/
145         mat->el.int_v = iarray_alloc(0, 0, m, n);
146         break;
147     }
148     return (mat);
149 }
150 
151 Matrix *fmatrix_alloc(int m, int n, Matrix_shape shape, Vartype vtype)
152 {
153     Matrix *mat;
154 
155     mat = ts_ralloc(Matrix);
156     mat->m = m;
157     mat->n = n;
158     mat->shape = shape;
159     mat->vtype = vtype;
160     switch (shape)
161     {
162     case matrix_full:
163         mat->el.float_v = farray_alloc(0, 0, m, n);
164         break;
165     case matrix_lower:
166     case matrix_symmetric:
167         mat->el.float_v = flower_alloc(0, m);
168         break;
169     case matrix_upper:
170         mat->el.float_v = fupper_alloc(0, m);
171         break;
172     default:                    /** full **/
173         mat->el.float_v = farray_alloc(0, 0, m, n);
174         break;
175     }
176     return (mat);
177 }
178 
179 Matrix *dmatrix_alloc(int m, int n, Matrix_shape shape, Vartype vtype)
180 {
181     Matrix *mat;
182 
183     mat = ts_ralloc(Matrix);
184     mat->m = m;
185     mat->n = n;
186     mat->shape = shape;
187     mat->vtype = vtype;
188     switch (shape)
189     {
190     case matrix_full:
191         mat->el.double_v = darray_alloc(0, 0, m, n);
192         break;
193     case matrix_lower:
194     case matrix_symmetric:
195         mat->el.double_v = dlower_alloc(0, m);
196         break;
197     case matrix_upper:
198         mat->el.double_v = dupper_alloc(0, m);
199         break;
200     default:                    /** full **/
201         mat->el.double_v = darray_alloc(0, 0, m, n);
202         break;
203     }
204     return (mat);
205 }
206 
207 Matrix *zmatrix_alloc(int m, int n, Matrix_shape shape, Vartype vtype)
208 {
209     Matrix *mat;
210 
211     mat = ts_ralloc(Matrix);
212     mat->m = m;
213     mat->n = n;
214     mat->shape = shape;
215     mat->vtype = vtype;
216     switch (shape)
217     {
218     case matrix_full:
219         mat->el.complex_v = zarray_alloc(0, 0, m, n);
220         break;
221     case matrix_lower:
222     case matrix_symmetric:
223         mat->el.complex_v = zlower_alloc(0, m);
224         break;
225     case matrix_upper:
226         mat->el.complex_v = zupper_alloc(0, m);
227         break;
228     default:                    /** full **/
229         mat->el.complex_v = zarray_alloc(0, 0, m, n);
230         break;
231     }
232     return (mat);
233 }
234 
235 Matrix *pmatrix_alloc(int m, int n, Matrix_shape shape, Vartype vtype)
236 {
237     Matrix *mat;
238 
239     mat = ts_ralloc(Matrix);
240     mat->m = m;
241     mat->n = n;
242     mat->shape = shape;
243     mat->vtype = vtype;
244     switch (shape)
245     {
246     case matrix_full:
247         mat->el.ptr_v = parray_alloc(0, 0, m, n);
248         break;
249     case matrix_lower:
250     case matrix_symmetric:
251         mat->el.ptr_v = plower_alloc(0, m);
252         break;
253     case matrix_upper:
254         mat->el.ptr_v = pupper_alloc(0, m);
255         break;
256     default:                    /** full **/
257         mat->el.ptr_v = parray_alloc(0, 0, m, n);
258         break;
259     }
260     return (mat);
261 }
262 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.