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

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

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

  1 /**@(#)Build matrices with same elements but different type
  2  */
  3 
  4 #include <tina/sys.h>
  5 #include <tina/sysfuncs.h>
  6 #include <tina/math.h>
  7 
  8 int     matrix_get();
  9 double  matrix_getf();
 10 
 11 void    matrix_put();
 12 void    matrix_putf();
 13 
 14 Matrix *matrix_alloc();
 15 Matrix *matrix_build();
 16 
 17 Matrix *imatrix_cast(Matrix * mat);
 18 Matrix *fmatrix_cast(Matrix * mat);
 19 Matrix *dmatrix_cast(Matrix * mat);
 20 
 21 Matrix *matrix_cast(Matrix * mat, Vartype vtype)
 22 {
 23     if (mat == NULL)
 24         return (NULL);
 25 
 26     switch (vtype)
 27     {
 28     case int_v:
 29         return (imatrix_cast(mat));
 30     case float_v:
 31         return (fmatrix_cast(mat));
 32     case double_v:
 33         return (dmatrix_cast(mat));
 34     }
 35     error("matrix_cast: no such type", non_fatal);
 36     return (NULL);
 37 }
 38 
 39 Matrix *imatrix_cast(Matrix * mat)
 40 {
 41     int   **el;
 42     Vartype vtype = mat->vtype;
 43     Matrix_shape shape = mat->shape;
 44     int     m = mat->m;
 45     int     n = mat->n;
 46 
 47     int     dummy1 = 0;
 48     int     dummy2 = 0;
 49 
 50     switch (OPAIR(vtype, shape))
 51     {
 52     case OPAIR(int_v, matrix_full):
 53         el = iarray_icopy(mat->el.int_v, 0, 0, m, n);
 54         break;
 55     case OPAIR(float_v, matrix_full):
 56         el = iarray_fcopy(mat->el.float_v, 0, 0, m, n);
 57         break;
 58     case OPAIR(double_v, matrix_full):
 59         el = iarray_dcopy(mat->el.double_v, 0, 0, m, n);
 60         break;
 61     case OPAIR(int_v, matrix_lower):
 62     case OPAIR(int_v, matrix_symmetric):
 63 
 64         /* BUG ilower_dcopy(double **, int     m1, n1, m2, n2). dummy1
 65          * & */
 66         /* dummy2 added */
 67         el = ilower_icopy(mat->el.int_v, 0, n, dummy1, dummy2);
 68         break;
 69     case OPAIR(float_v, matrix_lower):
 70     case OPAIR(float_v, matrix_symmetric):
 71 
 72         /* BUG ilower_dcopy(double **, int     m1, n1, m2, n2) */
 73         el = ilower_fcopy(mat->el.float_v, 0, n, dummy1, dummy2);
 74         break;
 75     case OPAIR(double_v, matrix_lower):
 76     case OPAIR(double_v, matrix_symmetric):
 77 
 78         /* BUG ilower_dcopy(double **, int     m1, n1, m2, n2) */
 79         el = ilower_dcopy(mat->el.double_v, 0, n, dummy1, dummy2);
 80         break;
 81     case OPAIR(int_v, matrix_upper):
 82         el = iupper_icopy(mat->el.int_v, 0, n);
 83         break;
 84     case OPAIR(float_v, matrix_upper):
 85         el = iupper_fcopy(mat->el.float_v, 0, n);
 86         break;
 87     case OPAIR(double_v, matrix_upper):
 88         el = iupper_dcopy(mat->el.double_v, 0, n);
 89         break;
 90     default:
 91         {
 92             int     i, j;
 93             Matrix *copy = matrix_alloc(m, n, mat->shape, int_v);
 94 
 95             for (i = 0; i < mat->m; ++i)
 96                 for (j = 0; j < mat->n; ++j)
 97                     matrix_put(matrix_get(mat, i, j), copy, i, j);
 98             return (copy);
 99         }
100     }
101     return (matrix_build(m, n, mat->shape, int_v, (void *) el));
102 }
103 
104 Matrix *fmatrix_cast(Matrix * mat)
105 {
106     float **el;
107     Vartype vtype = mat->vtype;
108     Matrix_shape shape = mat->shape;
109     int     m = mat->m;
110     int     n = mat->n;
111 
112     int     dummy1 = 0;
113     int     dummy2 = 0;
114 
115     switch (OPAIR(vtype, shape))
116     {
117     case OPAIR(int_v, matrix_full):
118         el = farray_icopy(mat->el.int_v, 0, 0, m, n);
119         break;
120     case OPAIR(float_v, matrix_full):
121         el = farray_fcopy(mat->el.float_v, 0, 0, m, n);
122         break;
123     case OPAIR(double_v, matrix_full):
124         el = farray_dcopy(mat->el.double_v, 0, 0, m, n);
125         break;
126     case OPAIR(int_v, matrix_lower):
127     case OPAIR(int_v, matrix_symmetric):
128 
129         /* BUG flower_dcopy(double **a, int m1, n1, m2, n2) */
130         el = flower_icopy(mat->el.int_v, 0, n, dummy1, dummy2);
131         break;
132     case OPAIR(float_v, matrix_lower):
133     case OPAIR(float_v, matrix_symmetric):
134 
135         /* BUG flower_dcopy(double **a, int m1, n1, m2, n2) */
136         el = flower_fcopy(mat->el.float_v, 0, n, dummy1, dummy2);
137         break;
138     case OPAIR(double_v, matrix_lower):
139     case OPAIR(double_v, matrix_symmetric):
140 
141         /* BUG flower_dcopy(double **a, int m1, n1, m2, n2) */
142         el = flower_dcopy(mat->el.double_v, 0, n, dummy1, dummy2);
143         break;
144     case OPAIR(int_v, matrix_upper):
145         el = fupper_icopy(mat->el.int_v, 0, n);
146         break;
147     case OPAIR(float_v, matrix_upper):
148         el = fupper_fcopy(mat->el.float_v, 0, n);
149         break;
150     case OPAIR(double_v, matrix_upper):
151         el = fupper_dcopy(mat->el.double_v, 0, n);
152         break;
153     default:
154         {
155             int     i, j;
156             Matrix *copy = matrix_alloc(m, n, mat->shape, float_v);
157 
158             for (i = 0; i < mat->m; ++i)
159                 for (j = 0; j < mat->n; ++j)
160                     matrix_putf(matrix_getf(mat, i, j), copy, i, j);
161             return (copy);
162         }
163     }
164     return (matrix_build(m, n, mat->shape, float_v, (void *) el));
165 }
166 
167 Matrix *dmatrix_cast(Matrix * mat)
168 {
169     double **el;
170     Vartype vtype = mat->vtype;
171     Matrix_shape shape = mat->shape;
172     int     m = mat->m;
173     int     n = mat->n;
174 
175     int     dummy1 = 0;
176     int     dummy2 = 0;
177 
178     switch (OPAIR(vtype, shape))
179     {
180     case OPAIR(int_v, matrix_full):
181         el = darray_icopy(mat->el.int_v, 0, 0, m, n);
182         break;
183     case OPAIR(float_v, matrix_full):
184         el = darray_fcopy(mat->el.float_v, 0, 0, m, n);
185         break;
186     case OPAIR(double_v, matrix_full):
187         el = darray_dcopy(mat->el.double_v, 0, 0, m, n);
188         break;
189     case OPAIR(int_v, matrix_lower):
190     case OPAIR(int_v, matrix_symmetric):
191 
192         /* BUG double **dlower_dcopy(a, m1, n1, m2, n2) */
193         el = dlower_icopy(mat->el.int_v, 0, n, dummy1, dummy2);
194         break;
195     case OPAIR(float_v, matrix_lower):
196     case OPAIR(float_v, matrix_symmetric):
197 
198         /* BUG double **dlower_dcopy(a, m1, n1, m2, n2) */
199         el = dlower_fcopy(mat->el.float_v, 0, n, dummy1, dummy2);
200         break;
201     case OPAIR(double_v, matrix_lower):
202     case OPAIR(double_v, matrix_symmetric):
203 
204         /* BUG double **dlower_dcopy(a, m1, n1, m2, n2) */
205         el = dlower_dcopy(mat->el.double_v, 0, n, dummy1, dummy2);
206         break;
207     case OPAIR(int_v, matrix_upper):
208         el = dupper_icopy(mat->el.int_v, 0, n);
209         break;
210     case OPAIR(float_v, matrix_upper):
211         el = dupper_fcopy(mat->el.float_v, 0, n);
212         break;
213     case OPAIR(double_v, matrix_upper):
214         el = dupper_dcopy(mat->el.double_v, 0, n);
215         break;
216     default:
217         {
218             int     i, j;
219             Matrix *copy = matrix_alloc(m, n, mat->shape, double_v);
220 
221             for (i = 0; i < mat->m; ++i)
222                 for (j = 0; j < mat->n; ++j)
223                     matrix_putf(matrix_getf(mat, i, j), copy, i, j);
224             return (copy);
225         }
226     }
227     return (matrix_build(m, n, mat->shape, double_v, (void *) el));
228 }
229 

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