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

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

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

  1 /**@(#)Matrix multiply (various)
  2  */
  3 
  4 #include <tina/sys.h>
  5 #include <tina/sysfuncs.h>
  6 #include <tina/math.h>
  7 #include <tina/mathfuncs.h>
  8 
  9 Vector *imatrix_vprod(Matrix * mat, Vector * vec);
 10 Vector *fmatrix_vprod(Matrix * mat, Vector * vec);
 11 Vector *dmatrix_vprod(Matrix * mat, Vector * vec);
 12 
 13 Vector *matrix_vprod(Matrix * mat, Vector * vec)
 14 {
 15     Matrix *m;
 16     Vector *u;
 17     Vector *v;
 18     Vartype vtype;
 19 
 20     if (mat == NULL || vec == NULL)
 21         return (NULL);
 22 
 23     /** choose type of product: e.g. int*float = float, etc. **/
 24 
 25     vtype = matrix_sup_vtype(mat->vtype, vec->vtype);
 26 
 27     /** make copy of required type **/
 28 
 29     m = matrix_cast_fill(mat, vtype);
 30     v = vector_cast(vec, vtype);
 31 
 32     switch (vtype)
 33     {
 34     case int_v:
 35         u = imatrix_vprod(m, v);
 36         break;
 37     case float_v:
 38         u = fmatrix_vprod(m, v);
 39         break;
 40     case double_v:
 41         u = dmatrix_vprod(m, v);
 42         break;
 43     default:
 44         u = NULL;
 45         break;
 46     }
 47 
 48     /** free copies **/
 49 
 50     matrix_free(m);
 51     vector_free(v);
 52 
 53     return (u);
 54 }
 55 
 56 Vector *imatrix_vprod(Matrix * mat, Vector * vec)
 57 {
 58     Vector *prod;
 59     int   **el1, *el2, *el3;
 60     int     sum;
 61     int     m, n;
 62     int     i, j;
 63 
 64     if (mat == NULL || vec == NULL)
 65         return (NULL);
 66 
 67     m = mat->m;
 68     n = MIN(mat->n, vec->n);
 69     prod = vector_alloc(m, int_v);
 70 
 71     el1 = mat->el.int_v;
 72     el2 = vec->data;
 73     el3 = prod->data;
 74 
 75     for (i = 0; i < m; i++)
 76     {
 77         sum = 0;
 78         for (j = 0; j < n; j++)
 79             sum += el1[i][j] * el2[j];
 80         el3[i] = sum;
 81     }
 82 
 83     return (prod);
 84 }
 85 
 86 Vector *fmatrix_vprod(Matrix * mat, Vector * vec)
 87 {
 88     Vector *prod;
 89     float **el1, *el2, *el3;
 90     double   sum;
 91     int     m, n;
 92     int     i, j;
 93 
 94     if (mat == NULL || vec == NULL)
 95         return (NULL);
 96 
 97     m = mat->m;
 98     n = MIN(mat->n, vec->n);
 99     prod = vector_alloc(m, float_v);
100 
101     el1 = mat->el.float_v;
102     el2 = vec->data;
103     el3 = prod->data;
104 
105     for (i = 0; i < m; i++)
106     {
107         sum = 0.0;
108         for (j = 0; j < n; j++)
109             sum += el1[i][j] * el2[j];
110         el3[i] = sum;
111     }
112 
113     return (prod);
114 }
115 
116 Vector *dmatrix_vprod(Matrix * mat, Vector * vec)
117 {
118     Vector *prod;
119     double **el1, *el2, *el3;
120     double  sum;
121     int     m, n;
122     int     i, j;
123 
124     if (mat == NULL || vec == NULL)
125         return (NULL);
126 
127     m = mat->m;
128     n = MIN(mat->n, vec->n);
129     prod = vector_alloc(m, double_v);
130 
131     el1 = mat->el.double_v;
132     el2 = vec->data;
133     el3 = prod->data;
134 
135     for (i = 0; i < m; i++)
136     {
137         sum = 0.0;
138         for (j = 0; j < n; j++)
139             sum += el1[i][j] * el2[j];
140         el3[i] = sum;
141     }
142 
143     return (prod);
144 }
145 

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