source: XMLIO_V2/external/include/blitz/vector.cc @ 80

Last change on this file since 80 was 80, checked in by ymipsl, 14 years ago

ajout lib externe

File size: 27.5 KB
Line 
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
16BZ_NAMESPACE(blitz)
17
18template<typename P_numtype>
19Vector<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
40template<typename P_numtype>
41void 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
50template<typename P_numtype>
51void 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
58template<typename P_numtype>
59void 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
69template<typename P_numtype>
70void 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
86template<typename P_numtype> template<typename P_expr, typename P_updater>
87inline
88void 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
141template<typename P_numtype> template<typename P_expr>
142inline 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)                                            \
199template<typename P_numtype> template<typename P_expr>                        \
200inline 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)                                            \
249template<typename P_numtype> template<typename P_expr>                        \
250inline 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)                                            \
275template<typename P_numtype> template<typename P_expr>                        \
276inline 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
294BZ_VECTOR_ASSIGN(+=)
295BZ_VECTOR_ASSIGN(-=)
296BZ_VECTOR_ASSIGN(*=)
297BZ_VECTOR_ASSIGN(/=)
298BZ_VECTOR_ASSIGN(%=)
299BZ_VECTOR_ASSIGN(^=)
300BZ_VECTOR_ASSIGN(&=)
301BZ_VECTOR_ASSIGN(|=)
302BZ_VECTOR_ASSIGN(>>=)
303BZ_VECTOR_ASSIGN(<<=)
304
305#if NOT_DEFINED
306
307template<typename P_numtype> template<typename P_expr>
308inline 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
315template<typename P_numtype> template<typename P_expr>
316inline 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
323template<typename P_numtype> template<typename P_expr>
324inline 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
331template<typename P_numtype> template<typename P_expr>
332inline 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
339template<typename P_numtype> template<typename P_expr>
340inline 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
347template<typename P_numtype> template<typename P_expr>
348inline 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
355template<typename P_numtype> template<typename P_expr>
356inline 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
363template<typename P_numtype> template<typename P_expr>
364inline 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
371template<typename P_numtype> template<typename P_expr>
372inline 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
379template<typename P_numtype> template<typename P_expr>
380inline 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
392template<typename P_numtype>
393inline 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
400template<typename P_numtype>
401inline 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
408template<typename P_numtype>
409inline 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
416template<typename P_numtype>
417inline 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
424template<typename P_numtype>
425inline 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
432template<typename P_numtype>
433inline 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
440template<typename P_numtype>
441inline 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
448template<typename P_numtype>
449inline 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
456template<typename P_numtype>
457inline 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
464template<typename P_numtype>
465inline 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
472template<typename P_numtype>
473inline 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
488template<typename P_numtype> template<>
489inline Vector<P_numtype>&
490Vector<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.
502template<typename P_numtype> template<typename P_numtype2>
503inline Vector<P_numtype>& 
504Vector<P_numtype>::operator=(const Vector<P_numtype2>& x)
505{
506    (*this) = _bz_VecExpr<VectorIterConst<P_numtype2> >(x.beginFast());
507    return *this;
508}
509
510template<typename P_numtype> template<typename P_numtype2>
511inline Vector<P_numtype>&
512Vector<P_numtype>::operator+=(const Vector<P_numtype2>& x)
513{
514    (*this) += _bz_VecExpr<VectorIterConst<P_numtype2> >(x.beginFast());
515    return *this;
516}
517
518template<typename P_numtype> template<typename P_numtype2>
519inline Vector<P_numtype>&
520Vector<P_numtype>::operator-=(const Vector<P_numtype2>& x)
521{
522    (*this) -= _bz_VecExpr<VectorIterConst<P_numtype2> >(x.beginFast());
523    return *this;
524}
525
526template<typename P_numtype> template<typename P_numtype2>
527inline Vector<P_numtype>&
528Vector<P_numtype>::operator*=(const Vector<P_numtype2>& x)
529{
530    (*this) *= _bz_VecExpr<VectorIterConst<P_numtype2> >(x.beginFast());
531    return *this;
532}
533
534template<typename P_numtype> template<typename P_numtype2>
535inline Vector<P_numtype>&
536Vector<P_numtype>::operator/=(const Vector<P_numtype2>& x)
537{
538    (*this) /= _bz_VecExpr<VectorIterConst<P_numtype2> >(x.beginFast());
539    return *this;
540}
541
542template<typename P_numtype> template<typename P_numtype2>
543inline Vector<P_numtype>&
544Vector<P_numtype>::operator%=(const Vector<P_numtype2>& x)
545{
546    (*this) %= _bz_VecExpr<VectorIterConst<P_numtype2> >(x.beginFast());
547    return *this;
548}
549
550template<typename P_numtype> template<typename P_numtype2>
551inline Vector<P_numtype>&
552Vector<P_numtype>::operator^=(const Vector<P_numtype2>& x)
553{
554    (*this) ^= _bz_VecExpr<VectorIterConst<P_numtype2> >(x.beginFast());
555    return *this;
556}
557
558template<typename P_numtype> template<typename P_numtype2>
559inline Vector<P_numtype>&
560Vector<P_numtype>::operator&=(const Vector<P_numtype2>& x)
561{
562    (*this) &= _bz_VecExpr<VectorIterConst<P_numtype2> >(x.beginFast());
563    return *this;
564}
565
566template<typename P_numtype> template<typename P_numtype2>
567inline Vector<P_numtype>&
568Vector<P_numtype>::operator|=(const Vector<P_numtype2>& x)
569{
570    (*this) |= _bz_VecExpr<VectorIterConst<P_numtype2> >(x.beginFast());
571    return *this;
572}
573
574template<typename P_numtype> template<typename P_numtype2>
575inline Vector<P_numtype>&
576Vector<P_numtype>::operator<<=(const Vector<P_numtype2>& x)
577{
578    (*this) <<= _bz_VecExpr<VectorIterConst<P_numtype2> >(x.beginFast());
579    return *this;
580}
581
582template<typename P_numtype> template<typename P_numtype2>
583inline Vector<P_numtype>&
584Vector<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
594template<typename P_numtype>
595inline Vector<P_numtype>& Vector<P_numtype>::operator=(Range r)
596{
597    (*this) = _bz_VecExpr<Range>(r);
598    return *this;
599}
600
601template<typename P_numtype>
602inline Vector<P_numtype>& Vector<P_numtype>::operator+=(Range r)
603{
604    (*this) += _bz_VecExpr<Range>(r);
605    return *this;
606}
607
608template<typename P_numtype>
609inline Vector<P_numtype>& Vector<P_numtype>::operator-=(Range r)
610{
611    (*this) -= _bz_VecExpr<Range>(r);
612    return *this;
613}
614
615template<typename P_numtype>
616inline Vector<P_numtype>& Vector<P_numtype>::operator*=(Range r)
617{
618    (*this) *= _bz_VecExpr<Range>(r);
619    return *this;
620}
621
622template<typename P_numtype>
623inline Vector<P_numtype>& Vector<P_numtype>::operator/=(Range r)
624{
625    (*this) /= _bz_VecExpr<Range>(r);
626    return *this;
627}
628
629template<typename P_numtype>
630inline Vector<P_numtype>& Vector<P_numtype>::operator%=(Range r)
631{
632    (*this) %= _bz_VecExpr<Range>(r);
633    return *this;
634}
635
636template<typename P_numtype>
637inline Vector<P_numtype>& Vector<P_numtype>::operator^=(Range r)
638{
639    (*this) ^= _bz_VecExpr<Range>(r);
640    return *this;
641}
642
643template<typename P_numtype>
644inline Vector<P_numtype>& Vector<P_numtype>::operator&=(Range r)
645{
646    (*this) &= _bz_VecExpr<Range>(r);
647    return *this;
648}
649
650template<typename P_numtype>
651inline Vector<P_numtype>& Vector<P_numtype>::operator|=(Range r)
652{
653    (*this) |= _bz_VecExpr<Range>(r);
654    return *this;
655}
656
657template<typename P_numtype>
658inline Vector<P_numtype>& Vector<P_numtype>::operator>>=(Range r)
659{
660    (*this) >>= _bz_VecExpr<Range>(r);
661    return *this;
662}
663
664template<typename P_numtype>
665inline 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
675template<typename P_numtype> template<typename P_numtype2>
676inline 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
684template<typename P_numtype> template<typename P_numtype2>
685inline 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
694template<typename P_numtype> template<typename P_numtype2>
695inline 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
703template<typename P_numtype> template<typename P_numtype2>
704inline 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
712template<typename P_numtype> template<typename P_numtype2>
713inline 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
721template<typename P_numtype> template<typename P_numtype2>
722inline 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
730template<typename P_numtype> template<typename P_numtype2>
731inline 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
739template<typename P_numtype> template<typename P_numtype2>
740inline 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
748template<typename P_numtype> template<typename P_numtype2>
749inline 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
761template<typename P_numtype> template<typename P_distribution>
762Vector<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
771template<typename P_numtype> template<typename P_distribution>
772Vector<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
779template<typename P_numtype> template<typename P_distribution>
780Vector<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
787template<typename P_numtype> template<typename P_distribution>
788Vector<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
795template<typename P_numtype> template<typename P_distribution>
796Vector<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
803template<typename P_numtype> template<typename P_distribution>
804Vector<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
811template<typename P_numtype> template<typename P_distribution>
812Vector<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
819template<typename P_numtype> template<typename P_distribution>
820Vector<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
827template<typename P_numtype> template<typename P_distribution>
828Vector<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
835template<typename P_numtype> template<typename P_distribution>
836Vector<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
845BZ_NAMESPACE_END
846
847#endif // BZ_VECTOR_CC
Note: See TracBrowser for help on using the repository browser.