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

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

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

  1 /**@(#)Matrix input/output (various types and shapes)
  2  */
  3 
  4 #include <math.h>
  5 #include <stdio.h>
  6 #include <tina/sys.h>
  7 #include <tina/sysfuncs.h>
  8 #include <tina/math.h>
  9 #include <tina/mathfuncs.h>
 10 
 11 int     matrix_get();
 12 double  matrix_getf();
 13 Complex matrix_getz();
 14 void   *matrix_getp();
 15 
 16 void    cmatrix_format(Matrix * mat);
 17 void    cmatrix_format_full(Matrix * mat);
 18 void    cmatrix_format_lower(Matrix * mat);
 19 void    cmatrix_format_gen(Matrix * mat);
 20 void    smatrix_format(Matrix * mat);
 21 void    smatrix_format_full(Matrix * mat);
 22 void    smatrix_format_lower(Matrix * mat);
 23 void    smatrix_format_gen(Matrix * mat);
 24 void    imatrix_format(Matrix * mat);
 25 void    imatrix_format_full(Matrix * mat);
 26 void    imatrix_format_lower(Matrix * mat);
 27 void    imatrix_format_gen(Matrix * mat);
 28 void    fmatrix_format(Matrix * mat);
 29 void    fmatrix_format_full(Matrix * mat);
 30 void    fmatrix_format_lower(Matrix * mat);
 31 void    fmatrix_format_gen(Matrix * mat);
 32 void    dmatrix_format(Matrix * mat);
 33 void    dmatrix_format_full(Matrix * mat);
 34 void    dmatrix_format_lower(Matrix * mat);
 35 void    dmatrix_format_gen(Matrix * mat);
 36 void    zmatrix_format(Matrix * mat);
 37 void    zmatrix_format_full(Matrix * mat);
 38 void    zmatrix_format_lower(Matrix * mat);
 39 void    zmatrix_format_gen(Matrix * mat);
 40 void    pmatrix_format(Matrix * mat);
 41 void    pmatrix_format_full(Matrix * mat);
 42 void    pmatrix_format_lower(Matrix * mat);
 43 void    pmatrix_format_gen(Matrix * mat);
 44 
 45 static void format_header(Matrix * mat)
 46 {
 47     format("matrix: ");
 48     format_shape(mat->shape);
 49     format(" %d by %d  of ", mat->m, mat->n);
 50     format_vtype(mat->vtype);
 51     format("\n");
 52 }
 53 
 54 void    mat_format(Matrix * mat)
 55 {
 56     int     i, j;
 57     int     m = mat->m;
 58     int     n = mat->n;
 59     float **el = mat->el.float_v;
 60 
 61     format_header(mat);
 62 
 63     for (i = 0; i < m; ++i)
 64     {
 65         for (j = 0; j < n; ++j)
 66             format("%12.6f ", el[i][j]);
 67         format("\n");
 68     }
 69 }
 70 
 71 void    matrix_format(Matrix * mat)
 72 {
 73     if (mat == NULL)
 74     {
 75         format("nil ");
 76         return;
 77     }
 78     switch (mat->vtype)
 79     {
 80     case char_v:
 81     case uchar_v:
 82         cmatrix_format(mat);
 83         break;
 84     case short_v:
 85     case ushort_v:
 86         smatrix_format(mat);
 87         break;
 88     case int_v:
 89     case uint_v:
 90         imatrix_format(mat);
 91         break;
 92     case float_v:
 93         fmatrix_format(mat);
 94         break;
 95     case double_v:
 96         dmatrix_format(mat);
 97         break;
 98     case complex_v:
 99         zmatrix_format(mat);
100         break;
101     case ptr_v:
102         pmatrix_format(mat);
103         break;
104     }
105 }
106 
107 void    cmatrix_format(Matrix * mat)
108 {
109     switch (mat->shape)
110     {
111         case matrix_full:
112         cmatrix_format_full(mat);
113         break;
114     case matrix_lower:
115     case matrix_symmetric:
116         cmatrix_format_lower(mat);
117         break;
118     default:
119         cmatrix_format_gen(mat);
120         break;
121     }
122 }
123 
124 void    cmatrix_format_full(Matrix * mat)
125 {
126     int     i, j;
127     int     m = mat->m;
128     int     n = mat->n;
129     char  **el = mat->el.char_v;
130 
131     format_header(mat);
132 
133     for (i = 0; i < m; ++i)
134     {
135         for (j = 0; j < n; ++j)
136             format("%c ", el[i][j]);
137         format("\n");
138     }
139 }
140 
141 void    cmatrix_format_lower(Matrix * mat)
142 {
143     int     i, j;
144     int     m = mat->m;
145     char  **el = mat->el.char_v;
146 
147     format_header(mat);
148 
149     for (i = 0; i < m; ++i)
150     {
151         for (j = 0; j <= i; ++j)
152             format("%c ", el[i][j]);
153         format("\n");
154     }
155 }
156 
157 void    cmatrix_format_gen(Matrix * mat)
158 {
159     int     i, j;
160     int     m = mat->m;
161     int     n = mat->n;
162 
163     format_header(mat);
164 
165     for (i = 0; i < m; ++i)
166     {
167         for (j = 0; j < n; ++j)
168             format("%c ", matrix_get(mat, i, j));
169         format("\n");
170     }
171 }
172 
173 void    smatrix_format(Matrix * mat)
174 {
175     switch (mat->shape)
176     {
177         case matrix_full:
178         smatrix_format_full(mat);
179         break;
180     case matrix_lower:
181     case matrix_symmetric:
182         smatrix_format_lower(mat);
183         break;
184     default:
185         smatrix_format_gen(mat);
186         break;
187     }
188 }
189 
190 
191 void    smatrix_format_full(Matrix * mat)
192 {
193     int     i, j;
194     int     m = mat->m;
195     int     n = mat->n;
196     short **el = mat->el.short_v;
197 
198     format_header(mat);
199 
200     for (i = 0; i < m; ++i)
201     {
202         for (j = 0; j < n; ++j)
203             format("%10d ", el[i][j]);
204         format("\n");
205     }
206 }
207 
208 void    smatrix_format_lower(Matrix * mat)
209 {
210     int     i, j;
211     int     m = mat->m;
212     short **el = mat->el.short_v;
213 
214     format_header(mat);
215 
216     for (i = 0; i < m; ++i)
217     {
218         for (j = 0; j <= i; ++j)
219             format("%10d ", el[i][j]);
220         format("\n");
221     }
222 }
223 
224 void    smatrix_format_gen(Matrix * mat)
225 {
226     int     i, j;
227     int     m = mat->m;
228     int     n = mat->n;
229 
230     format_header(mat);
231 
232     for (i = 0; i < m; ++i)
233     {
234         for (j = 0; j < n; ++j)
235             format("%10d ", matrix_get(mat, i, j));
236         format("\n");
237     }
238 }
239 
240 void    imatrix_format(Matrix * mat)
241 {
242     switch (mat->shape)
243     {
244         case matrix_full:
245         imatrix_format_full(mat);
246         break;
247     case matrix_lower:
248     case matrix_symmetric:
249         imatrix_format_lower(mat);
250         break;
251     default:
252         imatrix_format_gen(mat);
253         break;
254     }
255 }
256 
257 
258 void    imatrix_format_full(Matrix * mat)
259 {
260     int     i, j;
261     int     m = mat->m;
262     int     n = mat->n;
263     int   **el = mat->el.int_v;
264 
265     format_header(mat);
266 
267     for (i = 0; i < m; ++i)
268     {
269         for (j = 0; j < n; ++j)
270             format("%10d ", el[i][j]);
271         format("\n");
272     }
273 }
274 
275 void    imatrix_format_lower(Matrix * mat)
276 {
277     int     i, j;
278     int     m = mat->m;
279     int   **el = mat->el.int_v;
280 
281     format_header(mat);
282 
283     for (i = 0; i < m; ++i)
284     {
285         for (j = 0; j <= i; ++j)
286             format("%10d ", el[i][j]);
287         format("\n");
288     }
289 }
290 
291 void    imatrix_format_gen(Matrix * mat)
292 {
293     int     i, j;
294     int     m = mat->m;
295     int     n = mat->n;
296 
297     format_header(mat);
298 
299     for (i = 0; i < m; ++i)
300     {
301         for (j = 0; j < n; ++j)
302             format("%10d ", matrix_get(mat, i, j));
303         format("\n");
304     }
305 }
306 
307 void    fmatrix_format(Matrix * mat)
308 {
309     switch (mat->shape)
310     {
311         case matrix_full:
312         fmatrix_format_full(mat);
313         break;
314     case matrix_lower:
315     case matrix_symmetric:
316         fmatrix_format_lower(mat);
317         break;
318     default:
319         fmatrix_format_gen(mat);
320         break;
321     }
322 }
323 
324 void    fmatrix_format_full(Matrix * mat)
325 {
326     int     i, j;
327     int     m = mat->m;
328     int     n = mat->n;
329     float **el = mat->el.float_v;
330 
331     format_header(mat);
332 
333     for (i = 0; i < m; ++i)
334     {
335         for (j = 0; j < n; ++j)
336             format("%12.6f ", el[i][j]);
337         format("\n");
338     }
339 }
340 
341 void    fmatrix_format_lower(Matrix * mat)
342 {
343     int     i, j;
344     int     m = mat->m;
345     float **el = mat->el.float_v;
346 
347     format_header(mat);
348 
349     for (i = 0; i < m; ++i)
350     {
351         for (j = 0; j <= i; ++j)
352             format("%12.6f ", el[i][j]);
353         format("\n");
354     }
355 }
356 
357 void    fmatrix_format_gen(Matrix * mat)
358 {
359     int     i, j;
360     int     m = mat->m;
361     int     n = mat->n;
362 
363     format_header(mat);
364 
365     for (i = 0; i < m; ++i)
366     {
367         for (j = 0; j < n; ++j)
368             format("%12.6f ", matrix_getf(mat, i, j));
369         format("\n");
370     }
371 }
372 
373 void    dmatrix_format(Matrix * mat)
374 {
375     switch (mat->shape)
376     {
377         case matrix_full:
378         dmatrix_format_full(mat);
379         break;
380     case matrix_lower:
381     case matrix_symmetric:
382         dmatrix_format_lower(mat);
383         break;
384     default:
385         dmatrix_format_gen(mat);
386         break;
387     }
388 }
389 
390 void    dmatrix_format_full(Matrix * mat)
391 {
392     int     i, j;
393     int     m = mat->m;
394     int     n = mat->n;
395     double **el = mat->el.double_v;
396 
397     format_header(mat);
398 
399     for (i = 0; i < m; ++i)
400     {
401         for (j = 0; j < n; ++j)
402             format("%12.6f ", el[i][j]);
403         format("\n");
404     }
405 }
406 
407 void    dmatrix_format_lower(Matrix * mat)
408 {
409     int     i, j;
410     int     m = mat->m;
411     double **el = mat->el.double_v;
412 
413     format_header(mat);
414 
415     for (i = 0; i < m; ++i)
416     {
417         for (j = 0; j <= i; ++j)
418             format("%12.6f ", el[i][j]);
419         format("\n");
420     }
421 }
422 
423 void    dmatrix_format_gen(Matrix * mat)
424 {
425     int     i, j;
426     int     m = mat->m;
427     int     n = mat->n;
428 
429     format_header(mat);
430 
431     for (i = 0; i < m; ++i)
432     {
433         for (j = 0; j < n; ++j)
434             format("%12.6f ", matrix_getf(mat, i, j));
435         format("\n");
436     }
437 }
438 
439 void    zmatrix_format(Matrix * mat)
440 {
441     switch (mat->shape)
442     {
443         case matrix_full:
444         zmatrix_format_full(mat);
445         break;
446     case matrix_lower:
447     case matrix_symmetric:
448         zmatrix_format_lower(mat);
449         break;
450     default:
451         zmatrix_format_gen(mat);
452         break;
453     }
454 }
455 
456 void    zmatrix_format_full(Matrix * mat)
457 {
458     int     i, j;
459     int     m = mat->m;
460     int     n = mat->n;
461     Complex **el = mat->el.complex_v;
462 
463     format_header(mat);
464 
465     for (i = 0; i < m; ++i)
466     {
467         for (j = 0; j < n; ++j)
468             format("(%12.6f,%12.6f) ", el[i][j].x, el[i][j].y);
469         format("\n");
470     }
471 }
472 
473 void    zmatrix_format_lower(Matrix * mat)
474 {
475     int     i, j;
476     int     m = mat->m;
477     Complex **el = mat->el.complex_v;
478 
479     format_header(mat);
480 
481     for (i = 0; i < m; ++i)
482     {
483         for (j = 0; j <= i; ++j)
484             format("(%12.6f,%12.6f) ", el[i][j].x, el[i][j].y);
485         format("\n");
486     }
487 }
488 
489 void    zmatrix_format_gen(Matrix * mat)
490 {
491     int     i, j;
492     int     m = mat->m;
493     int     n = mat->n;
494 
495     format_header(mat);
496 
497     for (i = 0; i < m; ++i)
498     {
499         for (j = 0; j < n; ++j)
500         {
501             Complex val = {Complex_id};
502 
503             val = matrix_getz(mat, i, j);
504             format("(%12.6f,%12.6f) ", val.x, val.y);
505         }
506         format("\n");
507     }
508 }
509 
510 void    ptr_default_print(void *ptr)
511 {
512     if (ptr == NULL)
513         format(" 0");
514     else
515         format(" *");
516 }
517 
518 static void (*ptr_print) () = ptr_default_print;
519 
520 void    ptr_set_print(void (*newprint) ( /* ??? */ ))
521 {
522     ptr_print = newprint;
523 }
524 
525 void    (*ptr_get_print(void)) ( /* ??? */ )
526 {
527     return (ptr_print);
528 }
529 
530 void    pmatrix_format(Matrix * mat)
531 {
532     switch (mat->shape)
533     {
534         case matrix_full:
535         pmatrix_format_full(mat);
536         break;
537     case matrix_lower:
538     case matrix_symmetric:
539         pmatrix_format_lower(mat);
540         break;
541     default:
542         pmatrix_format_gen(mat);
543         break;
544     }
545 }
546 
547 void    pmatrix_format_full(Matrix * mat)
548 {
549     int     i, j;
550     int     m = mat->m;
551     int     n = mat->n;
552     void ***el = mat->el.ptr_v;
553 
554     format_header(mat);
555 
556     for (i = 0; i < m; ++i)
557     {
558         for (j = 0; j < n; ++j)
559             ptr_print(el[i][j]);
560         format("\n");
561     }
562 }
563 
564 void    pmatrix_format_lower(Matrix * mat)
565 {
566     int     i, j;
567     int     m = mat->m;
568     void ***el = mat->el.ptr_v;
569 
570     format_header(mat);
571 
572     for (i = 0; i < m; ++i)
573     {
574         for (j = 0; j <= i; ++j)
575             ptr_print(el[i][j]);
576         format("\n");
577     }
578 }
579 
580 void    pmatrix_format_gen(Matrix * mat)
581 {
582     int     i, j;
583     int     m = mat->m;
584     int     n = mat->n;
585 
586     format_header(mat);
587 
588     for (i = 0; i < m; ++i)
589     {
590         for (j = 0; j < n; ++j)
591         {
592             void   *val;
593 
594             val = matrix_getp(mat, i, j);
595             ptr_print(val);
596         }
597         format("\n");
598     }
599 }
600 

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