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

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

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

  1 /**@(#)Matrix handling (various types and shapes)
  2  */
  3 
  4 #include <tina/sys.h>
  5 #include <tina/math.h>
  6 #include <tina/mathfuncs.h>
  7 
  8 void    matrix_putf();
  9 
 10 Matrix_shape matrix_sup_shape(Matrix_shape shape1, Matrix_shape shape2)
 11 {
 12     if (shape1 != shape2)
 13         return (matrix_full);
 14     else
 15         return (shape1);
 16 }
 17 
 18 Vartype matrix_sup_vtype(Vartype vtype1, Vartype vtype2)
 19 {
 20     if (vtype1 == double_v || vtype2 == double_v)
 21         return (double_v);
 22     if (vtype1 == float_v || vtype2 == float_v)
 23         return (float_v);
 24     return (int_v);
 25 }
 26 
 27 int     matrix_swap_rows(Matrix * mat, int r1, int r2)
 28 {
 29     int     m, n;
 30     int     i;
 31 
 32     if (mat == NULL || mat->shape != matrix_full)
 33         return (0);
 34 
 35     m = mat->m;
 36     n = mat->n;
 37 
 38     if (r1 < 0 || r1 >= m || r2 < 0 || r2 > m)
 39         return (0);
 40 
 41     for (i = 0; i < n; ++i)
 42     {
 43         double  temp;
 44 
 45         temp = matrix_getf(mat, r1, i);
 46         matrix_putf(matrix_getf(mat, r2, i), mat, r1, i);
 47         matrix_putf(temp, mat, r2, i);
 48     }
 49     return (1);
 50 }
 51 
 52 int     matrix_swap_cols(Matrix * mat, int c1, int c2)
 53 {
 54     int     m, n;
 55     int     i;
 56 
 57     if (mat == NULL || mat->shape != matrix_full)
 58         return (0);
 59 
 60     m = mat->m;
 61     n = mat->n;
 62 
 63     if (c1 < 0 || c1 >= n || c2 < 0 || c2 > n)
 64         return (0);
 65 
 66     for (i = 0; i < m; ++i)
 67     {
 68         double  temp;
 69 
 70         temp = matrix_getf(mat, i, c1);
 71         matrix_putf(matrix_getf(mat, i, c2), mat, i, c1);
 72         matrix_putf(temp, mat, i, c2);
 73     }
 74     return (1);
 75 }
 76 
 77 Vector *matrix_col_vector(Matrix * mat, int c)
 78 {
 79     Vector *col;
 80     Vector *vector_alloc();
 81     int     m, n;
 82     int     i;
 83 
 84     if (mat == NULL)
 85         return (NULL);
 86 
 87     m = mat->m;
 88     n = mat->n;
 89 
 90     if (c < 0 || c >= n)
 91         return (NULL);
 92 
 93     col = vector_alloc(m, mat->vtype);
 94 
 95     for (i = 0; i < m; ++i)
 96     {
 97         vector_putf(matrix_getf(mat, i, c), col, i);
 98     }
 99     return (col);
100 }
101 

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