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

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

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

  1 /**@(#)Matrix negation. (Negate elements of matrix)
  2  */
  3 
  4 #include <math.h>
  5 #include <stdio.h>
  6 #include <tina/sys.h>
  7 #include <tina/math.h>
  8 
  9 int     matrix_get();
 10 double  matrix_getf();
 11 void    matrix_put();
 12 void    matrix_putf();
 13 
 14 Matrix *matrix_copy();
 15 
 16 Matrix *matrix_minus(Matrix * mat)
 17 {
 18     int     m, n, i, j;
 19     Matrix *minus;
 20 
 21     if (mat == NULL)
 22         return (NULL);
 23 
 24     minus = matrix_copy(mat);
 25     m = mat->m;
 26     n = mat->n;
 27 
 28     /** explicit for standard shapes **/
 29 
 30     switch (OPAIR(mat->vtype, mat->shape))
 31     {
 32     case OPAIR(int_v, matrix_full):
 33         {
 34             int   **el = minus->el.int_v;
 35 
 36             for (i = 0; i < m; i++)
 37                 for (j = 0; j < n; j++)
 38                     el[i][j] = -el[i][j];
 39             return (minus);
 40         }
 41     case OPAIR(float_v, matrix_full):
 42         {
 43             float **el = minus->el.float_v;
 44 
 45             for (i = 0; i < m; i++)
 46                 for (j = 0; j < n; j++)
 47                     el[i][j] = -el[i][j];
 48             return (minus);
 49         }
 50     case OPAIR(double_v, matrix_full):
 51         {
 52             double **el = minus->el.double_v;
 53 
 54             for (i = 0; i < m; i++)
 55                 for (j = 0; j < n; j++)
 56                     el[i][j] = -el[i][j];
 57             return (minus);
 58         }
 59     case OPAIR(int_v, matrix_lower):
 60     case OPAIR(int_v, matrix_symmetric):
 61         {
 62             int   **el = minus->el.int_v;
 63 
 64             for (i = 0; i < m; i++)
 65                 for (j = 0; j <= i; j++)
 66                     el[i][j] = -el[i][j];
 67             return (minus);
 68         }
 69     case OPAIR(float_v, matrix_lower):
 70     case OPAIR(float_v, matrix_symmetric):
 71         {
 72             float **el = minus->el.float_v;
 73 
 74             for (i = 0; i < m; i++)
 75                 for (j = 0; j <= i; j++)
 76                     el[i][j] = -el[i][j];
 77             return (minus);
 78         }
 79     case OPAIR(double_v, matrix_lower):
 80     case OPAIR(double_v, matrix_symmetric):
 81         {
 82             double **el = minus->el.double_v;
 83 
 84             for (i = 0; i < m; i++)
 85                 for (j = 0; j <= i; j++)
 86                     el[i][j] = -el[i][j];
 87             return (minus);
 88         }
 89     case OPAIR(int_v, matrix_upper):
 90         {
 91             int   **el = minus->el.int_v;
 92 
 93             for (i = 0; i < m; i++)
 94                 for (j = i; j < n; j++)
 95                     el[i][j] = -el[i][j];
 96             return (minus);
 97         }
 98     case OPAIR(float_v, matrix_upper):
 99         {
100             float **el = minus->el.float_v;
101 
102             for (i = 0; i < m; i++)
103                 for (j = i; j < n; j++)
104                     el[i][j] = -el[i][j];
105             return (minus);
106         }
107     case OPAIR(double_v, matrix_upper):
108         {
109             double **el = minus->el.double_v;
110 
111             for (i = 0; i < m; i++)
112                 for (j = i; j < n; j++)
113                     el[i][j] = -el[i][j];
114             return (minus);
115         }
116     }
117 
118     /** generic for other shapes **/
119 
120     switch (mat->vtype)
121     {
122     case int_v:
123         for (i = 0; i < m; i++)
124             for (j = 0; j < n; j++)
125                 matrix_put(-matrix_get(mat, i, j), minus, i, j);
126         break;
127     case float_v:
128     case double_v:
129         for (i = 0; i < m; i++)
130             for (j = 0; j < n; j++)
131                 matrix_putf(-matrix_getf(mat, i, j), minus, i, j);
132         break;
133     }
134     return (minus);
135 }
136 
137 Matrix *fmatrix_minus(Matrix * mat)     /* assume full float matrix */
138 
139 {
140     int     m, n, i, j;
141     Matrix *minus;
142     float **el;
143 
144     if (mat == NULL)
145         return (NULL);
146 
147     minus = matrix_copy(mat);
148     m = mat->m;
149     n = mat->n;
150 
151     el = minus->el.float_v;
152     for (i = 0; i < m; i++)
153         for (j = 0; j < n; j++)
154             el[i][j] = -el[i][j];
155     return (minus);
156 }
157 
158 Matrix *fmatrix_minus_inplace(Matrix * mat)     /* assume full float
159                                                  * matrix */
160 
161 {
162     int     m, n, i, j;
163     float **el;
164 
165     if (mat == NULL)
166         return (NULL);
167 
168     m = mat->m;
169     n = mat->n;
170 
171     el = mat->el.float_v;
172     for (i = 0; i < m; i++)
173         for (j = 0; j < n; j++)
174             el[i][j] = -el[i][j];
175     return (mat);
176 }
177 

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