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

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

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

  1 /**@(#)Matrix transpose
  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 Matrix *matrix_alloc();
 12 Matrix *matrix_copy();
 13 
 14 Matrix *imatrix_transp(Matrix * mat);
 15 Matrix *fmatrix_transp(Matrix * mat);
 16 Matrix *dmatrix_transp(Matrix * mat);
 17 
 18 Matrix *matrix_transp(Matrix * mat)
 19 {
 20     if (mat == NULL)
 21         return (NULL);
 22 
 23     switch (mat->vtype)
 24     {
 25     case int_v:
 26         return (imatrix_transp(mat));
 27     case float_v:
 28         return (fmatrix_transp(mat));
 29     case double_v:
 30         return (dmatrix_transp(mat));
 31     }
 32     error("matrix_transp: no such type", non_fatal);
 33     return (NULL);
 34 }
 35 
 36 Matrix *imatrix_transp(Matrix * mat)
 37 {
 38     Matrix *transp;
 39     int   **el1, **el2;
 40     int     m, n;
 41     int     i, j;
 42 
 43     if (mat == NULL)
 44         return (NULL);
 45 
 46     m = mat->m;
 47     n = mat->n;
 48     el1 = mat->el.int_v;
 49 
 50     switch (mat->shape)
 51     {
 52     case matrix_full:
 53         transp = matrix_alloc(n, m, matrix_full, int_v);
 54         el2 = transp->el.int_v;
 55         for (i = 0; i < m; ++i)
 56             for (j = 0; j < n; ++j)
 57                 el2[j][i] = el1[i][j];
 58         break;
 59     case matrix_lower:
 60         transp = matrix_alloc(n, m, matrix_lower, int_v);
 61         el2 = transp->el.int_v;
 62         for (i = 0; i < m; ++i)
 63             for (j = i; j < m; ++j)
 64                 el2[j][i] = el1[i][j];
 65         break;
 66     case matrix_upper:
 67         transp = matrix_alloc(n, m, matrix_upper, int_v);
 68         el2 = transp->el.int_v;
 69         for (i = 0; i < m; ++i)
 70             for (j = 0; j <= i; ++j)
 71                 el2[j][i] = el1[i][j];
 72         break;
 73     case matrix_symmetric:
 74         return (matrix_copy(mat));
 75     default:
 76         transp = matrix_alloc(n, m, matrix_full, int_v);
 77         el2 = transp->el.int_v;
 78         for (i = 0; i < m; ++i)
 79             for (j = 0; j < n; ++j)
 80                 el2[j][i] = matrix_get(mat, i, j);
 81         break;
 82     }
 83     return (transp);
 84 }
 85 
 86 Matrix *fmatrix_transp(Matrix * mat)
 87 {
 88     Matrix *transp;
 89     float **el1, **el2;
 90     int     m, n;
 91     int     i, j;
 92 
 93     if (mat == NULL)
 94         return (NULL);
 95 
 96     m = mat->m;
 97     n = mat->n;
 98     el1 = mat->el.float_v;
 99 
100     switch (mat->shape)
101     {
102     case matrix_full:
103         transp = matrix_alloc(n, m, matrix_full, float_v);
104         el2 = transp->el.float_v;
105         for (i = 0; i < m; ++i)
106             for (j = 0; j < n; ++j)
107                 el2[j][i] = el1[i][j];
108         break;
109     case matrix_lower:
110         transp = matrix_alloc(n, m, matrix_lower, float_v);
111         el2 = transp->el.float_v;
112         for (i = 0; i < m; ++i)
113             for (j = i; j < m; ++j)
114                 el2[j][i] = el1[i][j];
115         break;
116     case matrix_upper:
117         transp = matrix_alloc(n, m, matrix_upper, float_v);
118         el2 = transp->el.float_v;
119         for (i = 0; i < m; ++i)
120             for (j = 0; j <= i; ++j)
121                 el2[j][i] = el1[i][j];
122         break;
123     case matrix_symmetric:
124         return (matrix_copy(mat));
125     default:
126         transp = matrix_alloc(n, m, matrix_full, float_v);
127         el2 = transp->el.float_v;
128         for (i = 0; i < m; ++i)
129             for (j = 0; j < n; ++j)
130                 el2[j][i] = matrix_getf(mat, i, j);
131         break;
132     }
133     return (transp);
134 }
135 
136 Matrix *dmatrix_transp(Matrix * mat)
137 {
138     Matrix *transp;
139     double **el1, **el2;
140     int     m, n;
141     int     i, j;
142 
143     if (mat == NULL)
144         return (NULL);
145 
146     m = mat->m;
147     n = mat->n;
148     el1 = mat->el.double_v;
149 
150     switch (mat->shape)
151     {
152     case matrix_full:
153         transp = matrix_alloc(n, m, matrix_full, double_v);
154         el2 = transp->el.double_v;
155         for (i = 0; i < m; ++i)
156             for (j = 0; j < n; ++j)
157                 el2[j][i] = el1[i][j];
158         break;
159     case matrix_lower:
160         transp = matrix_alloc(n, m, matrix_lower, double_v);
161         el2 = transp->el.double_v;
162         for (i = 0; i < m; ++i)
163             for (j = i; j < m; ++j)
164                 el2[j][i] = el1[i][j];
165         break;
166     case matrix_upper:
167         transp = matrix_alloc(n, m, matrix_upper, double_v);
168         el2 = transp->el.double_v;
169         for (i = 0; i < m; ++i)
170             for (j = 0; j <= i; ++j)
171                 el2[j][i] = el1[i][j];
172         break;
173     case matrix_symmetric:
174         return (matrix_copy(mat));
175     default:
176         transp = matrix_alloc(n, m, matrix_full, double_v);
177         el2 = transp->el.double_v;
178         for (i = 0; i < m; ++i)
179             for (j = 0; j < n; ++j)
180                 el2[j][i] = matrix_getf(mat, i, j);
181         break;
182     }
183     return (transp);
184 }
185 

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