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

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

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

  1 /**@(#)Matrix elements setting. (Setting locations outside matrix is not an error).
  2  */
  3 
  4 #include <math.h>
  5 #include <stdio.h>
  6 #include <tina/sys.h>
  7 #include <tina/math.h>
  8 
  9 void    matrix_put_full(int val, Matrix * mat, int i, int j);
 10 void    matrix_putf_full(double val, Matrix * mat, int i, int j);
 11 void    matrix_putz_full(Complex val, Matrix * mat, int i, int j);
 12 void    matrix_putp_full(void *val, Matrix * mat, int i, int j);
 13 Complex cmplx();
 14 
 15 /** puts integer value into matrix, casting if necessary **/
 16 
 17 void    mat_putf(float val, Matrix * mat, int i, int j)
 18 {
 19     if (i < 0 || i >= mat->m || j < 0 || j >= mat->n)
 20         return;
 21     mat->el.float_v[i][j] = val;
 22 }
 23 
 24 void    matrix_put(int val, Matrix * mat, int i, int j)
 25 {
 26     if (mat == NULL)
 27         return;
 28 
 29     if (i < 0 || i >= mat->m || j < 0 || j >= mat->n)
 30         return;
 31 
 32     switch (mat->shape)
 33     {
 34     case matrix_full:
 35         matrix_put_full(val, mat, i, j);
 36         break;
 37     case matrix_lower:
 38     case matrix_symmetric:
 39         if (i < j)
 40             SWAP(int, i, j);
 41         matrix_put_full(val, mat, i, j);
 42         break;
 43     case matrix_upper:
 44         if (j < i)
 45             SWAP(int, i, j);
 46         matrix_put_full(val, mat, i, j);
 47         break;
 48     }
 49 }
 50 
 51 void    matrix_put_full(int val, Matrix * mat, int i, int j)
 52 {
 53     switch (mat->vtype)
 54     {
 55         case char_v:
 56         mat->el.char_v[i][j] = (char) val;
 57         break;
 58     case uchar_v:
 59         mat->el.uchar_v[i][j] = (unsigned char) val;
 60         break;
 61     case short_v:
 62         mat->el.short_v[i][j] = (short) val;
 63         break;
 64     case ushort_v:
 65         mat->el.ushort_v[i][j] = (unsigned short) val;
 66         break;
 67     case int_v:
 68         mat->el.int_v[i][j] = (int) val;
 69         break;
 70     case uint_v:
 71         mat->el.uint_v[i][j] = (unsigned int) val;
 72         break;
 73     case float_v:
 74         mat->el.float_v[i][j] = (float) val;
 75         break;
 76     case double_v:
 77         mat->el.double_v[i][j] = (double) val;
 78         break;
 79     case complex_v:
 80         mat->el.complex_v[i][j] = cmplx((double) val, 0.0);
 81         break;
 82     case ptr_v:
 83         mat->el.ptr_v[i][j] = (void *) val;
 84         break;
 85     }
 86 }
 87 
 88 /** puts double value into matrix, casting if necessary **/
 89 
 90 void    matrix_putf(double val, Matrix * mat, int i, int j)
 91 {
 92     if (mat == NULL)
 93         return;
 94 
 95     if (i < 0 || i >= mat->m || j < 0 || j >= mat->n)
 96         return;
 97 
 98     switch (mat->shape)
 99     {
100     case matrix_full:
101         matrix_putf_full(val, mat, i, j);
102         break;
103     case matrix_lower:
104     case matrix_symmetric:
105         if (i < j)
106             SWAP(int, i, j);
107         matrix_putf_full(val, mat, i, j);
108         break;
109     case matrix_upper:
110         if (j < i)
111             SWAP(int, i, j);
112         matrix_putf_full(val, mat, i, j);
113         break;
114     }
115 }
116 
117 void    matrix_putf_full(double val, Matrix * mat, int i, int j)
118 {
119     switch (mat->vtype)
120     {
121         case char_v:
122         mat->el.char_v[i][j] = (char) val;
123         break;
124     case uchar_v:
125         mat->el.uchar_v[i][j] = (unsigned char) val;
126         break;
127     case short_v:
128         mat->el.short_v[i][j] = (short) val;
129         break;
130     case ushort_v:
131         mat->el.ushort_v[i][j] = (unsigned short) val;
132         break;
133     case int_v:
134         mat->el.int_v[i][j] = (int) val;
135         break;
136     case uint_v:
137         mat->el.uint_v[i][j] = (unsigned int) val;
138         break;
139     case float_v:
140         mat->el.float_v[i][j] = (float) val;
141         break;
142     case double_v:
143         mat->el.double_v[i][j] = (double) val;
144         break;
145     case complex_v:
146         mat->el.complex_v[i][j] = cmplx((double) val, 0.0);
147         break;
148     case ptr_v:
149         mat->el.ptr_v[i][j] = (void *) (int) val;
150         break;
151     }
152 }
153 
154 /** puts complex value into matrix, casting if necessary **/
155 
156 void    matrix_putz(Complex val, Matrix * mat, int i, int j)
157 {
158     if (mat == NULL)
159         return;
160 
161     if (i < 0 || i >= mat->m || j < 0 || j >= mat->n)
162         return;
163 
164     switch (mat->shape)
165     {
166     case matrix_full:
167         matrix_putz_full(val, mat, i, j);
168         break;
169     case matrix_lower:
170     case matrix_symmetric:
171         if (i < j)
172             SWAP(int, i, j);
173         matrix_putz_full(val, mat, i, j);
174         break;
175     case matrix_upper:
176         if (j < i)
177             SWAP(int, i, j);
178         matrix_putz_full(val, mat, i, j);
179         break;
180     }
181 }
182 
183 void    matrix_putz_full(Complex val, Matrix * mat, int i, int j)
184 {
185     switch (mat->vtype)
186     {
187         case char_v:
188         mat->el.char_v[i][j] = (char) val.x;
189         break;
190     case uchar_v:
191         mat->el.uchar_v[i][j] = (unsigned char) val.x;
192         break;
193     case short_v:
194         mat->el.short_v[i][j] = (short) val.x;
195         break;
196     case ushort_v:
197         mat->el.ushort_v[i][j] = (unsigned short) val.x;
198         break;
199     case int_v:
200         mat->el.int_v[i][j] = (int) val.x;
201         break;
202     case uint_v:
203         mat->el.uint_v[i][j] = (unsigned int) val.x;
204         break;
205     case float_v:
206         mat->el.float_v[i][j] = (float) val.x;
207         break;
208     case double_v:
209         mat->el.double_v[i][j] = (double) val.x;
210         break;
211     case complex_v:
212         mat->el.complex_v[i][j] = val;
213         break;
214     case ptr_v:
215         mat->el.ptr_v[i][j] = (void *) (int) val.x;
216         break;
217     }
218 }
219 
220 /** puts ptr value into matrix, casting if necessary **/
221 
222 void    matrix_putp(void *val, Matrix * mat, int i, int j)
223 {
224     if (mat == NULL)
225         return;
226 
227     if (i < 0 || i >= mat->m || j < 0 || j >= mat->n)
228         return;
229 
230     switch (mat->shape)
231     {
232     case matrix_full:
233         matrix_putp_full(val, mat, i, j);
234         break;
235     case matrix_lower:
236     case matrix_symmetric:
237         if (i < j)
238             SWAP(int, i, j);
239         matrix_putp_full(val, mat, i, j);
240         break;
241     case matrix_upper:
242         if (j < i)
243             SWAP(int, i, j);
244         matrix_putp_full(val, mat, i, j);
245         break;
246     }
247 }
248 
249 void    matrix_putp_full(void *val, Matrix * mat, int i, int j)
250 {
251     switch (mat->vtype)
252     {
253         /* cast twice to avoid compiler warning: cast from pointer to
254          * integer of different size */
255         case char_v:
256         mat->el.char_v[i][j] = (char) (int) val;
257         break;
258     case uchar_v:
259         mat->el.uchar_v[i][j] = (unsigned char) (int) val;
260         break;
261     case short_v:
262         mat->el.short_v[i][j] = (short) (int) val;
263         break;
264     case ushort_v:
265         mat->el.ushort_v[i][j] = (unsigned short) (int) val;
266         break;
267     case int_v:
268         mat->el.int_v[i][j] = (int) val;
269         break;
270     case uint_v:
271         mat->el.uint_v[i][j] = (unsigned int) val;
272         break;
273     case float_v:
274         mat->el.float_v[i][j] = (float) (int) val;
275         break;
276     case double_v:
277         mat->el.double_v[i][j] = (double) (int) val;
278         break;
279     case complex_v:
280         mat->el.complex_v[i][j] = cmplx((double) (int) val, 0.0);
281         break;
282     case ptr_v:
283         mat->el.ptr_v[i][j] = val;
284         break;
285     }
286 }
287 

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