1 |
|
---|
2 | Covariant type conformance is used in member functions. This is
|
---|
3 | indicated with the "current" type which is the type of the
|
---|
4 | overriding class. Note that current might not be exactly the same
|
---|
5 | type. It might be a implementation of a diagonal matrix corresponding
|
---|
6 | to current, for example.
|
---|
7 |
|
---|
8 | Matrix multiplication is a bit of a mess because of the way the different
|
---|
9 | types of matrices get involved. Say G=general, S=symmetric, and D=diagonal,
|
---|
10 | then we get the following possible mxm accumulation routines: G+=G*G, G+=S*S,
|
---|
11 | D+=D*D, G+=D*D, G+=G*S, G+=S*G, G+=G*D, G+=D*G, G+=S*D, G+=D*S, and S+=Sa*Sb
|
---|
12 | if [Sa,Sb] = 0 (I use accumulation routines so storage isn't allocated
|
---|
13 | unnecessarily where it isn't needed). Not all of these will be implemented
|
---|
14 | in a given matrix implementation, so, unfortunately, there can be runtime
|
---|
15 | type errors.
|
---|
16 |
|
---|
17 | The various accumulation routines are G+=G, G+=S, G+=D, S+=S, S+=D, and D+=D.
|
---|
18 |
|
---|
19 | Generic operations on matrices are done with the following:
|
---|
20 | A->element_op(op)
|
---|
21 | For all elements in A do op.
|
---|
22 |
|
---|
23 | A->matrix_op(B,op)
|
---|
24 | For all elements in A
|
---|
25 | For all elements in B
|
---|
26 | do op.
|
---|
27 |
|
---|
28 | A->matrix_pair_op(B,C,D,op)
|
---|
29 | For all elements in (A,B)
|
---|
30 | For all elements in (C,D)
|
---|
31 | do op.
|
---|
32 | (A and B must have exactly the same dimensions as well as C and D.)
|
---|
33 |
|
---|
34 | // Abstract class
|
---|
35 | SCDimension
|
---|
36 | Specifies storage information for a dimension. Each matrix implementation
|
---|
37 | has a corresponding SCDimension implementation.
|
---|
38 |
|
---|
39 | // abstract
|
---|
40 | virtual int dim()
|
---|
41 | The integer dimension is returned.
|
---|
42 | virtual corresponding_matrix_type create_matrix(SCDimension a)
|
---|
43 | A matrix is created with this as the rowdim and a as the coldim.
|
---|
44 | virtual corresponding_matrix_type create_symmmatrix()
|
---|
45 | A symmetric matrix is created with this as rowdim and coldim.
|
---|
46 | virtual corresponding_matrix_type create_diagmatrix()
|
---|
47 | A diagonal matrix is created with this as rowdim and coldim.
|
---|
48 | virtual corresponding_vector_type create_vector()
|
---|
49 | A diagonal matrix is created with this as dim.
|
---|
50 |
|
---|
51 | // Abstract class
|
---|
52 | SCMatrix
|
---|
53 |
|
---|
54 | // concrete:
|
---|
55 | CTOR()
|
---|
56 | current i()
|
---|
57 | Returns the inverse of this.
|
---|
58 | current t()
|
---|
59 | Returns the transpose of this.
|
---|
60 | current operator*(current a)
|
---|
61 | Returns this * a.
|
---|
62 | current operator+(current a)
|
---|
63 | Returns this + a.
|
---|
64 | current operator-(current a)
|
---|
65 | Returns this - a.
|
---|
66 | int nrow()
|
---|
67 | The number of rows in the matrix.
|
---|
68 | int ncol()
|
---|
69 | The number of columns in the matrix.
|
---|
70 | current clone()
|
---|
71 | Returns an identical matrix with uninitialized elements.
|
---|
72 | void scale(double a)
|
---|
73 | Scales all of the elements in this by a.
|
---|
74 | current assign(double a)
|
---|
75 | Assigns all of the elements to a;
|
---|
76 | void copy(current a)
|
---|
77 | Copy a to this. The dimensions must be the same. This is not
|
---|
78 | operator=(current), because operator=(current) has a different
|
---|
79 | meaning in the reference counting classes.
|
---|
80 | SCdouble operator()(int,int)
|
---|
81 | This lets users do things like a(1,1) = x; x = a(1,1);. Note that
|
---|
82 | printf("%f",(something of type SCdouble)) won't work, because
|
---|
83 | SCdouble can't be passed though '...'.
|
---|
84 |
|
---|
85 | // abstract:
|
---|
86 | SCDimension rowdim()
|
---|
87 | The row dimension of the matrix.
|
---|
88 | SCDimension coldim()
|
---|
89 | The column dimension of the matrix.
|
---|
90 | double get_element(int,int)
|
---|
91 | Get the value of a matrix element.
|
---|
92 | void set_element(int,int,double)
|
---|
93 | Set the value of a matrix element.
|
---|
94 | current multiply_and_accumulate(current a, current b)
|
---|
95 | Performs the operation this += a * b. Returns this.
|
---|
96 | void accumulate(current a)
|
---|
97 | Performs this += a.
|
---|
98 | current transpose_this()
|
---|
99 | Transposes and returns this.
|
---|
100 | current invert_this()
|
---|
101 | Inverts and returns this.
|
---|
102 | void element_op(RefSCElementOp)
|
---|
103 | Performs some operation on each element of the matrix.
|
---|
104 | The member functions for all SCMatrixElementOp's must be available
|
---|
105 | on the node programs in a parallel environment.
|
---|
106 | void resize(SCDimension,SCDimension)
|
---|
107 | Resize this.
|
---|
108 |
|
---|
109 | // These are abstract classes which inherits virtually from SCMatrix.
|
---|
110 | // Specializations of SCMatrix which are diagonal or symmetric should
|
---|
111 | // inherit form the appropiate class. The inheritance hierarchy could
|
---|
112 | // take on one of the following forms:
|
---|
113 | // Single inheritance:
|
---|
114 | // SCMatrix
|
---|
115 | // | \
|
---|
116 | // | SymmSCMatrix
|
---|
117 | // SpecSCMatrix | \
|
---|
118 | // | DiagSCMatrix
|
---|
119 | // SpecSymmSCMatrix |
|
---|
120 | // |
|
---|
121 | // SpecDiagSCMatrix
|
---|
122 | // Multiple inheritance:
|
---|
123 | // SCMatrix
|
---|
124 | // | \
|
---|
125 | // | SymmSCMatrix
|
---|
126 | // SpecSCMatrix | \
|
---|
127 | // | | DiagSCMatrix
|
---|
128 | // SpecSymmSCMatrix |
|
---|
129 | // | |
|
---|
130 | // SpecDiagSCMatrix
|
---|
131 | //
|
---|
132 |
|
---|
133 | // Abstract class
|
---|
134 | SymmSCMatrix: virtual SCMatrix
|
---|
135 | // concrete
|
---|
136 | CTOR()
|
---|
137 | implementations of rowdim and coldim
|
---|
138 | implement rowcol_clone(DimSpec rowdim,current colmatrix,DimSpec coldim)
|
---|
139 | override t(), i(), etc
|
---|
140 |
|
---|
141 | // abstract
|
---|
142 | int ndim()
|
---|
143 | returns the integer dimension
|
---|
144 | SCDimension dim()
|
---|
145 | returns the dimension
|
---|
146 |
|
---|
147 | // Abstract class
|
---|
148 | DiagSCMatrix: virtual SymmSCMatrix
|
---|
149 |
|
---|
150 | // Concrete class
|
---|
151 | LocalSCMatrix: SCMatrix
|
---|
152 | // concrete:
|
---|
153 | CTOR(int,int)
|
---|
154 | implementations of all of SCMatrix's abstract functions
|
---|
155 |
|
---|
156 | // Concrete class
|
---|
157 | LocalSymmSCMatrix: SymmSCMatrix
|
---|
158 | // concrete:
|
---|
159 | CTOR(int,int)
|
---|
160 | implementations of all of SCMatrix's abstract functions
|
---|
161 |
|
---|
162 | // Concrete class
|
---|
163 | LocalDiagSCMatrix: DiagSCMatrix
|
---|
164 | // concrete:
|
---|
165 | CTOR(int,int)
|
---|
166 | implementations of all of SCMatrix's abstract functions
|
---|
167 |
|
---|
168 | // Concrete class
|
---|
169 | DistSCMatrix: SCMatrix
|
---|
170 | // concrete:
|
---|
171 | CTOR(DistMap,DistMap)
|
---|
172 | implementations of all of SCMatrix's abstract functions
|
---|
173 |
|
---|
174 | // Concrete class
|
---|
175 | DistSymmSCMatrix: SymmSCMatrix
|
---|
176 | // concrete:
|
---|
177 | CTOR(DistMap,DistMap)
|
---|
178 | implementations of all of SCMatrix's abstract functions
|
---|
179 |
|
---|
180 | // Concrete class
|
---|
181 | DistDiagSCMatrix: DiagSCMatrix
|
---|
182 | // concrete:
|
---|
183 | CTOR(DistMap,DistMap)
|
---|
184 | implementations of all of SCMatrix's abstract functions
|
---|
185 |
|
---|