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

Linux Cross Reference
Tina6/tina-libs/tina/math/mathMatr_copy.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_copy.c,v $
 37  * Date    :  $Date: 2003/09/23 11:32:20 $
 38  * Version :  $Revision: 1.4 $
 39  * CVS Id  :  $Id: mathMatr_copy.c,v 1.4 2003/09/23 11:32:20 matts Exp $
 40  *
 41  * Author  :  Legacy TINA
 42  *
 43  * Notes : Matrix copy (various types and shapes)
 44  *
 45  *********
 46 */
 47 /** 
 48  *  @file
 49  *  @brief  Matrix copy functions according to type and shape.  
 50  *
 51  *
 52  * 
 53 */
 54 
 55 #include "mathMatr_copy.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_get.h>
 65 #include <tina/math/mathMatr_put.h>
 66 #include <tina/math/mathMatr_alloc.h>
 67 #include <tina/math/mathMatr_build.h>
 68 
 69 
 70 Matrix         *matrix_copy(Matrix * mat)
 71 {
 72         if (mat == NULL)
 73                 return (NULL);
 74 
 75         switch (mat->vtype)
 76         {
 77         case int_v:
 78                 return (imatrix_copy(mat));
 79         case float_v:
 80                 return (fmatrix_copy(mat));
 81         case double_v:
 82                 return (dmatrix_copy(mat));
 83         default:
 84                 error("matrix_copy: unsupported type", non_fatal);
 85                 return (NULL);
 86         }
 87 
 88 
 89 }
 90 
 91 Matrix         *imatrix_copy(Matrix * mat)
 92 {
 93         void           *el;
 94         int             m = mat->m;
 95         int             n = mat->n;
 96         Matrix_shape    shape = mat->shape;
 97 
 98         int             dummy1 = 0;
 99         int             dummy2 = 0;
100 
101         switch (shape)
102         {
103         case matrix_full:
104                 el = (void *) iarray_icopy(mat->el.int_v, 0, 0, m, n);
105                 break;
106         case matrix_lower:
107         case matrix_symmetric:
108 
109                 /* BUG ilower_icopy(int **a, int m1, n1, m2, n2 */
110                 el = (void *) ilower_icopy(mat->el.int_v, 0, n, dummy1, dummy2);
111                 break;
112         case matrix_upper:
113                 el = (void *) iupper_icopy(mat->el.int_v, 0, n);
114                 break;
115         default:
116                 {
117                         int             i, j;
118                         Matrix         *copy = matrix_alloc(m, n, shape, int_v);
119 
120                         for (i = 0; i < m; ++i)
121                                 for (j = 0; j < n; ++j)
122                                         matrix_put(matrix_get(mat, i, j), copy, i, j);
123                         return (copy);
124                 }
125         }
126         return (matrix_build(m, n, shape, int_v, el));
127 }
128 
129 Matrix         *fmatrix_copy(Matrix * mat)
130 {
131         void           *el;
132         int             m = mat->m;
133         int             n = mat->n;
134         Matrix_shape    shape = mat->shape;
135 
136         int             dummy1 = 0;
137         int             dummy2 = 0;
138 
139         switch (shape)
140         {
141         case matrix_full:
142                 el = (void *) farray_fcopy(mat->el.float_v, 0, 0, m, n);
143                 break;
144         case matrix_lower:
145         case matrix_symmetric:
146 
147                 /* BUG flower_dcopy(double **a, int m1, n1, m2, n2) */
148                 el = (void *) flower_fcopy(mat->el.float_v, 0, n, dummy1, dummy2);
149                 break;
150         case matrix_upper:
151                 el = (void *) fupper_fcopy(mat->el.float_v, 0, n);
152                 break;
153         default:
154                 {
155                         int             i, j;
156                         Matrix         *copy = matrix_alloc(m, n, shape, float_v);
157 
158                         for (i = 0; i < m; ++i)
159                                 for (j = 0; j < n; ++j)
160                                         matrix_putf(matrix_getf(mat, i, j), copy, i, j);
161                         return (copy);
162                 }
163         }
164         return (matrix_build(m, n, shape, float_v, el));
165 }
166 
167 Matrix         *dmatrix_copy(Matrix * mat)
168 {
169         void           *el;
170         int             m = mat->m;
171         int             n = mat->n;
172         Matrix_shape    shape = mat->shape;
173 
174         int             dummy1 = 0;
175         int             dummy2 = 0;
176 
177         switch (shape)
178         {
179         case matrix_full:
180                 el = (void *) darray_dcopy(mat->el.double_v, 0, 0, m, n);
181                 break;
182         case matrix_lower:
183         case matrix_symmetric:
184 
185                 /* BUG double **dlower_dcopy(a, m1, n1, m2, n2) */
186                 el = (void *) dlower_dcopy(mat->el.double_v, 0, n, dummy1, dummy2);
187                 break;
188         case matrix_upper:
189                 el = (void *) dupper_dcopy(mat->el.double_v, 0, n);
190                 break;
191         default:
192                 {
193                         int             i, j;
194                         Matrix         *copy = matrix_alloc(m, n, shape, double_v);
195 
196                         for (i = 0; i < m; ++i)
197                                 for (j = 0; j < n; ++j)
198                                         matrix_putf(matrix_getf(mat, i, j), copy, i, j);
199                         return (copy);
200                 }
201         }
202         return (matrix_build(m, n, shape, double_v, el));
203 }
204 
205 Matrix         *matrix_copy_inplace(Matrix * mat1, Matrix * mat2)
206 {
207         int             n, m;
208         int             i, j;
209 
210         if (mat1 == NULL || mat2 == NULL)
211                 return (mat2);
212 
213         m = mat1->m;
214         n = mat1->n;
215 
216         if (mat2->m < m || mat2->n < n)
217                 return (mat2);
218 
219         for (i = 0; i < m; ++i)
220                 for (j = 0; j < n; ++j)
221                         matrix_putf(matrix_getf(mat1, i, j), mat2, i, j);
222         return (mat2);
223 }
224 

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