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_cast.c,v $
37 * Date : $Date: 2003/09/23 11:32:20 $
38 * Version : $Revision: 1.4 $
39 * CVS Id : $Id: mathMatr_cast.c,v 1.4 2003/09/23 11:32:20 matts Exp $
40 *
41 * Author : Legacy TINA
42 *
43 * Notes : Build matrices with same elements but different type
44 *
45 *********
46 */
47
48 /**
49 * @file
50 * @brief Build Matrices with same elements but different type.
51 *
52 *
53 *
54 */
55
56 #include "mathMatr_cast.h"
57
58 #if HAVE_CONFIG_H
59 #include <config.h>
60 #endif
61
62
63 #include <tina/sys/sysDef.h>
64 #include <tina/sys/sysPro.h>
65 #include <tina/math/math_MatrDef.h>
66 #include <tina/math/mathMatr_get.h>
67 #include <tina/math/mathMatr_put.h>
68 #include <tina/math/mathMatr_alloc.h>
69 #include <tina/math/mathMatr_build.h>
70
71 Matrix *matrix_cast(Matrix * mat, Vartype vtype)
72 {
73 if (mat == NULL)
74 return (NULL);
75
76 switch (vtype)
77 {
78 case int_v:
79 return (imatrix_cast(mat));
80 case float_v:
81 return (fmatrix_cast(mat));
82 case double_v:
83 return (dmatrix_cast(mat));
84 default:
85 error("matrix_cast: no such type", non_fatal);
86 return (NULL);
87 }
88 }
89
90 Matrix *imatrix_cast(Matrix * mat)
91 {
92 int **el;
93 Vartype vtype = mat->vtype;
94 Matrix_shape shape = mat->shape;
95 int m = mat->m;
96 int n = mat->n;
97
98 int dummy1 = 0;
99 int dummy2 = 0;
100
101 switch (OPAIR(vtype, shape))
102 {
103 case OPAIR(int_v, matrix_full):
104 el = iarray_icopy(mat->el.int_v, 0, 0, m, n);
105 break;
106 case OPAIR(float_v, matrix_full):
107 el = iarray_fcopy(mat->el.float_v, 0, 0, m, n);
108 break;
109 case OPAIR(double_v, matrix_full):
110 el = iarray_dcopy(mat->el.double_v, 0, 0, m, n);
111 break;
112 case OPAIR(int_v, matrix_lower):
113 case OPAIR(int_v, matrix_symmetric):
114
115 /*
116 * BUG ilower_dcopy(double **, int m1, n1, m2, n2).
117 * dummy1 &
118 */
119 /* dummy2 added */
120 el = ilower_icopy(mat->el.int_v, 0, n, dummy1, dummy2);
121 break;
122 case OPAIR(float_v, matrix_lower):
123 case OPAIR(float_v, matrix_symmetric):
124
125 /* BUG ilower_dcopy(double **, int m1, n1, m2, n2) */
126 el = ilower_fcopy(mat->el.float_v, 0, n, dummy1, dummy2);
127 break;
128 case OPAIR(double_v, matrix_lower):
129 case OPAIR(double_v, matrix_symmetric):
130
131 /* BUG ilower_dcopy(double **, int m1, n1, m2, n2) */
132 el = ilower_dcopy(mat->el.double_v, 0, n, dummy1, dummy2);
133 break;
134 case OPAIR(int_v, matrix_upper):
135 el = iupper_icopy(mat->el.int_v, 0, n);
136 break;
137 case OPAIR(float_v, matrix_upper):
138 el = iupper_fcopy(mat->el.float_v, 0, n);
139 break;
140 case OPAIR(double_v, matrix_upper):
141 el = iupper_dcopy(mat->el.double_v, 0, n);
142 break;
143 default:
144 {
145 int i, j;
146 Matrix *copy = matrix_alloc(m, n, mat->shape, int_v);
147
148 for (i = 0; i < mat->m; ++i)
149 for (j = 0; j < mat->n; ++j)
150 matrix_put(matrix_get(mat, i, j), copy, i, j);
151 return (copy);
152 }
153 }
154 return (matrix_build(m, n, mat->shape, int_v, (void *) el));
155 }
156
157 Matrix *fmatrix_cast(Matrix * mat)
158 {
159 float **el;
160 Vartype vtype = mat->vtype;
161 Matrix_shape shape = mat->shape;
162 int m = mat->m;
163 int n = mat->n;
164
165 int dummy1 = 0;
166 int dummy2 = 0;
167
168 switch (OPAIR(vtype, shape))
169 {
170 case OPAIR(int_v, matrix_full):
171 el = farray_icopy(mat->el.int_v, 0, 0, m, n);
172 break;
173 case OPAIR(float_v, matrix_full):
174 el = farray_fcopy(mat->el.float_v, 0, 0, m, n);
175 break;
176 case OPAIR(double_v, matrix_full):
177 el = farray_dcopy(mat->el.double_v, 0, 0, m, n);
178 break;
179 case OPAIR(int_v, matrix_lower):
180 case OPAIR(int_v, matrix_symmetric):
181
182 /* BUG flower_dcopy(double **a, int m1, n1, m2, n2) */
183 el = flower_icopy(mat->el.int_v, 0, n, dummy1, dummy2);
184 break;
185 case OPAIR(float_v, matrix_lower):
186 case OPAIR(float_v, matrix_symmetric):
187
188 /* BUG flower_dcopy(double **a, int m1, n1, m2, n2) */
189 el = flower_fcopy(mat->el.float_v, 0, n, dummy1, dummy2);
190 break;
191 case OPAIR(double_v, matrix_lower):
192 case OPAIR(double_v, matrix_symmetric):
193
194 /* BUG flower_dcopy(double **a, int m1, n1, m2, n2) */
195 el = flower_dcopy(mat->el.double_v, 0, n, dummy1, dummy2);
196 break;
197 case OPAIR(int_v, matrix_upper):
198 el = fupper_icopy(mat->el.int_v, 0, n);
199 break;
200 case OPAIR(float_v, matrix_upper):
201 el = fupper_fcopy(mat->el.float_v, 0, n);
202 break;
203 case OPAIR(double_v, matrix_upper):
204 el = fupper_dcopy(mat->el.double_v, 0, n);
205 break;
206 default:
207 {
208 int i, j;
209 Matrix *copy = matrix_alloc(m, n, mat->shape, float_v);
210
211 for (i = 0; i < mat->m; ++i)
212 for (j = 0; j < mat->n; ++j)
213 matrix_putf(matrix_getf(mat, i, j), copy, i, j);
214 return (copy);
215 }
216 }
217 return (matrix_build(m, n, mat->shape, float_v, (void *) el));
218 }
219
220 Matrix *dmatrix_cast(Matrix * mat)
221 {
222 double **el;
223 Vartype vtype = mat->vtype;
224 Matrix_shape shape = mat->shape;
225 int m = mat->m;
226 int n = mat->n;
227
228 int dummy1 = 0;
229 int dummy2 = 0;
230
231 switch (OPAIR(vtype, shape))
232 {
233 case OPAIR(int_v, matrix_full):
234 el = darray_icopy(mat->el.int_v, 0, 0, m, n);
235 break;
236 case OPAIR(float_v, matrix_full):
237 el = darray_fcopy(mat->el.float_v, 0, 0, m, n);
238 break;
239 case OPAIR(double_v, matrix_full):
240 el = darray_dcopy(mat->el.double_v, 0, 0, m, n);
241 break;
242 case OPAIR(int_v, matrix_lower):
243 case OPAIR(int_v, matrix_symmetric):
244
245 /* BUG double **dlower_dcopy(a, m1, n1, m2, n2) */
246 el = dlower_icopy(mat->el.int_v, 0, n, dummy1, dummy2);
247 break;
248 case OPAIR(float_v, matrix_lower):
249 case OPAIR(float_v, matrix_symmetric):
250
251 /* BUG double **dlower_dcopy(a, m1, n1, m2, n2) */
252 el = dlower_fcopy(mat->el.float_v, 0, n, dummy1, dummy2);
253 break;
254 case OPAIR(double_v, matrix_lower):
255 case OPAIR(double_v, matrix_symmetric):
256
257 /* BUG double **dlower_dcopy(a, m1, n1, m2, n2) */
258 el = dlower_dcopy(mat->el.double_v, 0, n, dummy1, dummy2);
259 break;
260 case OPAIR(int_v, matrix_upper):
261 el = dupper_icopy(mat->el.int_v, 0, n);
262 break;
263 case OPAIR(float_v, matrix_upper):
264 el = dupper_fcopy(mat->el.float_v, 0, n);
265 break;
266 case OPAIR(double_v, matrix_upper):
267 el = dupper_dcopy(mat->el.double_v, 0, n);
268 break;
269 default:
270 {
271 int i, j;
272 Matrix *copy = matrix_alloc(m, n, mat->shape, double_v);
273
274 for (i = 0; i < mat->m; ++i)
275 for (j = 0; j < mat->n; ++j)
276 matrix_putf(matrix_getf(mat, i, j), copy, i, j);
277 return (copy);
278 }
279 }
280 return (matrix_build(m, n, mat->shape, double_v, (void *) el));
281 }
282
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.