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

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

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

  1 /**@(#)Matrix copy (various types and shapes)
  2  */
  3 
  4 #include <tina/sys.h>
  5 #include <tina/sysfuncs.h>
  6 #include <tina/math.h>
  7 #include <tina/mathfuncs.h>
  8 
  9 int     matrix_get();
 10 
 11 void    matrix_put();
 12 void    matrix_putf();
 13 
 14 Matrix *matrix_alloc();
 15 Matrix *matrix_build();
 16 
 17 Matrix *imatrix_copy(Matrix * mat);
 18 Matrix *fmatrix_copy(Matrix * mat);
 19 Matrix *dmatrix_copy(Matrix * mat);
 20 
 21 Matrix *matrix_copy(Matrix * mat)
 22 {
 23     if (mat == NULL)
 24         return (NULL);
 25 
 26     switch (mat->vtype)
 27     {
 28     case int_v:
 29         return (imatrix_copy(mat));
 30     case float_v:
 31         return (fmatrix_copy(mat));
 32     case double_v:
 33         return (dmatrix_copy(mat));
 34     }
 35 
 36     error("matrix_copy: no such type", non_fatal);
 37     return (NULL);
 38 }
 39 
 40 Matrix *imatrix_copy(Matrix * mat)
 41 {
 42     void   *el;
 43     int     m = mat->m;
 44     int     n = mat->n;
 45     Matrix_shape shape = mat->shape;
 46 
 47     int     dummy1 = 0;
 48     int     dummy2 = 0;
 49 
 50     switch (shape)
 51     {
 52     case matrix_full:
 53         el = (void *) iarray_icopy(mat->el.int_v, 0, 0, m, n);
 54         break;
 55     case matrix_lower:
 56     case matrix_symmetric:
 57 
 58         /* BUG ilower_icopy(int **a, int m1, n1, m2, n2 */
 59         el = (void *) ilower_icopy(mat->el.int_v, 0, n, dummy1, dummy2);
 60         break;
 61     case matrix_upper:
 62         el = (void *) iupper_icopy(mat->el.int_v, 0, n);
 63         break;
 64     default:
 65         {
 66             int     i, j;
 67             Matrix *copy = matrix_alloc(m, n, shape, int_v);
 68 
 69             for (i = 0; i < m; ++i)
 70                 for (j = 0; j < n; ++j)
 71                     matrix_put(matrix_get(mat, i, j), copy, i, j);
 72             return (copy);
 73         }
 74     }
 75     return (matrix_build(m, n, shape, int_v, el));
 76 }
 77 
 78 Matrix *fmatrix_copy(Matrix * mat)
 79 {
 80     void   *el;
 81     int     m = mat->m;
 82     int     n = mat->n;
 83     Matrix_shape shape = mat->shape;
 84 
 85     int     dummy1 = 0;
 86     int     dummy2 = 0;
 87 
 88     switch (shape)
 89     {
 90     case matrix_full:
 91         el = (void *) farray_fcopy(mat->el.float_v, 0, 0, m, n);
 92         break;
 93     case matrix_lower:
 94     case matrix_symmetric:
 95 
 96         /* BUG flower_dcopy(double **a, int m1, n1, m2, n2) */
 97         el = (void *) flower_fcopy(mat->el.float_v, 0, n, dummy1, dummy2);
 98         break;
 99     case matrix_upper:
100         el = (void *) fupper_fcopy(mat->el.float_v, 0, n);
101         break;
102     default:
103         {
104             int     i, j;
105             Matrix *copy = matrix_alloc(m, n, shape, float_v);
106 
107             for (i = 0; i < m; ++i)
108                 for (j = 0; j < n; ++j)
109                     matrix_putf(matrix_getf(mat, i, j), copy, i, j);
110             return (copy);
111         }
112     }
113     return (matrix_build(m, n, shape, float_v, el));
114 }
115 
116 Matrix *dmatrix_copy(Matrix * mat)
117 {
118     void   *el;
119     int     m = mat->m;
120     int     n = mat->n;
121     Matrix_shape shape = mat->shape;
122 
123     int     dummy1 = 0;
124     int     dummy2 = 0;
125 
126     switch (shape)
127     {
128     case matrix_full:
129         el = (void *) darray_dcopy(mat->el.double_v, 0, 0, m, n);
130         break;
131     case matrix_lower:
132     case matrix_symmetric:
133 
134         /* BUG double **dlower_dcopy(a, m1, n1, m2, n2) */
135         el = (void *) dlower_dcopy(mat->el.double_v, 0, n, dummy1, dummy2);
136         break;
137     case matrix_upper:
138         el = (void *) dupper_dcopy(mat->el.double_v, 0, n);
139         break;
140     default:
141         {
142             int     i, j;
143             Matrix *copy = matrix_alloc(m, n, shape, double_v);
144 
145             for (i = 0; i < m; ++i)
146                 for (j = 0; j < n; ++j)
147                     matrix_putf(matrix_getf(mat, i, j), copy, i, j);
148             return (copy);
149         }
150     }
151     return (matrix_build(m, n, shape, double_v, el));
152 }
153 
154 Matrix *matrix_copy_inplace(Matrix * mat1, Matrix * mat2)
155 {
156     int     n, m;
157     int     i, j;
158 
159     if (mat1 == NULL || mat2 == NULL)
160         return (mat2);
161 
162     m = mat1->m;
163     n = mat1->n;
164 
165     if (mat2->m < m || mat2->n < n)
166         return (mat2);
167 
168     for (i = 0; i < m; ++i)
169         for (j = 0; j < n; ++j)
170             matrix_putf(matrix_getf(mat1, i, j), mat2, i, j);
171     return (mat2);
172 }
173 

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