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

Linux Cross Reference
Tina6/tina-libs/tina/math/mathMatr_transp.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_transp.c,v $
 37  * Date    :  $Date: 2003/09/23 11:32:20 $
 38  * Version :  $Revision: 1.4 $
 39  * CVS Id  :  $Id: mathMatr_transp.c,v 1.4 2003/09/23 11:32:20 matts Exp $
 40  *
 41  * Author  :  Legacy TINA
 42  *
 43  * Notes : Matrix transpose
 44  *
 45  *********
 46 */
 47 /** 
 48  *  @file
 49  *  @brief  Calculates transpose of a Matrix according to type and shape.       
 50  *
 51  *  Only int, float and double are allowed.
 52  * 
 53 */
 54 
 55 #include "mathMatr_transp.h"
 56 
 57 #if HAVE_CONFIG_H
 58 #include <config.h>
 59 #endif
 60 
 61 #include <tina/sys/sysDef.h>
 62 #include <tina/sys/sysPro.h>
 63 #include <tina/math/math_MatrDef.h>
 64 #include <tina/math/mathMatr_alloc.h>
 65 #include <tina/math/mathMatr_get.h>
 66 #include <tina/math/mathMatr_copy.h>
 67 
 68 Matrix         *matrix_transp(Matrix * mat)
 69 {
 70         if (mat == NULL)
 71                 return (NULL);
 72 
 73         switch (mat->vtype)
 74         {
 75         case int_v:
 76                 return (imatrix_transp(mat));
 77         case float_v:
 78                 return (fmatrix_transp(mat));
 79         case double_v:
 80                 return (dmatrix_transp(mat));
 81         default:
 82                 error("matrix_transp: unsupported type", non_fatal);
 83                 return (NULL);
 84         }
 85 }
 86 
 87 
 88 Matrix         *imatrix_transp(Matrix * mat)
 89 {
 90         Matrix         *transp;
 91         int           **el1, **el2;
 92         int             m, n;
 93         int             i, j;
 94 
 95         if (mat == NULL)
 96                 return (NULL);
 97 
 98         m = mat->m;
 99         n = mat->n;
100         el1 = mat->el.int_v;
101 
102         switch (mat->shape)
103         {
104         case matrix_full:
105                 transp = matrix_alloc(n, m, matrix_full, int_v);
106                 el2 = transp->el.int_v;
107                 for (i = 0; i < m; ++i)
108                         for (j = 0; j < n; ++j)
109                                 el2[j][i] = el1[i][j];
110                 break;
111         case matrix_lower:
112                 transp = matrix_alloc(n, m, matrix_lower, int_v);
113                 el2 = transp->el.int_v;
114                 for (i = 0; i < m; ++i)
115                         for (j = i; j < m; ++j)
116                                 el2[j][i] = el1[i][j];
117                 break;
118         case matrix_upper:
119                 transp = matrix_alloc(n, m, matrix_upper, int_v);
120                 el2 = transp->el.int_v;
121                 for (i = 0; i < m; ++i)
122                         for (j = 0; j <= i; ++j)
123                                 el2[j][i] = el1[i][j];
124                 break;
125         case matrix_symmetric:
126                 return (matrix_copy(mat));
127         default:
128                 transp = matrix_alloc(n, m, matrix_full, int_v);
129                 el2 = transp->el.int_v;
130                 for (i = 0; i < m; ++i)
131                         for (j = 0; j < n; ++j)
132                                 el2[j][i] = matrix_get(mat, i, j);
133                 break;
134         }
135         return (transp);
136 }
137 
138 Matrix         *fmatrix_transp(Matrix * mat)
139 {
140         Matrix         *transp;
141         float         **el1, **el2;
142         int             m, n;
143         int             i, j;
144 
145         if (mat == NULL)
146                 return (NULL);
147 
148         m = mat->m;
149         n = mat->n;
150         el1 = mat->el.float_v;
151 
152         switch (mat->shape)
153         {
154         case matrix_full:
155                 transp = matrix_alloc(n, m, matrix_full, float_v);
156                 el2 = transp->el.float_v;
157                 for (i = 0; i < m; ++i)
158                         for (j = 0; j < n; ++j)
159                                 el2[j][i] = el1[i][j];
160                 break;
161         case matrix_lower:
162                 transp = matrix_alloc(n, m, matrix_lower, float_v);
163                 el2 = transp->el.float_v;
164                 for (i = 0; i < m; ++i)
165                         for (j = i; j < m; ++j)
166                                 el2[j][i] = el1[i][j];
167                 break;
168         case matrix_upper:
169                 transp = matrix_alloc(n, m, matrix_upper, float_v);
170                 el2 = transp->el.float_v;
171                 for (i = 0; i < m; ++i)
172                         for (j = 0; j <= i; ++j)
173                                 el2[j][i] = el1[i][j];
174                 break;
175         case matrix_symmetric:
176                 return (matrix_copy(mat));
177         default:
178                 transp = matrix_alloc(n, m, matrix_full, float_v);
179                 el2 = transp->el.float_v;
180                 for (i = 0; i < m; ++i)
181                         for (j = 0; j < n; ++j)
182                                 el2[j][i] = matrix_getf(mat, i, j);
183                 break;
184         }
185         return (transp);
186 }
187 
188 Matrix         *dmatrix_transp(Matrix * mat)
189 {
190         Matrix         *transp;
191         double        **el1, **el2;
192         int             m, n;
193         int             i, j;
194 
195         if (mat == NULL)
196                 return (NULL);
197 
198         m = mat->m;
199         n = mat->n;
200         el1 = mat->el.double_v;
201 
202         switch (mat->shape)
203         {
204         case matrix_full:
205                 transp = matrix_alloc(n, m, matrix_full, double_v);
206                 el2 = transp->el.double_v;
207                 for (i = 0; i < m; ++i)
208                         for (j = 0; j < n; ++j)
209                                 el2[j][i] = el1[i][j];
210                 break;
211         case matrix_lower:
212                 transp = matrix_alloc(n, m, matrix_lower, double_v);
213                 el2 = transp->el.double_v;
214                 for (i = 0; i < m; ++i)
215                         for (j = i; j < m; ++j)
216                                 el2[j][i] = el1[i][j];
217                 break;
218         case matrix_upper:
219                 transp = matrix_alloc(n, m, matrix_upper, double_v);
220                 el2 = transp->el.double_v;
221                 for (i = 0; i < m; ++i)
222                         for (j = 0; j <= i; ++j)
223                                 el2[j][i] = el1[i][j];
224                 break;
225         case matrix_symmetric:
226                 return (matrix_copy(mat));
227         default:
228                 transp = matrix_alloc(n, m, matrix_full, double_v);
229                 el2 = transp->el.double_v;
230                 for (i = 0; i < m; ++i)
231                         for (j = 0; j < n; ++j)
232                                 el2[j][i] = matrix_getf(mat, i, j);
233                 break;
234         }
235         return (transp);
236 }
237 

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