Mercurial > octave-nkf
comparison src/DLD-FUNCTIONS/kron.cc @ 10154:40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 20 Jan 2010 17:33:41 -0500 |
parents | 923c7cb7f13f |
children | 12884915a8e4 |
comparison
equal
deleted
inserted
replaced
10153:2c28f9d0360f | 10154:40dfc0c99116 |
---|---|
58 octave_idx_type Ac, Ar, Cc, Cr; | 58 octave_idx_type Ac, Ar, Cc, Cr; |
59 | 59 |
60 for (Ac = Cc = 0; Ac < A.columns (); Ac++, Cc += B.columns ()) | 60 for (Ac = Cc = 0; Ac < A.columns (); Ac++, Cc += B.columns ()) |
61 for (Ar = Cr = 0; Ar < A.rows (); Ar++, Cr += B.rows ()) | 61 for (Ar = Cr = 0; Ar < A.rows (); Ar++, Cr += B.rows ()) |
62 { | 62 { |
63 const T v = A (Ar, Ac); | 63 const T v = A (Ar, Ac); |
64 for (octave_idx_type Bc = 0; Bc < B.columns (); Bc++) | 64 for (octave_idx_type Bc = 0; Bc < B.columns (); Bc++) |
65 for (octave_idx_type Br = 0; Br < B.rows (); Br++) | 65 for (octave_idx_type Br = 0; Br < B.rows (); Br++) |
66 { | 66 { |
67 OCTAVE_QUIT; | 67 OCTAVE_QUIT; |
68 C.xelem (Cr+Br, Cc+Bc) = v * B.elem (Br, Bc); | 68 C.xelem (Cr+Br, Cc+Bc) = v * B.elem (Br, Bc); |
69 } | 69 } |
70 } | 70 } |
71 } | 71 } |
72 | 72 |
73 template void | 73 template void |
74 kron (const Array2<double>&, const Array2<double>&, Array2<double>&); | 74 kron (const Array2<double>&, const Array2<double>&, Array2<double>&); |
95 void | 95 void |
96 kron (const Sparse<T>& A, const Sparse<T>& B, Sparse<T>& C) | 96 kron (const Sparse<T>& A, const Sparse<T>& B, Sparse<T>& C) |
97 { | 97 { |
98 octave_idx_type idx = 0; | 98 octave_idx_type idx = 0; |
99 C = Sparse<T> (A.rows () * B.rows (), A.columns () * B.columns (), | 99 C = Sparse<T> (A.rows () * B.rows (), A.columns () * B.columns (), |
100 A.nzmax () * B.nzmax ()); | 100 A.nzmax () * B.nzmax ()); |
101 | 101 |
102 C.cidx (0) = 0; | 102 C.cidx (0) = 0; |
103 | 103 |
104 for (octave_idx_type Aj = 0; Aj < A.columns (); Aj++) | 104 for (octave_idx_type Aj = 0; Aj < A.columns (); Aj++) |
105 for (octave_idx_type Bj = 0; Bj < B.columns (); Bj++) | 105 for (octave_idx_type Bj = 0; Bj < B.columns (); Bj++) |
106 { | 106 { |
107 for (octave_idx_type Ai = A.cidx (Aj); Ai < A.cidx (Aj+1); Ai++) | 107 for (octave_idx_type Ai = A.cidx (Aj); Ai < A.cidx (Aj+1); Ai++) |
108 { | 108 { |
109 octave_idx_type Ci = A.ridx(Ai) * B.rows (); | 109 octave_idx_type Ci = A.ridx(Ai) * B.rows (); |
110 const T v = A.data (Ai); | 110 const T v = A.data (Ai); |
111 | 111 |
112 for (octave_idx_type Bi = B.cidx (Bj); Bi < B.cidx (Bj+1); Bi++) | 112 for (octave_idx_type Bi = B.cidx (Bj); Bi < B.cidx (Bj+1); Bi++) |
113 { | 113 { |
114 OCTAVE_QUIT; | 114 OCTAVE_QUIT; |
115 C.data (idx) = v * B.data (Bi); | 115 C.data (idx) = v * B.data (Bi); |
116 C.ridx (idx++) = Ci + B.ridx (Bi); | 116 C.ridx (idx++) = Ci + B.ridx (Bi); |
117 } | 117 } |
118 } | 118 } |
119 C.cidx (Aj * B.columns () + Bj + 1) = idx; | 119 C.cidx (Aj * B.columns () + Bj + 1) = idx; |
120 } | 120 } |
121 } | 121 } |
122 | 122 |
123 template void | 123 template void |
124 kron (const Sparse<double>&, const Sparse<double>&, Sparse<double>&); | 124 kron (const Sparse<double>&, const Sparse<double>&, Sparse<double>&); |
156 print_usage (); | 156 print_usage (); |
157 } | 157 } |
158 else if (args(0).is_sparse_type () || args(1).is_sparse_type ()) | 158 else if (args(0).is_sparse_type () || args(1).is_sparse_type ()) |
159 { | 159 { |
160 if (args(0).is_complex_type () || args(1).is_complex_type ()) | 160 if (args(0).is_complex_type () || args(1).is_complex_type ()) |
161 { | 161 { |
162 SparseComplexMatrix a (args(0).sparse_complex_matrix_value()); | 162 SparseComplexMatrix a (args(0).sparse_complex_matrix_value()); |
163 SparseComplexMatrix b (args(1).sparse_complex_matrix_value()); | 163 SparseComplexMatrix b (args(1).sparse_complex_matrix_value()); |
164 | 164 |
165 if (! error_state) | 165 if (! error_state) |
166 { | 166 { |
167 SparseComplexMatrix c; | 167 SparseComplexMatrix c; |
168 kron (a, b, c); | 168 kron (a, b, c); |
169 retval(0) = c; | 169 retval(0) = c; |
170 } | 170 } |
171 } | 171 } |
172 else | 172 else |
173 { | 173 { |
174 SparseMatrix a (args(0).sparse_matrix_value ()); | 174 SparseMatrix a (args(0).sparse_matrix_value ()); |
175 SparseMatrix b (args(1).sparse_matrix_value ()); | 175 SparseMatrix b (args(1).sparse_matrix_value ()); |
176 | 176 |
177 if (! error_state) | 177 if (! error_state) |
178 { | 178 { |
179 SparseMatrix c; | 179 SparseMatrix c; |
180 kron (a, b, c); | 180 kron (a, b, c); |
181 retval (0) = c; | 181 retval (0) = c; |
182 } | 182 } |
183 } | 183 } |
184 } | 184 } |
185 else | 185 else |
186 { | 186 { |
187 if (args(0).is_single_type () || args(1).is_single_type ()) | 187 if (args(0).is_single_type () || args(1).is_single_type ()) |
188 { | 188 { |
189 if (args(0).is_complex_type () || args(1).is_complex_type ()) | 189 if (args(0).is_complex_type () || args(1).is_complex_type ()) |
190 { | 190 { |
191 FloatComplexMatrix a (args(0).float_complex_matrix_value()); | 191 FloatComplexMatrix a (args(0).float_complex_matrix_value()); |
192 FloatComplexMatrix b (args(1).float_complex_matrix_value()); | 192 FloatComplexMatrix b (args(1).float_complex_matrix_value()); |
193 | 193 |
194 if (! error_state) | 194 if (! error_state) |
195 { | 195 { |
196 FloatComplexMatrix c; | 196 FloatComplexMatrix c; |
197 kron (a, b, c); | 197 kron (a, b, c); |
198 retval(0) = c; | 198 retval(0) = c; |
199 } | 199 } |
200 } | 200 } |
201 else | 201 else |
202 { | 202 { |
203 FloatMatrix a (args(0).float_matrix_value ()); | 203 FloatMatrix a (args(0).float_matrix_value ()); |
204 FloatMatrix b (args(1).float_matrix_value ()); | 204 FloatMatrix b (args(1).float_matrix_value ()); |
205 | 205 |
206 if (! error_state) | 206 if (! error_state) |
207 { | 207 { |
208 FloatMatrix c; | 208 FloatMatrix c; |
209 kron (a, b, c); | 209 kron (a, b, c); |
210 retval (0) = c; | 210 retval (0) = c; |
211 } | 211 } |
212 } | 212 } |
213 } | 213 } |
214 else | 214 else |
215 { | 215 { |
216 if (args(0).is_complex_type () || args(1).is_complex_type ()) | 216 if (args(0).is_complex_type () || args(1).is_complex_type ()) |
217 { | 217 { |
218 ComplexMatrix a (args(0).complex_matrix_value()); | 218 ComplexMatrix a (args(0).complex_matrix_value()); |
219 ComplexMatrix b (args(1).complex_matrix_value()); | 219 ComplexMatrix b (args(1).complex_matrix_value()); |
220 | 220 |
221 if (! error_state) | 221 if (! error_state) |
222 { | 222 { |
223 ComplexMatrix c; | 223 ComplexMatrix c; |
224 kron (a, b, c); | 224 kron (a, b, c); |
225 retval(0) = c; | 225 retval(0) = c; |
226 } | 226 } |
227 } | 227 } |
228 else | 228 else |
229 { | 229 { |
230 Matrix a (args(0).matrix_value ()); | 230 Matrix a (args(0).matrix_value ()); |
231 Matrix b (args(1).matrix_value ()); | 231 Matrix b (args(1).matrix_value ()); |
232 | 232 |
233 if (! error_state) | 233 if (! error_state) |
234 { | 234 { |
235 Matrix c; | 235 Matrix c; |
236 kron (a, b, c); | 236 kron (a, b, c); |
237 retval (0) = c; | 237 retval (0) = c; |
238 } | 238 } |
239 } | 239 } |
240 } | 240 } |
241 } | 241 } |
242 | 242 |
243 return retval; | 243 return retval; |
244 } | 244 } |