1 | /* |
---|
2 | * $Id: vector.cc,v 1.7 2005/10/06 23:28:03 julianc Exp $ |
---|
3 | * |
---|
4 | * Copyright (C) 1997 Todd Veldhuizen <tveldhui@oonumerics.org> |
---|
5 | * All rights reserved. Please see <blitz/blitz.h> for terms and |
---|
6 | * conditions of use. |
---|
7 | * |
---|
8 | */ |
---|
9 | |
---|
10 | #ifndef BZ_VECTOR_CC |
---|
11 | #define BZ_VECTOR_CC |
---|
12 | |
---|
13 | #include <blitz/vector.h> |
---|
14 | #include <blitz/update.h> |
---|
15 | |
---|
16 | BZ_NAMESPACE(blitz) |
---|
17 | |
---|
18 | template<typename P_numtype> |
---|
19 | Vector<P_numtype> Vector<P_numtype>::copy() const |
---|
20 | { |
---|
21 | Vector<P_numtype> newCopy(length_); |
---|
22 | |
---|
23 | if (stride_ == 1) |
---|
24 | { |
---|
25 | memcpy(newCopy.data(), data(), length_ * sizeof(P_numtype)); |
---|
26 | } |
---|
27 | else { |
---|
28 | for (int i=0; i < length_; ++i) |
---|
29 | { |
---|
30 | // Can assume that newCopy has unit stride, and hence use |
---|
31 | // the operator(), which assumes unit stride. Since this |
---|
32 | // vector doesn't have unit stride, use []. |
---|
33 | newCopy(i) = (*this)[i]; |
---|
34 | } |
---|
35 | } |
---|
36 | |
---|
37 | return newCopy; |
---|
38 | } |
---|
39 | |
---|
40 | template<typename P_numtype> |
---|
41 | void Vector<P_numtype>::makeUnique() |
---|
42 | { |
---|
43 | if ((stride_ != 1) || (this->numReferences() > 1)) |
---|
44 | { |
---|
45 | Vector<P_numtype> tmp = copy(); |
---|
46 | reference(tmp); |
---|
47 | } |
---|
48 | } |
---|
49 | |
---|
50 | template<typename P_numtype> |
---|
51 | void Vector<P_numtype>::reference(Vector<P_numtype>& x) |
---|
52 | { |
---|
53 | MemoryBlockReference<P_numtype>::changeBlock(x); |
---|
54 | length_ = x.length_; |
---|
55 | stride_ = x.stride_; |
---|
56 | } |
---|
57 | |
---|
58 | template<typename P_numtype> |
---|
59 | void Vector<P_numtype>::resize(int length) |
---|
60 | { |
---|
61 | if (length != length_) |
---|
62 | { |
---|
63 | MemoryBlockReference<P_numtype>::newBlock(length); |
---|
64 | length_ = length; |
---|
65 | stride_ = 1; |
---|
66 | } |
---|
67 | } |
---|
68 | |
---|
69 | template<typename P_numtype> |
---|
70 | void Vector<P_numtype>::resizeAndPreserve(int newLength) |
---|
71 | { |
---|
72 | Vector<P_numtype> newVector(newLength); |
---|
73 | |
---|
74 | if (newLength > length_) |
---|
75 | newVector(Range(0,length_-1)) = (*this); |
---|
76 | else |
---|
77 | newVector(Range(0,newLength-1)) = (*this); |
---|
78 | |
---|
79 | reference(newVector); |
---|
80 | } |
---|
81 | |
---|
82 | /***************************************************************************** |
---|
83 | * Assignment operators with vector expression operand |
---|
84 | */ |
---|
85 | |
---|
86 | template<typename P_numtype> template<typename P_expr, typename P_updater> |
---|
87 | inline |
---|
88 | void Vector<P_numtype>::_bz_assign(P_expr expr, P_updater) |
---|
89 | { |
---|
90 | BZPRECONDITION(expr.length(length_) == length_); |
---|
91 | |
---|
92 | // If all vectors in the expression, plus the vector to which the |
---|
93 | // result is being assigned have unit stride, then avoid stride |
---|
94 | // calculations. |
---|
95 | if ((stride_ == 1) && (expr._bz_hasFastAccess())) |
---|
96 | { |
---|
97 | #ifndef BZ_PARTIAL_LOOP_UNROLL |
---|
98 | for (int i=0; i < length_; ++i) |
---|
99 | P_updater::update(data_[i], expr._bz_fastAccess(i)); |
---|
100 | #else |
---|
101 | // Unwind the inner loop, four elements at a time. |
---|
102 | int leftover = length_ & 0x03; |
---|
103 | |
---|
104 | int i=0; |
---|
105 | for (; i < leftover; ++i) |
---|
106 | P_updater::update(data_[i], expr._bz_fastAccess(i)); |
---|
107 | |
---|
108 | for (; i < length_; i += 4) |
---|
109 | { |
---|
110 | // Common subexpression elimination: avoid doing i+1, i+2, i+3 |
---|
111 | // multiple times (compilers *won't* do this cse automatically) |
---|
112 | int t1 = i+1; |
---|
113 | int t2 = i+2; |
---|
114 | int t3 = i+3; |
---|
115 | |
---|
116 | _bz_typename P_expr::T_numtype tmp1, tmp2, tmp3, tmp4; |
---|
117 | |
---|
118 | // Reading all the results first avoids aliasing |
---|
119 | // ambiguities, and provides more flexibility in |
---|
120 | // register allocation & instruction scheduling |
---|
121 | tmp1 = expr._bz_fastAccess(i); |
---|
122 | tmp2 = expr._bz_fastAccess(BZ_NO_PROPAGATE(t1)); |
---|
123 | tmp3 = expr._bz_fastAccess(BZ_NO_PROPAGATE(t2)); |
---|
124 | tmp4 = expr._bz_fastAccess(BZ_NO_PROPAGATE(t3)); |
---|
125 | |
---|
126 | P_updater::update(data_[i], BZ_NO_PROPAGATE(tmp1)); |
---|
127 | P_updater::update(data_[t1], tmp2); |
---|
128 | P_updater::update(data_[t2], tmp3); |
---|
129 | P_updater::update(data_[t3], tmp4); |
---|
130 | } |
---|
131 | #endif |
---|
132 | } |
---|
133 | else { |
---|
134 | // Not all unit strides -- have to access all the vector elements |
---|
135 | // as data_[i*stride_], which is slower. |
---|
136 | for (int i=0; i < length_; ++i) |
---|
137 | P_updater::update((*this)[i], expr[i]); |
---|
138 | } |
---|
139 | } |
---|
140 | |
---|
141 | template<typename P_numtype> template<typename P_expr> |
---|
142 | inline Vector<P_numtype>& Vector<P_numtype>::operator=(_bz_VecExpr<P_expr> expr) |
---|
143 | { |
---|
144 | BZPRECONDITION(expr.length(length_) == length_); |
---|
145 | |
---|
146 | // If all vectors in the expression, plus the vector to which the |
---|
147 | // result is being assigned have unit stride, then avoid stride |
---|
148 | // calculations. |
---|
149 | if ((stride_ == 1) && (expr._bz_hasFastAccess())) |
---|
150 | { |
---|
151 | #ifndef BZ_PARTIAL_LOOP_UNROLL |
---|
152 | for (int i=0; i < length_; ++i) |
---|
153 | data_[i] = (P_numtype)expr._bz_fastAccess(i); |
---|
154 | #else |
---|
155 | // Unwind the inner loop, four elements at a time. |
---|
156 | int leftover = length_ & 3; |
---|
157 | |
---|
158 | int i=0; |
---|
159 | for (; i < leftover; ++i) |
---|
160 | data_[i] = (P_numtype)expr._bz_fastAccess(i); |
---|
161 | |
---|
162 | for (; i < length_; i += 4) |
---|
163 | { |
---|
164 | // Common subexpression elimination: avoid doing i+1, i+2, i+3 |
---|
165 | // multiple times (compilers *won't* do this cse automatically) |
---|
166 | int t1 = i+1; |
---|
167 | int t2 = i+2; |
---|
168 | int t3 = i+3; |
---|
169 | |
---|
170 | _bz_typename P_expr::T_numtype tmp1, tmp2, tmp3, tmp4; |
---|
171 | |
---|
172 | // Reading all the results first avoids aliasing |
---|
173 | // ambiguities, and provides more flexibility in |
---|
174 | // register allocation & instruction scheduling |
---|
175 | tmp1 = expr._bz_fastAccess(i); |
---|
176 | tmp2 = expr._bz_fastAccess(BZ_NO_PROPAGATE(t1)); |
---|
177 | tmp3 = expr._bz_fastAccess(BZ_NO_PROPAGATE(t2)); |
---|
178 | tmp4 = expr._bz_fastAccess(BZ_NO_PROPAGATE(t3)); |
---|
179 | |
---|
180 | data_[i] = (P_numtype)BZ_NO_PROPAGATE(tmp1); |
---|
181 | data_[t1] = (P_numtype)tmp2; |
---|
182 | data_[t2] = (P_numtype)tmp3; |
---|
183 | data_[t3] = (P_numtype)tmp4; |
---|
184 | } |
---|
185 | #endif |
---|
186 | } |
---|
187 | else { |
---|
188 | // Not all unit strides -- have to access all the vector elements |
---|
189 | // as data_[i*stride_], which is slower. |
---|
190 | for (int i=0; i < length_; ++i) |
---|
191 | (*this)[i] = (P_numtype)expr[i]; |
---|
192 | } |
---|
193 | return *this; |
---|
194 | } |
---|
195 | |
---|
196 | #ifdef BZ_PARTIAL_LOOP_UNROLL |
---|
197 | |
---|
198 | #define BZ_VECTOR_ASSIGN(op) \ |
---|
199 | template<typename P_numtype> template<typename P_expr> \ |
---|
200 | inline Vector<P_numtype>& Vector<P_numtype>:: \ |
---|
201 | operator op (_bz_VecExpr<P_expr> expr) \ |
---|
202 | { \ |
---|
203 | BZPRECONDITION(expr.length(length_) == length_); \ |
---|
204 | if ((stride_ == 1) && (expr._bz_hasFastAccess())) \ |
---|
205 | { \ |
---|
206 | int leftover = length_ & 0x03; \ |
---|
207 | \ |
---|
208 | int i=0; \ |
---|
209 | for (; i < leftover; ++i) \ |
---|
210 | data_[i] op expr._bz_fastAccess(i); \ |
---|
211 | \ |
---|
212 | for (; i < length_; i += 4) \ |
---|
213 | { \ |
---|
214 | int t1 = i+1; \ |
---|
215 | int t2 = i+2; \ |
---|
216 | int t3 = i+3; \ |
---|
217 | \ |
---|
218 | _bz_typename P_expr::T_numtype tmp1, tmp2, tmp3, tmp4; \ |
---|
219 | \ |
---|
220 | tmp1 = expr._bz_fastAccess(i); \ |
---|
221 | tmp2 = expr._bz_fastAccess(t1); \ |
---|
222 | tmp3 = expr._bz_fastAccess(t2); \ |
---|
223 | tmp4 = expr._bz_fastAccess(t3); \ |
---|
224 | \ |
---|
225 | data_[i] op tmp1; \ |
---|
226 | data_[t1] op tmp2; \ |
---|
227 | data_[t2] op tmp3; \ |
---|
228 | data_[t3] op tmp4; \ |
---|
229 | } \ |
---|
230 | } \ |
---|
231 | else { \ |
---|
232 | for (int i=0; i < length_; ++i) \ |
---|
233 | (*this)[i] op expr[i]; \ |
---|
234 | } \ |
---|
235 | return *this; \ |
---|
236 | } |
---|
237 | |
---|
238 | #else // not BZ_PARTIAL_LOOP_UNROLL |
---|
239 | |
---|
240 | #ifdef BZ_ALTERNATE_FORWARD_BACKWARD_TRAVERSALS |
---|
241 | |
---|
242 | /* |
---|
243 | * NEEDS_WORK: need to incorporate BZ_NO_PROPAGATE here. This |
---|
244 | * will require doing away with the macro BZ_VECTOR_ASSIGN, and |
---|
245 | * adopting an approach similar to that used in arrayeval.cc. |
---|
246 | */ |
---|
247 | |
---|
248 | #define BZ_VECTOR_ASSIGN(op) \ |
---|
249 | template<typename P_numtype> template<typename P_expr> \ |
---|
250 | inline Vector<P_numtype>& Vector<P_numtype>:: \ |
---|
251 | operator op (_bz_VecExpr<P_expr> expr) \ |
---|
252 | { \ |
---|
253 | BZPRECONDITION(expr.length(length_) == length_); \ |
---|
254 | static int traversalOrder = 0; \ |
---|
255 | if ((stride_ == 1) && (expr._bz_hasFastAccess())) \ |
---|
256 | { \ |
---|
257 | if (traversalOrder & 0x01) \ |
---|
258 | for (int i=length_-1; i >= 0; --i) \ |
---|
259 | data_[i] op expr._bz_fastAccess(i); \ |
---|
260 | else \ |
---|
261 | for (int i=0; i < length_; ++i) \ |
---|
262 | data_[i] op expr._bz_fastAccess(i); \ |
---|
263 | } \ |
---|
264 | else { \ |
---|
265 | for (int i=0; i < length_; ++i) \ |
---|
266 | (*this)[i] op expr[i]; \ |
---|
267 | } \ |
---|
268 | traversalOrder ^= 0x01; \ |
---|
269 | return *this; \ |
---|
270 | } |
---|
271 | |
---|
272 | #else // not BZ_ALTERNATE_FORWARD_BACKWARD_TRAVERSALS |
---|
273 | |
---|
274 | #define BZ_VECTOR_ASSIGN(op) \ |
---|
275 | template<typename P_numtype> template<typename P_expr> \ |
---|
276 | inline Vector<P_numtype>& Vector<P_numtype>:: \ |
---|
277 | operator op (_bz_VecExpr<P_expr> expr) \ |
---|
278 | { \ |
---|
279 | BZPRECONDITION(expr.length(length_) == length_); \ |
---|
280 | if ((stride_ == 1) && (expr._bz_hasFastAccess())) \ |
---|
281 | { \ |
---|
282 | for (int i=0; i < length_; ++i) \ |
---|
283 | data_[i] op expr._bz_fastAccess(i); \ |
---|
284 | } \ |
---|
285 | else { \ |
---|
286 | for (int i=0; i < length_; ++i) \ |
---|
287 | (*this)[i] op expr[i]; \ |
---|
288 | } \ |
---|
289 | return *this; \ |
---|
290 | } |
---|
291 | #endif // BZ_ALTERNATE_FORWARD_BACKWARD_TRAVERSALS |
---|
292 | #endif // BZ_PARTIAL_LOOP_UNROLL |
---|
293 | |
---|
294 | BZ_VECTOR_ASSIGN(+=) |
---|
295 | BZ_VECTOR_ASSIGN(-=) |
---|
296 | BZ_VECTOR_ASSIGN(*=) |
---|
297 | BZ_VECTOR_ASSIGN(/=) |
---|
298 | BZ_VECTOR_ASSIGN(%=) |
---|
299 | BZ_VECTOR_ASSIGN(^=) |
---|
300 | BZ_VECTOR_ASSIGN(&=) |
---|
301 | BZ_VECTOR_ASSIGN(|=) |
---|
302 | BZ_VECTOR_ASSIGN(>>=) |
---|
303 | BZ_VECTOR_ASSIGN(<<=) |
---|
304 | |
---|
305 | #if NOT_DEFINED |
---|
306 | |
---|
307 | template<typename P_numtype> template<typename P_expr> |
---|
308 | inline Vector<P_numtype>& Vector<P_numtype>::operator+=(_bz_VecExpr<P_expr> expr) |
---|
309 | { |
---|
310 | _bz_assign(expr, _bz_plus_update<P_numtype, |
---|
311 | _bz_typename P_expr::T_numtype>()); |
---|
312 | return *this; |
---|
313 | } |
---|
314 | |
---|
315 | template<typename P_numtype> template<typename P_expr> |
---|
316 | inline Vector<P_numtype>& Vector<P_numtype>::operator-=(_bz_VecExpr<P_expr> expr) |
---|
317 | { |
---|
318 | _bz_assign(expr, _bz_minus_update<P_numtype, |
---|
319 | _bz_typename P_expr::T_numtype>()); |
---|
320 | return *this; |
---|
321 | } |
---|
322 | |
---|
323 | template<typename P_numtype> template<typename P_expr> |
---|
324 | inline Vector<P_numtype>& Vector<P_numtype>::operator*=(_bz_VecExpr<P_expr> expr) |
---|
325 | { |
---|
326 | _bz_assign(expr, _bz_multiply_update<P_numtype, |
---|
327 | _bz_typename P_expr::T_numtype>()); |
---|
328 | return *this; |
---|
329 | } |
---|
330 | |
---|
331 | template<typename P_numtype> template<typename P_expr> |
---|
332 | inline Vector<P_numtype>& Vector<P_numtype>::operator/=(_bz_VecExpr<P_expr> expr) |
---|
333 | { |
---|
334 | _bz_assign(expr, _bz_divide_update<P_numtype, |
---|
335 | _bz_typename P_expr::T_numtype>()); |
---|
336 | return *this; |
---|
337 | } |
---|
338 | |
---|
339 | template<typename P_numtype> template<typename P_expr> |
---|
340 | inline Vector<P_numtype>& Vector<P_numtype>::operator%=(_bz_VecExpr<P_expr> expr) |
---|
341 | { |
---|
342 | _bz_assign(expr, _bz_mod_update<P_numtype, |
---|
343 | _bz_typename P_expr::T_numtype>()); |
---|
344 | return *this; |
---|
345 | } |
---|
346 | |
---|
347 | template<typename P_numtype> template<typename P_expr> |
---|
348 | inline Vector<P_numtype>& Vector<P_numtype>::operator^=(_bz_VecExpr<P_expr> expr) |
---|
349 | { |
---|
350 | _bz_assign(expr, _bz_xor_update<P_numtype, |
---|
351 | _bz_typename P_expr::T_numtype>()); |
---|
352 | return *this; |
---|
353 | } |
---|
354 | |
---|
355 | template<typename P_numtype> template<typename P_expr> |
---|
356 | inline Vector<P_numtype>& Vector<P_numtype>::operator&=(_bz_VecExpr<P_expr> expr) |
---|
357 | { |
---|
358 | _bz_assign(expr, _bz_bitand_update<P_numtype, |
---|
359 | _bz_typename P_expr::T_numtype>()); |
---|
360 | return *this; |
---|
361 | } |
---|
362 | |
---|
363 | template<typename P_numtype> template<typename P_expr> |
---|
364 | inline Vector<P_numtype>& Vector<P_numtype>::operator|=(_bz_VecExpr<P_expr> expr) |
---|
365 | { |
---|
366 | _bz_assign(expr, _bz_bitor_update<P_numtype, |
---|
367 | _bz_typename P_expr::T_numtype>()); |
---|
368 | return *this; |
---|
369 | } |
---|
370 | |
---|
371 | template<typename P_numtype> template<typename P_expr> |
---|
372 | inline Vector<P_numtype>& Vector<P_numtype>::operator>>=(_bz_VecExpr<P_expr> expr) |
---|
373 | { |
---|
374 | _bz_assign(expr, _bz_shiftr_update<P_numtype, |
---|
375 | _bz_typename P_expr::T_numtype>()); |
---|
376 | return *this; |
---|
377 | } |
---|
378 | |
---|
379 | template<typename P_numtype> template<typename P_expr> |
---|
380 | inline Vector<P_numtype>& Vector<P_numtype>::operator<<=(_bz_VecExpr<P_expr> expr) |
---|
381 | { |
---|
382 | _bz_assign(expr, _bz_shiftl_update<P_numtype, |
---|
383 | _bz_typename P_expr::T_numtype>()); |
---|
384 | return *this; |
---|
385 | } |
---|
386 | #endif // NOT_DEFINED |
---|
387 | |
---|
388 | /***************************************************************************** |
---|
389 | * Assignment operators with scalar operand |
---|
390 | */ |
---|
391 | |
---|
392 | template<typename P_numtype> |
---|
393 | inline Vector<P_numtype>& Vector<P_numtype>::initialize(P_numtype x) |
---|
394 | { |
---|
395 | typedef _bz_VecExprConstant<P_numtype> T_expr; |
---|
396 | (*this) = _bz_VecExpr<T_expr>(T_expr(x)); |
---|
397 | return *this; |
---|
398 | } |
---|
399 | |
---|
400 | template<typename P_numtype> |
---|
401 | inline Vector<P_numtype>& Vector<P_numtype>::operator+=(P_numtype x) |
---|
402 | { |
---|
403 | typedef _bz_VecExprConstant<P_numtype> T_expr; |
---|
404 | (*this) += _bz_VecExpr<T_expr>(T_expr(x)); |
---|
405 | return *this; |
---|
406 | } |
---|
407 | |
---|
408 | template<typename P_numtype> |
---|
409 | inline Vector<P_numtype>& Vector<P_numtype>::operator-=(P_numtype x) |
---|
410 | { |
---|
411 | typedef _bz_VecExprConstant<P_numtype> T_expr; |
---|
412 | (*this) -= _bz_VecExpr<T_expr>(T_expr(x)); |
---|
413 | return *this; |
---|
414 | } |
---|
415 | |
---|
416 | template<typename P_numtype> |
---|
417 | inline Vector<P_numtype>& Vector<P_numtype>::operator*=(P_numtype x) |
---|
418 | { |
---|
419 | typedef _bz_VecExprConstant<P_numtype> T_expr; |
---|
420 | (*this) *= _bz_VecExpr<T_expr>(T_expr(x)); |
---|
421 | return *this; |
---|
422 | } |
---|
423 | |
---|
424 | template<typename P_numtype> |
---|
425 | inline Vector<P_numtype>& Vector<P_numtype>::operator/=(P_numtype x) |
---|
426 | { |
---|
427 | typedef _bz_VecExprConstant<P_numtype> T_expr; |
---|
428 | (*this) /= _bz_VecExpr<T_expr>(T_expr(x)); |
---|
429 | return *this; |
---|
430 | } |
---|
431 | |
---|
432 | template<typename P_numtype> |
---|
433 | inline Vector<P_numtype>& Vector<P_numtype>::operator%=(P_numtype x) |
---|
434 | { |
---|
435 | typedef _bz_VecExprConstant<P_numtype> T_expr; |
---|
436 | (*this) %= _bz_VecExpr<T_expr>(T_expr(x)); |
---|
437 | return *this; |
---|
438 | } |
---|
439 | |
---|
440 | template<typename P_numtype> |
---|
441 | inline Vector<P_numtype>& Vector<P_numtype>::operator^=(P_numtype x) |
---|
442 | { |
---|
443 | typedef _bz_VecExprConstant<P_numtype> T_expr; |
---|
444 | (*this) ^= _bz_VecExpr<T_expr>(T_expr(x)); |
---|
445 | return *this; |
---|
446 | } |
---|
447 | |
---|
448 | template<typename P_numtype> |
---|
449 | inline Vector<P_numtype>& Vector<P_numtype>::operator&=(P_numtype x) |
---|
450 | { |
---|
451 | typedef _bz_VecExprConstant<P_numtype> T_expr; |
---|
452 | (*this) &= _bz_VecExpr<T_expr>(T_expr(x)); |
---|
453 | return *this; |
---|
454 | } |
---|
455 | |
---|
456 | template<typename P_numtype> |
---|
457 | inline Vector<P_numtype>& Vector<P_numtype>::operator|=(P_numtype x) |
---|
458 | { |
---|
459 | typedef _bz_VecExprConstant<P_numtype> T_expr; |
---|
460 | (*this) |= _bz_VecExpr<T_expr>(T_expr(x)); |
---|
461 | return *this; |
---|
462 | } |
---|
463 | |
---|
464 | template<typename P_numtype> |
---|
465 | inline Vector<P_numtype>& Vector<P_numtype>::operator>>=(int x) |
---|
466 | { |
---|
467 | typedef _bz_VecExprConstant<int> T_expr; |
---|
468 | (*this) >>= _bz_VecExpr<T_expr>(T_expr(x)); |
---|
469 | return *this; |
---|
470 | } |
---|
471 | |
---|
472 | template<typename P_numtype> |
---|
473 | inline Vector<P_numtype>& Vector<P_numtype>::operator<<=(int x) |
---|
474 | { |
---|
475 | typedef _bz_VecExprConstant<P_numtype> T_expr; |
---|
476 | (*this) <<= _bz_VecExpr<T_expr>(T_expr(x)); |
---|
477 | return *this; |
---|
478 | } |
---|
479 | |
---|
480 | /***************************************************************************** |
---|
481 | * Assignment operators with vector operand |
---|
482 | */ |
---|
483 | |
---|
484 | // This version is for two vectors with the same template parameter. |
---|
485 | // Does not appear to be supported by the current C++ standard; or |
---|
486 | // is it? |
---|
487 | #if 0 |
---|
488 | template<typename P_numtype> template<> |
---|
489 | inline Vector<P_numtype>& |
---|
490 | Vector<P_numtype>::operator=(const Vector<P_numtype>& x) |
---|
491 | { |
---|
492 | // NEEDS_WORK: if unit strides, use memcpy or something similar. |
---|
493 | |
---|
494 | typedef VectorIterConst<P_numtype> T_expr; |
---|
495 | (*this) = _bz_VecExpr<T_expr>(T_expr(*this)); |
---|
496 | return *this; |
---|
497 | } |
---|
498 | #endif |
---|
499 | |
---|
500 | // This version is for two vectors with *different* template |
---|
501 | // parameters. |
---|
502 | template<typename P_numtype> template<typename P_numtype2> |
---|
503 | inline Vector<P_numtype>& |
---|
504 | Vector<P_numtype>::operator=(const Vector<P_numtype2>& x) |
---|
505 | { |
---|
506 | (*this) = _bz_VecExpr<VectorIterConst<P_numtype2> >(x.beginFast()); |
---|
507 | return *this; |
---|
508 | } |
---|
509 | |
---|
510 | template<typename P_numtype> template<typename P_numtype2> |
---|
511 | inline Vector<P_numtype>& |
---|
512 | Vector<P_numtype>::operator+=(const Vector<P_numtype2>& x) |
---|
513 | { |
---|
514 | (*this) += _bz_VecExpr<VectorIterConst<P_numtype2> >(x.beginFast()); |
---|
515 | return *this; |
---|
516 | } |
---|
517 | |
---|
518 | template<typename P_numtype> template<typename P_numtype2> |
---|
519 | inline Vector<P_numtype>& |
---|
520 | Vector<P_numtype>::operator-=(const Vector<P_numtype2>& x) |
---|
521 | { |
---|
522 | (*this) -= _bz_VecExpr<VectorIterConst<P_numtype2> >(x.beginFast()); |
---|
523 | return *this; |
---|
524 | } |
---|
525 | |
---|
526 | template<typename P_numtype> template<typename P_numtype2> |
---|
527 | inline Vector<P_numtype>& |
---|
528 | Vector<P_numtype>::operator*=(const Vector<P_numtype2>& x) |
---|
529 | { |
---|
530 | (*this) *= _bz_VecExpr<VectorIterConst<P_numtype2> >(x.beginFast()); |
---|
531 | return *this; |
---|
532 | } |
---|
533 | |
---|
534 | template<typename P_numtype> template<typename P_numtype2> |
---|
535 | inline Vector<P_numtype>& |
---|
536 | Vector<P_numtype>::operator/=(const Vector<P_numtype2>& x) |
---|
537 | { |
---|
538 | (*this) /= _bz_VecExpr<VectorIterConst<P_numtype2> >(x.beginFast()); |
---|
539 | return *this; |
---|
540 | } |
---|
541 | |
---|
542 | template<typename P_numtype> template<typename P_numtype2> |
---|
543 | inline Vector<P_numtype>& |
---|
544 | Vector<P_numtype>::operator%=(const Vector<P_numtype2>& x) |
---|
545 | { |
---|
546 | (*this) %= _bz_VecExpr<VectorIterConst<P_numtype2> >(x.beginFast()); |
---|
547 | return *this; |
---|
548 | } |
---|
549 | |
---|
550 | template<typename P_numtype> template<typename P_numtype2> |
---|
551 | inline Vector<P_numtype>& |
---|
552 | Vector<P_numtype>::operator^=(const Vector<P_numtype2>& x) |
---|
553 | { |
---|
554 | (*this) ^= _bz_VecExpr<VectorIterConst<P_numtype2> >(x.beginFast()); |
---|
555 | return *this; |
---|
556 | } |
---|
557 | |
---|
558 | template<typename P_numtype> template<typename P_numtype2> |
---|
559 | inline Vector<P_numtype>& |
---|
560 | Vector<P_numtype>::operator&=(const Vector<P_numtype2>& x) |
---|
561 | { |
---|
562 | (*this) &= _bz_VecExpr<VectorIterConst<P_numtype2> >(x.beginFast()); |
---|
563 | return *this; |
---|
564 | } |
---|
565 | |
---|
566 | template<typename P_numtype> template<typename P_numtype2> |
---|
567 | inline Vector<P_numtype>& |
---|
568 | Vector<P_numtype>::operator|=(const Vector<P_numtype2>& x) |
---|
569 | { |
---|
570 | (*this) |= _bz_VecExpr<VectorIterConst<P_numtype2> >(x.beginFast()); |
---|
571 | return *this; |
---|
572 | } |
---|
573 | |
---|
574 | template<typename P_numtype> template<typename P_numtype2> |
---|
575 | inline Vector<P_numtype>& |
---|
576 | Vector<P_numtype>::operator<<=(const Vector<P_numtype2>& x) |
---|
577 | { |
---|
578 | (*this) <<= _bz_VecExpr<VectorIterConst<P_numtype2> >(x.beginFast()); |
---|
579 | return *this; |
---|
580 | } |
---|
581 | |
---|
582 | template<typename P_numtype> template<typename P_numtype2> |
---|
583 | inline Vector<P_numtype>& |
---|
584 | Vector<P_numtype>::operator>>=(const Vector<P_numtype2>& x) |
---|
585 | { |
---|
586 | (*this) >>= _bz_VecExpr<VectorIterConst<P_numtype2> >(x.beginFast()); |
---|
587 | return *this; |
---|
588 | } |
---|
589 | |
---|
590 | /***************************************************************************** |
---|
591 | * Assignment operators with Range operand |
---|
592 | */ |
---|
593 | |
---|
594 | template<typename P_numtype> |
---|
595 | inline Vector<P_numtype>& Vector<P_numtype>::operator=(Range r) |
---|
596 | { |
---|
597 | (*this) = _bz_VecExpr<Range>(r); |
---|
598 | return *this; |
---|
599 | } |
---|
600 | |
---|
601 | template<typename P_numtype> |
---|
602 | inline Vector<P_numtype>& Vector<P_numtype>::operator+=(Range r) |
---|
603 | { |
---|
604 | (*this) += _bz_VecExpr<Range>(r); |
---|
605 | return *this; |
---|
606 | } |
---|
607 | |
---|
608 | template<typename P_numtype> |
---|
609 | inline Vector<P_numtype>& Vector<P_numtype>::operator-=(Range r) |
---|
610 | { |
---|
611 | (*this) -= _bz_VecExpr<Range>(r); |
---|
612 | return *this; |
---|
613 | } |
---|
614 | |
---|
615 | template<typename P_numtype> |
---|
616 | inline Vector<P_numtype>& Vector<P_numtype>::operator*=(Range r) |
---|
617 | { |
---|
618 | (*this) *= _bz_VecExpr<Range>(r); |
---|
619 | return *this; |
---|
620 | } |
---|
621 | |
---|
622 | template<typename P_numtype> |
---|
623 | inline Vector<P_numtype>& Vector<P_numtype>::operator/=(Range r) |
---|
624 | { |
---|
625 | (*this) /= _bz_VecExpr<Range>(r); |
---|
626 | return *this; |
---|
627 | } |
---|
628 | |
---|
629 | template<typename P_numtype> |
---|
630 | inline Vector<P_numtype>& Vector<P_numtype>::operator%=(Range r) |
---|
631 | { |
---|
632 | (*this) %= _bz_VecExpr<Range>(r); |
---|
633 | return *this; |
---|
634 | } |
---|
635 | |
---|
636 | template<typename P_numtype> |
---|
637 | inline Vector<P_numtype>& Vector<P_numtype>::operator^=(Range r) |
---|
638 | { |
---|
639 | (*this) ^= _bz_VecExpr<Range>(r); |
---|
640 | return *this; |
---|
641 | } |
---|
642 | |
---|
643 | template<typename P_numtype> |
---|
644 | inline Vector<P_numtype>& Vector<P_numtype>::operator&=(Range r) |
---|
645 | { |
---|
646 | (*this) &= _bz_VecExpr<Range>(r); |
---|
647 | return *this; |
---|
648 | } |
---|
649 | |
---|
650 | template<typename P_numtype> |
---|
651 | inline Vector<P_numtype>& Vector<P_numtype>::operator|=(Range r) |
---|
652 | { |
---|
653 | (*this) |= _bz_VecExpr<Range>(r); |
---|
654 | return *this; |
---|
655 | } |
---|
656 | |
---|
657 | template<typename P_numtype> |
---|
658 | inline Vector<P_numtype>& Vector<P_numtype>::operator>>=(Range r) |
---|
659 | { |
---|
660 | (*this) >>= _bz_VecExpr<Range>(r); |
---|
661 | return *this; |
---|
662 | } |
---|
663 | |
---|
664 | template<typename P_numtype> |
---|
665 | inline Vector<P_numtype>& Vector<P_numtype>::operator<<=(Range r) |
---|
666 | { |
---|
667 | (*this) <<= _bz_VecExpr<Range>(r); |
---|
668 | return *this; |
---|
669 | } |
---|
670 | |
---|
671 | /***************************************************************************** |
---|
672 | * Assignment operators with VectorPick operand |
---|
673 | */ |
---|
674 | |
---|
675 | template<typename P_numtype> template<typename P_numtype2> |
---|
676 | inline Vector<P_numtype>& Vector<P_numtype>::operator=(const |
---|
677 | VectorPick<P_numtype2>& x) |
---|
678 | { |
---|
679 | typedef VectorPickIterConst<P_numtype2> T_expr; |
---|
680 | (*this) = _bz_VecExpr<T_expr>(x.beginFast()); |
---|
681 | return *this; |
---|
682 | } |
---|
683 | |
---|
684 | template<typename P_numtype> template<typename P_numtype2> |
---|
685 | inline Vector<P_numtype>& Vector<P_numtype>::operator+=(const |
---|
686 | VectorPick<P_numtype2>& x) |
---|
687 | { |
---|
688 | typedef VectorPickIterConst<P_numtype2> T_expr; |
---|
689 | (*this) += _bz_VecExpr<T_expr>(x.beginFast()); |
---|
690 | return *this; |
---|
691 | } |
---|
692 | |
---|
693 | |
---|
694 | template<typename P_numtype> template<typename P_numtype2> |
---|
695 | inline Vector<P_numtype>& Vector<P_numtype>::operator-=(const |
---|
696 | VectorPick<P_numtype2>& x) |
---|
697 | { |
---|
698 | typedef VectorPickIterConst<P_numtype2> T_expr; |
---|
699 | (*this) -= _bz_VecExpr<T_expr>(x.beginFast()); |
---|
700 | return *this; |
---|
701 | } |
---|
702 | |
---|
703 | template<typename P_numtype> template<typename P_numtype2> |
---|
704 | inline Vector<P_numtype>& Vector<P_numtype>::operator*=(const |
---|
705 | VectorPick<P_numtype2>& x) |
---|
706 | { |
---|
707 | typedef VectorPickIterConst<P_numtype2> T_expr; |
---|
708 | (*this) *= _bz_VecExpr<T_expr>(x.beginFast()); |
---|
709 | return *this; |
---|
710 | } |
---|
711 | |
---|
712 | template<typename P_numtype> template<typename P_numtype2> |
---|
713 | inline Vector<P_numtype>& Vector<P_numtype>::operator/=(const |
---|
714 | VectorPick<P_numtype2>& x) |
---|
715 | { |
---|
716 | typedef VectorPickIterConst<P_numtype2> T_expr; |
---|
717 | (*this) /= _bz_VecExpr<T_expr>(x.beginFast()); |
---|
718 | return *this; |
---|
719 | } |
---|
720 | |
---|
721 | template<typename P_numtype> template<typename P_numtype2> |
---|
722 | inline Vector<P_numtype>& Vector<P_numtype>::operator%=(const |
---|
723 | VectorPick<P_numtype2>& x) |
---|
724 | { |
---|
725 | typedef VectorPickIterConst<P_numtype2> T_expr; |
---|
726 | (*this) %= _bz_VecExpr<T_expr>(x.beginFast()); |
---|
727 | return *this; |
---|
728 | } |
---|
729 | |
---|
730 | template<typename P_numtype> template<typename P_numtype2> |
---|
731 | inline Vector<P_numtype>& Vector<P_numtype>::operator^=(const |
---|
732 | VectorPick<P_numtype2>& x) |
---|
733 | { |
---|
734 | typedef VectorPickIterConst<P_numtype2> T_expr; |
---|
735 | (*this) ^= _bz_VecExpr<T_expr>(x.beginFast()); |
---|
736 | return *this; |
---|
737 | } |
---|
738 | |
---|
739 | template<typename P_numtype> template<typename P_numtype2> |
---|
740 | inline Vector<P_numtype>& Vector<P_numtype>::operator&=(const |
---|
741 | VectorPick<P_numtype2>& x) |
---|
742 | { |
---|
743 | typedef VectorPickIterConst<P_numtype2> T_expr; |
---|
744 | (*this) &= _bz_VecExpr<T_expr>(x.beginFast()); |
---|
745 | return *this; |
---|
746 | } |
---|
747 | |
---|
748 | template<typename P_numtype> template<typename P_numtype2> |
---|
749 | inline Vector<P_numtype>& Vector<P_numtype>::operator|=(const |
---|
750 | VectorPick<P_numtype2>& x) |
---|
751 | { |
---|
752 | typedef VectorPickIterConst<P_numtype2> T_expr; |
---|
753 | (*this) |= _bz_VecExpr<T_expr>(x.beginFast()); |
---|
754 | return *this; |
---|
755 | } |
---|
756 | |
---|
757 | /***************************************************************************** |
---|
758 | * Assignment operators with Random operand |
---|
759 | */ |
---|
760 | |
---|
761 | template<typename P_numtype> template<typename P_distribution> |
---|
762 | Vector<P_numtype>& Vector<P_numtype>::operator=(Random<P_distribution>& rand) |
---|
763 | { |
---|
764 | for (int i=0; i < length_; ++i) |
---|
765 | (*this)[i] = rand.random(); |
---|
766 | return *this; |
---|
767 | } |
---|
768 | |
---|
769 | #ifdef BZ_PECULIAR_RANDOM_VECTOR_ASSIGN_BUG |
---|
770 | |
---|
771 | template<typename P_numtype> template<typename P_distribution> |
---|
772 | Vector<P_numtype>& Vector<P_numtype>::operator=(Random<P_distribution>& rand) |
---|
773 | { |
---|
774 | (*this) = _bz_VecExpr<_bz_VecExprRandom<P_distribution> > |
---|
775 | (_bz_VecExprRandom<P_distribution>(rand)); |
---|
776 | return *this; |
---|
777 | } |
---|
778 | |
---|
779 | template<typename P_numtype> template<typename P_distribution> |
---|
780 | Vector<P_numtype>& Vector<P_numtype>::operator+=(Random<P_distribution>& rand) |
---|
781 | { |
---|
782 | (*this) += _bz_VecExpr<_bz_VecExprRandom<P_distribution> > |
---|
783 | (_bz_VecExprRandom<P_distribution>(rand)); |
---|
784 | return *this; |
---|
785 | } |
---|
786 | |
---|
787 | template<typename P_numtype> template<typename P_distribution> |
---|
788 | Vector<P_numtype>& Vector<P_numtype>::operator-=(Random<P_distribution>& rand) |
---|
789 | { |
---|
790 | (*this) -= _bz_VecExpr<_bz_VecExprRandom<P_distribution> > |
---|
791 | (_bz_VecExprRandom<P_distribution>(rand)); |
---|
792 | return *this; |
---|
793 | } |
---|
794 | |
---|
795 | template<typename P_numtype> template<typename P_distribution> |
---|
796 | Vector<P_numtype>& Vector<P_numtype>::operator*=(Random<P_distribution>& rand) |
---|
797 | { |
---|
798 | (*this) *= _bz_VecExpr<_bz_VecExprRandom<P_distribution> > |
---|
799 | (_bz_VecExprRandom<P_distribution>(rand)); |
---|
800 | return *this; |
---|
801 | } |
---|
802 | |
---|
803 | template<typename P_numtype> template<typename P_distribution> |
---|
804 | Vector<P_numtype>& Vector<P_numtype>::operator/=(Random<P_distribution>& rand) |
---|
805 | { |
---|
806 | (*this) /= _bz_VecExpr<_bz_VecExprRandom<P_distribution> > |
---|
807 | (_bz_VecExprRandom<P_distribution>(rand)); |
---|
808 | return *this; |
---|
809 | } |
---|
810 | |
---|
811 | template<typename P_numtype> template<typename P_distribution> |
---|
812 | Vector<P_numtype>& Vector<P_numtype>::operator%=(Random<P_distribution>& rand) |
---|
813 | { |
---|
814 | (*this) %= _bz_VecExpr<_bz_VecExprRandom<P_distribution> > |
---|
815 | (_bz_VecExprRandom<P_distribution>(rand)); |
---|
816 | return *this; |
---|
817 | } |
---|
818 | |
---|
819 | template<typename P_numtype> template<typename P_distribution> |
---|
820 | Vector<P_numtype>& Vector<P_numtype>::operator^=(Random<P_distribution>& rand) |
---|
821 | { |
---|
822 | (*this) ^= _bz_VecExpr<_bz_VecExprRandom<P_distribution> > |
---|
823 | (_bz_VecExprRandom<P_distribution>(rand)); |
---|
824 | return *this; |
---|
825 | } |
---|
826 | |
---|
827 | template<typename P_numtype> template<typename P_distribution> |
---|
828 | Vector<P_numtype>& Vector<P_numtype>::operator&=(Random<P_distribution>& rand) |
---|
829 | { |
---|
830 | (*this) &= _bz_VecExpr<_bz_VecExprRandom<P_distribution> > |
---|
831 | (_bz_VecExprRandom<P_distribution>(rand)); |
---|
832 | return *this; |
---|
833 | } |
---|
834 | |
---|
835 | template<typename P_numtype> template<typename P_distribution> |
---|
836 | Vector<P_numtype>& Vector<P_numtype>::operator|=(Random<P_distribution>& rand) |
---|
837 | { |
---|
838 | (*this) |= _bz_VecExpr<_bz_VecExprRandom<P_distribution> > |
---|
839 | (_bz_VecExprRandom<P_distribution>(rand)); |
---|
840 | return *this; |
---|
841 | } |
---|
842 | |
---|
843 | #endif // BZ_PECULIAR_RANDOM_VECTOR_ASSIGN_BUG |
---|
844 | |
---|
845 | BZ_NAMESPACE_END |
---|
846 | |
---|
847 | #endif // BZ_VECTOR_CC |
---|