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

Linux Cross Reference
Tina5/tina-libs/tina/math/mathMatr_vprod.c

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

  1 /**********
  2  *
  3  * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
  4  * University of Manchester, UK.  All rights reserved.
  5  * 
  6  * Redistribution and use in source and binary forms, with or without modification, 
  7  * are permitted provided that the following conditions are met:
  8  * 
  9  *   . Redistributions of source code must retain the above copyright notice, 
 10  *     this list of conditions and the following disclaimer.
 11  *    
 12  *   . Redistributions in binary form must reproduce the above copyright notice,
 13  *     this list of conditions and the following disclaimer in the documentation 
 14  *     and/or other materials provided with the distribution.
 15  * 
 16  *   . Neither the name of the University of Manchester nor the names of its
 17  *     contributors may be used to endorse or promote products derived from this 
 18  *     software without specific prior written permission.
 19  * 
 20  * 
 21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 31  * POSSIBILITY OF SUCH DAMAGE.
 32  *
 33  **********
 34  *
 35  * Program :    TINA
 36  * File    :  $Source: /home/tina/cvs/tina-libs/tina/math/mathMatr_vprod.c,v $
 37  * Date    :  $Date: 2003/09/23 11:32:20 $
 38  * Version :  $Revision: 1.4 $
 39  * CVS Id  :  $Id: mathMatr_vprod.c,v 1.4 2003/09/23 11:32:20 matts Exp $
 40  *
 41  * Author  :  Legacy TINA
 42  *
 43  * Notes : Matrix multiply (various)
 44  *
 45  *********
 46 */
 47 /** 
 48  *  @file
 49  *  @brief  Functions for calculating the inner product of a Matrix with a Vector.      
 50  *
 51  *
 52  * 
 53 */
 54 
 55 #include "mathMatr_vprod.h"
 56 
 57 #if HAVE_CONFIG_H
 58 #include <config.h>
 59 #endif
 60 
 61 #include <tina/sys/sysDef.h>
 62 #include <tina/sys/sysPro.h>
 63 #include <tina/math/math_MatrDef.h>
 64 #include <tina/math/math_VecDef.h>
 65 #include <tina/math/math_VecPro.h>
 66 #include <tina/math/mathMatr_util.h>
 67 #include <tina/math/mathMatr_cast.h>
 68 #include <tina/math/mathMatr_free.h>
 69 #include <tina/math/mathMatr_fill.h>
 70 
 71 Vector         *matrix_vprod(Matrix * mat, Vector * vec)
 72 {
 73         Matrix         *m;
 74         Vector         *u;
 75         Vector         *v;
 76         Vartype         vtype;
 77 
 78         if (mat == NULL || vec == NULL)
 79                 return (NULL);
 80 
 81         /** choose type of product: e.g. int*float = float, etc. **/
 82 
 83         vtype = matrix_sup_vtype(mat->vtype, vec->vtype);
 84 
 85         /** make copy of required type **/
 86 
 87         m = matrix_cast_fill(mat, vtype);
 88         v = vector_cast(vec, vtype);
 89 
 90         switch (vtype)
 91         {
 92         case int_v:
 93                 u = imatrix_vprod(m, v);
 94                 break;
 95         case float_v:
 96                 u = fmatrix_vprod(m, v);
 97                 break;
 98         case double_v:
 99                 u = dmatrix_vprod(m, v);
100                 break;
101         default:
102                 u = NULL;
103                 break;
104         }
105 
106         /** free copies **/
107 
108         matrix_free(m);
109         vector_free(v);
110 
111         return (u);
112 }
113 
114 Vector         *imatrix_vprod(Matrix * mat, Vector * vec)
115 {
116         Vector         *prod;
117         int           **el1, *el2, *el3;
118         int             sum;
119         int             m, n;
120         int             i, j;
121 
122         if (mat == NULL || vec == NULL)
123                 return (NULL);
124 
125         m = mat->m;
126         n = MIN(mat->n, vec->n);
127         prod = vector_alloc(m, int_v);
128 
129         el1 = mat->el.int_v;
130         el2 = vec->data;
131         el3 = prod->data;
132 
133         for (i = 0; i < m; i++)
134         {
135                 sum = 0;
136                 for (j = 0; j < n; j++)
137                         sum += el1[i][j] * el2[j];
138                 el3[i] = sum;
139         }
140 
141         return (prod);
142 }
143 
144 Vector         *fmatrix_vprod(Matrix * mat, Vector * vec)
145 {
146         Vector         *prod;
147         float         **el1, *el2, *el3;
148         double          sum;
149         int             m, n;
150         int             i, j;
151 
152         if (mat == NULL || vec == NULL)
153                 return (NULL);
154 
155         m = mat->m;
156         n = MIN(mat->n, vec->n);
157         prod = vector_alloc(m, float_v);
158 
159         el1 = mat->el.float_v;
160         el2 = vec->data;
161         el3 = prod->data;
162 
163         for (i = 0; i < m; i++)
164         {
165                 sum = 0.0;
166                 for (j = 0; j < n; j++)
167                         sum += el1[i][j] * el2[j];
168                 el3[i] = sum;
169         }
170 
171         return (prod);
172 }
173 
174 Vector         *dmatrix_vprod(Matrix * mat, Vector * vec)
175 {
176         Vector         *prod;
177         double        **el1, *el2, *el3;
178         double          sum;
179         int             m, n;
180         int             i, j;
181 
182         if (mat == NULL || vec == NULL)
183                 return (NULL);
184 
185         m = mat->m;
186         n = MIN(mat->n, vec->n);
187         prod = vector_alloc(m, double_v);
188 
189         el1 = mat->el.double_v;
190         el2 = vec->data;
191         el3 = prod->data;
192 
193         for (i = 0; i < m; i++)
194         {
195                 sum = 0.0;
196                 for (j = 0; j < n; j++)
197                         sum += el1[i][j] * el2[j];
198                 el3[i] = sum;
199         }
200 
201         return (prod);
202 }
203 

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