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

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

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

  1 /**@(#)Matrix multiplied by a scalar.
  2  */
  3 
  4 #include <tina/sys.h>
  5 #include <tina/math.h>
  6 #include <tina/mathfuncs.h>
  7 
  8 Vartype matrix_sup_vtype();
  9 
 10 int     matrix_get();
 11 double  matrix_getf();
 12 
 13 Matrix *matrix_alloc();
 14 Matrix *matrix_cast();
 15 
 16 Matrix *imatrix_times();
 17 Matrix *fmatrix_times(double k, Matrix * mat);
 18 Matrix *dmatrix_times(double k, Matrix * mat);
 19 
 20 Matrix *matrix_times(double k, Matrix * mat)
 21 {
 22     Matrix *prod;
 23     Matrix *m;
 24     Vartype vtype;
 25 
 26     if (mat == NULL)
 27         return (NULL);
 28 
 29     vtype = matrix_sup_vtype(mat->vtype, float_v);
 30 
 31     if (mat->vtype != vtype)
 32         m = matrix_cast(mat, vtype);
 33     else
 34         m = mat;
 35 
 36     switch (vtype)
 37     {
 38     case float_v:
 39         prod = fmatrix_times(k, m);
 40         break;
 41     case double_v:
 42         prod = dmatrix_times(k, m);
 43     }
 44     if (mat->vtype != vtype)
 45         matrix_free(m);
 46 
 47     return (prod);
 48 }
 49 
 50 Matrix *fmatrix_times(double k, Matrix * mat)
 51 {
 52     Matrix *prod;
 53     int     m = mat->m;
 54     int     n = mat->n;
 55     float **el1 = mat->el.float_v;
 56     float **el2;
 57     int     i, j;
 58 
 59     switch (mat->shape)
 60     {
 61     case matrix_full:
 62         prod = matrix_alloc(m, n, matrix_full, float_v);
 63         el2 = prod->el.float_v;
 64         for (i = 0; i < m; ++i)
 65             for (j = 0; j < n; ++j)
 66                 el2[i][j] = k * el1[i][j];
 67         break;
 68     case matrix_lower:
 69         prod = matrix_alloc(m, n, matrix_lower, float_v);
 70         el2 = prod->el.float_v;
 71         for (i = 0; i < m; ++i)
 72             for (j = 0; j <= i; ++j)
 73                 el2[i][j] = k * el1[i][j];
 74         break;
 75     case matrix_upper:
 76         prod = matrix_alloc(m, n, matrix_upper, float_v);
 77         el2 = prod->el.float_v;
 78         for (i = 0; i < m; ++i)
 79             for (j = i; j < n; ++j)
 80                 el2[i][j] = k * el1[i][j];
 81         break;
 82     case matrix_symmetric:
 83         prod = matrix_alloc(m, n, matrix_symmetric, float_v);
 84         el2 = prod->el.float_v;
 85         for (i = 0; i < m; ++i)
 86             for (j = 0; j <= i; ++j)
 87                 el2[i][j] = k * el1[i][j];
 88         break;
 89     default:
 90         prod = matrix_alloc(m, n, matrix_full, float_v);
 91         for (i = 0; i < m; ++i)
 92             for (j = 0; j < n; ++j)
 93                 matrix_putf(k * matrix_getf(mat, i, j), prod, i, j);
 94         break;
 95     }
 96 
 97     return (prod);
 98 }
 99 
100 Matrix *dmatrix_times(double k, Matrix * mat)
101 {
102     Matrix *prod;
103     int     m = mat->m;
104     int     n = mat->n;
105     double **el1 = mat->el.double_v;
106     double **el2;
107     int     i, j;
108 
109     switch (mat->shape)
110     {
111     case matrix_full:
112         prod = matrix_alloc(m, n, matrix_full, double_v);
113         el2 = prod->el.double_v;
114         for (i = 0; i < m; ++i)
115             for (j = 0; j < n; ++j)
116                 el2[i][j] = k * el1[i][j];
117         break;
118     case matrix_lower:
119         prod = matrix_alloc(m, n, matrix_lower, double_v);
120         el2 = prod->el.double_v;
121         for (i = 0; i < m; ++i)
122             for (j = 0; j <= i; ++j)
123                 el2[i][j] = k * el1[i][j];
124         break;
125     case matrix_upper:
126         prod = matrix_alloc(m, n, matrix_upper, double_v);
127         el2 = prod->el.double_v;
128         for (i = 0; i < m; ++i)
129             for (j = i; j < n; ++j)
130                 el2[i][j] = k * el1[i][j];
131         break;
132     case matrix_symmetric:
133         prod = matrix_alloc(m, n, matrix_symmetric, double_v);
134         el2 = prod->el.double_v;
135         for (i = 0; i < m; ++i)
136             for (j = 0; j <= i; ++j)
137                 el2[i][j] = k * el1[i][j];
138         break;
139     default:
140         prod = matrix_alloc(m, n, matrix_full, double_v);
141         for (i = 0; i < m; ++i)
142             for (j = 0; j < n; ++j)
143                 matrix_putf(k * matrix_getf(mat, i, j), prod, i, j);
144         break;
145     }
146 
147     return (prod);
148 }
149 

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