SCIRun  5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DenseColMajMatrixMultiplication.h
Go to the documentation of this file.
1 /*
2  For more information, please see: http://software.sci.utah.edu
3 
4  The MIT License
5 
6  Copyright (c) 2009 Scientific Computing and Imaging Institute,
7  University of Utah.
8 
9 
10  Permission is hereby granted, free of charge, to any person obtaining a
11  copy of this software and associated documentation files (the "Software"),
12  to deal in the Software without restriction, including without limitation
13  the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  and/or sell copies of the Software, and to permit persons to whom the
15  Software is furnished to do so, subject to the following conditions:
16 
17  The above copyright notice and this permission notice shall be included
18  in all copies or substantial portions of the Software.
19 
20  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26  DEALINGS IN THE SOFTWARE.
27 */
28 
29 
30 
31 /*
32  *@file DenseColMajMatrixMultiplication.h
33  *@brief DenseColMaj matrices
34  *
35  *@author
36  * Steven G. Parker
37  * Department of Computer Science
38  * University of Utah
39  *@date October 1994
40  *
41  */
42 
43 #ifndef CORE_DATATYPES_DENSECOLMAJMATRIXMULTIPLICATION_H
44 #define CORE_DATATYPES_DENSECOLMAJMATRIXMULTIPLICATION_H
45 
46 namespace SCIRun {
47 
48 template <typename T>
49 void
51  index_type beg, index_type end,
52  int spVec) const
53 {
54  // Compute A*x=b
55  ASSERTEQ(x.nrows(), this->ncols_);
56  ASSERTEQ(b.nrows(), this->nrows_);
57  if (beg == -1) beg = 0;
58  if (end == -1) end = this->nrows_;
59  index_type i, j;
60  if (!spVec)
61  {
62  for (i=beg; i<end; i++)
63  {
64  double sum = 0.0;
65  for (j=0; j<this->ncols_; j++)
66  {
67  sum += iget(i, j) * x[j];
68  }
69  b[i] = sum;
70  }
71  }
72  else
73  {
74  for (i=beg; i<end; i++) b[i] = 0.0;
75  for (j=0; j<this->ncols_; j++)
76  {
77  if (x[j])
78  {
79  for (i=beg; i<end; i++)
80  {
81  b[i] += iget(i, j) * x[j];
82  }
83  }
84  }
85  }
86 }
87 
88 template <typename T>
89 void
91  index_type beg, index_type end,
92  int spVec) const
93 {
94  // Compute At*x=b
95  ASSERT(x.nrows() == this->nrows_);
96  ASSERT(b.nrows() == this->ncols_);
97  if (beg == -1) beg = 0;
98  if (end == -1) end = this->ncols_;
99  index_type i, j;
100  if (!spVec)
101  {
102  for (i=beg; i<end; i++)
103  {
104  double sum = 0.0;
105  for (j=0; j<this->nrows_; j++)
106  {
107  sum += iget(j, i) * x[j];
108  }
109  b[i] = sum;
110  }
111  }
112  else
113  {
114  for (i=beg; i<end; i++) b[i] = 0.0;
115  for (j=0; j<this->nrows_; j++)
116  {
117  if (x[j])
118  {
119  for (i=beg; i<end; i++)
120  {
121  b[i] += iget(j, i) * x[j];
122  }
123  }
124  }
125  }
126 }
127 
128 } // End namespace SCIRun
129 
130 #endif
#define ASSERTEQ(c1, c2)
Definition: Assert.h:98
#define ASSERT(condition)
Definition: Assert.h:110
Definition: ColumnMatrix.h:55
long long index_type
Definition: Types.h:39
virtual void mult(const ColumnMatrix &x, ColumnMatrix &b, index_type beg=-1, index_type end=-1, int spVec=0) const
Definition: DenseColMajMatrixMultiplication.h:50
virtual void mult_transpose(const ColumnMatrix &x, ColumnMatrix &b, index_type beg=-1, index_type end=-1, int spVec=0) const
Definition: DenseColMajMatrixMultiplication.h:90
size_type nrows() const
Definition: Matrix.h:132