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

Linux Cross Reference
Tina5/tina-libs/tina/math/mathMatr_alloc.c

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

  1 /**********
  2  *
  3  * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
  4  * University of Manchester, UK.  All rights reserved.
  5  * 
  6  * Redistribution and use in source and binary forms, with or without modification, 
  7  * are permitted provided that the following conditions are met:
  8  * 
  9  *   . Redistributions of source code must retain the above copyright notice, 
 10  *     this list of conditions and the following disclaimer.
 11  *    
 12  *   . Redistributions in binary form must reproduce the above copyright notice,
 13  *     this list of conditions and the following disclaimer in the documentation 
 14  *     and/or other materials provided with the distribution.
 15  * 
 16  *   . Neither the name of the University of Manchester nor the names of its
 17  *     contributors may be used to endorse or promote products derived from this 
 18  *     software without specific prior written permission.
 19  * 
 20  * 
 21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 31  * POSSIBILITY OF SUCH DAMAGE.
 32  *
 33  **********
 34  *
 35  * Program :    TINA
 36  * File    :  $Source: /home/tina/cvs/tina-libs/tina/math/mathMatr_alloc.c,v $
 37  * Date    :  $Date: 2003/09/23 11:32:20 $
 38  * Version :  $Revision: 1.4 $
 39  * CVS Id  :  $Id: mathMatr_alloc.c,v 1.4 2003/09/23 11:32:20 matts Exp $
 40  *
 41  * Author  :  Legacy TINA
 42  *
 43  * Notes : Matrix allocation: function (various types and shapes)
 44  *
 45  *********
 46 */
 47 /** 
 48  *  @file
 49  *  @brief  Matrix allocation.  
 50  *
 51  *  The higher-level matrix_alloc calls a lower level function according to the 
 52  *  type of values to be entered into the Matrix, and this then allocate a Matrix determined 
 53  *  by the required shape.
 54  *
 55  *  NB, mat_alloc is equivalent to matrix_alloc using a full matrix and floating type values.
 56 */
 57 
 58 #include "mathMatr_alloc.h"
 59 
 60 #if HAVE_CONFIG_H
 61 #include <config.h>
 62 #endif
 63 
 64 
 65 #include <math.h>
 66 #include <stdio.h>
 67 #include <tina/sys/sysDef.h>
 68 #include <tina/sys/sysPro.h>
 69 #include <tina/math/math_MatrDef.h>
 70 
 71 
 72 Matrix         *mat_alloc(int m, int n)
 73 {
 74         Matrix         *mat;
 75 
 76         mat = ts_ralloc(Matrix);
 77         mat->m = m;
 78         mat->n = n;
 79         mat->shape = matrix_full;
 80         mat->vtype = float_v;
 81         mat->el.float_v = farray_alloc(0, 0, m, n);
 82         return (mat);
 83 }
 84 
 85 Matrix         *matrix_alloc(int m, int n, Matrix_shape shape, Vartype vtype)
 86 {
 87         if (m < 0 || n < 0)
 88         {
 89                 error("matrix_alloc: bad size", non_fatal);
 90                 return (NULL);
 91         }
 92         if (m == 0 || n == 0)
 93         {
 94                 error("matrix_alloc: zero size", warning);
 95                 return (NULL);
 96         }
 97         switch (vtype)
 98         {
 99         case char_v:
100         case uchar_v:
101                 return (cmatrix_alloc(m, n, shape, vtype));
102         case short_v:
103         case ushort_v:
104                 return (smatrix_alloc(m, n, shape, vtype));
105         case int_v:
106         case uint_v:
107                 return (imatrix_alloc(m, n, shape, vtype));
108         case float_v:
109                 return (fmatrix_alloc(m, n, shape, vtype));
110         case double_v:
111                 return (dmatrix_alloc(m, n, shape, vtype));
112         case complex_v:
113                 return (zmatrix_alloc(m, n, shape, vtype));
114         case ptr_v:
115                 return (pmatrix_alloc(m, n, shape, vtype));
116         default:
117                 error("matrix_alloc: no such vtype", non_fatal);
118                 return (NULL);
119         }
120 }
121 
122 
123 Matrix         *cmatrix_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.char_v = carray_alloc(0, 0, m, n);
136                 break;
137         case matrix_lower:
138         case matrix_symmetric:
139                 mat->el.char_v = clower_alloc(0, m);
140                 break;
141         case matrix_upper:
142                 mat->el.char_v = cupper_alloc(0, m);
143                 break;
144         default:                /** full **/
145                 mat->el.char_v = carray_alloc(0, 0, m, n);
146                 break;
147         }
148 
149         return (mat);
150 }
151 
152 Matrix         *smatrix_alloc(int m, int n, Matrix_shape shape, Vartype vtype)
153 {
154         Matrix         *mat;
155 
156         mat = ts_ralloc(Matrix);
157         mat->m = m;
158         mat->n = n;
159         mat->shape = shape;
160         mat->vtype = vtype;
161         switch (shape)
162         {
163         case matrix_full:
164                 mat->el.short_v = sarray_alloc(0, 0, m, n);
165                 break;
166         case matrix_lower:
167         case matrix_symmetric:
168                 mat->el.short_v = slower_alloc(0, m);
169                 break;
170         case matrix_upper:
171                 mat->el.short_v = supper_alloc(0, m);
172                 break;
173         default:                /** full **/
174                 mat->el.short_v = sarray_alloc(0, 0, m, n);
175                 break;
176         }
177 
178         return (mat);
179 }
180 
181 Matrix         *imatrix_alloc(int m, int n, Matrix_shape shape, Vartype vtype)
182 {
183         Matrix         *mat;
184 
185         mat = ts_ralloc(Matrix);
186         mat->m = m;
187         mat->n = n;
188         mat->shape = shape;
189         mat->vtype = vtype;
190         switch (shape)
191         {
192         case matrix_full:
193                 mat->el.int_v = iarray_alloc(0, 0, m, n);
194                 break;
195         case matrix_lower:
196         case matrix_symmetric:
197                 mat->el.int_v = ilower_alloc(0, m);
198                 break;
199         case matrix_upper:
200                 mat->el.int_v = iupper_alloc(0, m);
201                 break;
202         default:                /** full **/
203                 mat->el.int_v = iarray_alloc(0, 0, m, n);
204                 break;
205         }
206         return (mat);
207 }
208 
209 Matrix         *fmatrix_alloc(int m, int n, Matrix_shape shape, Vartype vtype)
210 {
211         Matrix         *mat;
212 
213         mat = ts_ralloc(Matrix);
214         mat->m = m;
215         mat->n = n;
216         mat->shape = shape;
217         mat->vtype = vtype;
218         switch (shape)
219         {
220         case matrix_full:
221                 mat->el.float_v = farray_alloc(0, 0, m, n);
222                 break;
223         case matrix_lower:
224         case matrix_symmetric:
225                 mat->el.float_v = flower_alloc(0, m);
226                 break;
227         case matrix_upper:
228                 mat->el.float_v = fupper_alloc(0, m);
229                 break;
230         default:                /** full **/
231                 mat->el.float_v = farray_alloc(0, 0, m, n);
232                 break;
233         }
234         return (mat);
235 }
236 
237 Matrix         *dmatrix_alloc(int m, int n, Matrix_shape shape, Vartype vtype)
238 {
239         Matrix         *mat;
240 
241         mat = ts_ralloc(Matrix);
242         mat->m = m;
243         mat->n = n;
244         mat->shape = shape;
245         mat->vtype = vtype;
246         switch (shape)
247         {
248         case matrix_full:
249                 mat->el.double_v = darray_alloc(0, 0, m, n);
250                 break;
251         case matrix_lower:
252         case matrix_symmetric:
253                 mat->el.double_v = dlower_alloc(0, m);
254                 break;
255         case matrix_upper:
256                 mat->el.double_v = dupper_alloc(0, m);
257                 break;
258         default:                /** full **/
259                 mat->el.double_v = darray_alloc(0, 0, m, n);
260                 break;
261         }
262         return (mat);
263 }
264 
265 Matrix         *zmatrix_alloc(int m, int n, Matrix_shape shape, Vartype vtype)
266 {
267         Matrix         *mat;
268 
269         mat = ts_ralloc(Matrix);
270         mat->m = m;
271         mat->n = n;
272         mat->shape = shape;
273         mat->vtype = vtype;
274         switch (shape)
275         {
276         case matrix_full:
277                 mat->el.complex_v = zarray_alloc(0, 0, m, n);
278                 break;
279         case matrix_lower:
280         case matrix_symmetric:
281                 mat->el.complex_v = zlower_alloc(0, m);
282                 break;
283         case matrix_upper:
284                 mat->el.complex_v = zupper_alloc(0, m);
285                 break;
286         default:                /** full **/
287                 mat->el.complex_v = zarray_alloc(0, 0, m, n);
288                 break;
289         }
290         return (mat);
291 }
292 
293 Matrix         *pmatrix_alloc(int m, int n, Matrix_shape shape, Vartype vtype)
294 {
295         Matrix         *mat;
296 
297         mat = ts_ralloc(Matrix);
298         mat->m = m;
299         mat->n = n;
300         mat->shape = shape;
301         mat->vtype = vtype;
302         switch (shape)
303         {
304         case matrix_full:
305                 mat->el.ptr_v = parray_alloc(0, 0, m, n);
306                 break;
307         case matrix_lower:
308         case matrix_symmetric:
309                 mat->el.ptr_v = plower_alloc(0, m);
310                 break;
311         case matrix_upper:
312                 mat->el.ptr_v = pupper_alloc(0, m);
313                 break;
314         default:                /** full **/
315                 mat->el.ptr_v = parray_alloc(0, 0, m, n);
316                 break;
317         }
318         return (mat);
319 }
320 

~ [ 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.