source: Sophya/trunk/SophyaExt/Blitz/blitz/tinyvec.cc@ 3772

Last change on this file since 3772 was 221, checked in by ansari, 26 years ago

Creation module DPC/Blitz (blitz 0.4) Reza 09/04/99

File size: 18.7 KB
Line 
1#ifndef BZ_TINYVEC_CC
2#define BZ_TINYVEC_CC
3
4#ifndef BZ_TINYVEC_H
5 #include <blitz/tinyvec.h>
6#endif
7
8#ifndef BZ_VECTOR_H
9 #include <blitz/vector.h>
10#endif
11
12#ifndef BZ_VECPICK_H
13 #include <blitz/vecpick.h>
14#endif
15
16#ifndef BZ_RANGE_H
17 #include <blitz/range.h>
18#endif
19
20#include <blitz/meta/vecassign.h>
21
22BZ_NAMESPACE(blitz)
23
24template<class T_numtype, int N_length>
25inline TinyVector<T_numtype, N_length>::TinyVector(T_numtype initValue)
26{
27 for (int i=0; i < N_length; ++i)
28 data_[i] = initValue;
29}
30
31template<class T_numtype, int N_length>
32inline TinyVector<T_numtype, N_length>::TinyVector(const
33 TinyVector<T_numtype, N_length>& x)
34{
35 for (int i=0; i < N_length; ++i)
36 data_[i] = x.data_[i];
37}
38
39template<class T_numtype, int N_length> template<class P_expr, class P_updater>
40inline
41void TinyVector<T_numtype, N_length>::_bz_assign(P_expr expr, P_updater up)
42{
43 BZPRECHECK(expr.length(N_length) == N_length,
44 "An expression with length " << expr.length(N_length)
45 << " was assigned to a TinyVector<"
46 << BZ_DEBUG_TEMPLATE_AS_STRING_LITERAL(T_numtype)
47 << "," << N_length << ">");
48
49 if (expr._bz_hasFastAccess())
50 {
51 _bz_meta_vecAssign<N_length, 0>::fastAssign(*this, expr, up);
52 }
53 else {
54 _bz_meta_vecAssign<N_length, 0>::assign(*this, expr, up);
55 }
56}
57
58/*****************************************************************************
59 * Assignment operators with vector expression operand
60 */
61
62template<class P_numtype, int N_length> template<class P_expr>
63inline TinyVector<P_numtype, N_length>&
64TinyVector<P_numtype, N_length>::operator=(_bz_VecExpr<P_expr> expr)
65{
66 _bz_assign(expr, _bz_update<P_numtype, _bz_typename P_expr::T_numtype>());
67 return *this;
68}
69
70template<class P_numtype, int N_length> template<class P_expr>
71inline TinyVector<P_numtype, N_length>&
72TinyVector<P_numtype, N_length>::operator+=(_bz_VecExpr<P_expr> expr)
73{
74 _bz_assign(expr, _bz_plus_update<P_numtype,
75 _bz_typename P_expr::T_numtype>());
76 return *this;
77}
78
79template<class P_numtype, int N_length> template<class P_expr>
80inline TinyVector<P_numtype, N_length>&
81TinyVector<P_numtype, N_length>::operator-=(_bz_VecExpr<P_expr> expr)
82{
83 _bz_assign(expr, _bz_minus_update<P_numtype,
84 _bz_typename P_expr::T_numtype>());
85 return *this;
86}
87
88template<class P_numtype, int N_length> template<class P_expr>
89inline TinyVector<P_numtype, N_length>&
90TinyVector<P_numtype, N_length>::operator*=(_bz_VecExpr<P_expr> expr)
91{
92 _bz_assign(expr, _bz_multiply_update<P_numtype,
93 _bz_typename P_expr::T_numtype>());
94 return *this;
95}
96
97template<class P_numtype, int N_length> template<class P_expr>
98inline TinyVector<P_numtype, N_length>&
99TinyVector<P_numtype, N_length>::operator/=(_bz_VecExpr<P_expr> expr)
100{
101 _bz_assign(expr, _bz_divide_update<P_numtype,
102 _bz_typename P_expr::T_numtype>());
103 return *this;
104}
105
106template<class P_numtype, int N_length> template<class P_expr>
107inline TinyVector<P_numtype, N_length>&
108TinyVector<P_numtype, N_length>::operator%=(_bz_VecExpr<P_expr> expr)
109{
110 _bz_assign(expr, _bz_mod_update<P_numtype,
111 _bz_typename P_expr::T_numtype>());
112 return *this;
113}
114
115template<class P_numtype, int N_length> template<class P_expr>
116inline TinyVector<P_numtype, N_length>&
117TinyVector<P_numtype, N_length>::operator^=(_bz_VecExpr<P_expr> expr)
118{
119 _bz_assign(expr, _bz_xor_update<P_numtype,
120 _bz_typename P_expr::T_numtype>());
121 return *this;
122}
123
124template<class P_numtype, int N_length> template<class P_expr>
125inline TinyVector<P_numtype, N_length>&
126TinyVector<P_numtype, N_length>::operator&=(_bz_VecExpr<P_expr> expr)
127{
128 _bz_assign(expr, _bz_bitand_update<P_numtype,
129 _bz_typename P_expr::T_numtype>());
130 return *this;
131}
132
133template<class P_numtype, int N_length> template<class P_expr>
134inline TinyVector<P_numtype, N_length>&
135TinyVector<P_numtype, N_length>::operator|=(_bz_VecExpr<P_expr> expr)
136{
137 _bz_assign(expr, _bz_bitor_update<P_numtype,
138 _bz_typename P_expr::T_numtype>());
139 return *this;
140}
141
142template<class P_numtype, int N_length> template<class P_expr>
143inline TinyVector<P_numtype, N_length>&
144TinyVector<P_numtype, N_length>::operator<<=(_bz_VecExpr<P_expr> expr)
145{
146 _bz_assign(expr, _bz_shiftl_update<P_numtype,
147 _bz_typename P_expr::T_numtype>());
148 return *this;
149}
150
151template<class P_numtype, int N_length> template<class P_expr>
152inline TinyVector<P_numtype, N_length>&
153TinyVector<P_numtype, N_length>::operator>>=(_bz_VecExpr<P_expr> expr)
154{
155 _bz_assign(expr, _bz_shiftr_update<P_numtype,
156 _bz_typename P_expr::T_numtype>());
157 return *this;
158}
159
160/*****************************************************************************
161 * Assignment operators with scalar operand
162 */
163
164template<class P_numtype, int N_length>
165inline TinyVector<P_numtype, N_length>&
166TinyVector<P_numtype, N_length>::initialize(P_numtype x)
167{
168#ifndef BZ_KCC_COPY_PROPAGATION_KLUDGE
169 typedef _bz_VecExprConstant<P_numtype> T_expr;
170 (*this) = _bz_VecExpr<T_expr>(T_expr(x));
171#else
172 // Avoid using the copy propagation kludge for this simple
173 // operation.
174 for (int i=0; i < N_length; ++i)
175 data_[i] = x;
176#endif
177 return *this;
178}
179
180template<class P_numtype, int N_length>
181inline TinyVector<P_numtype, N_length>&
182TinyVector<P_numtype, N_length>::operator+=(P_numtype x)
183{
184 typedef _bz_VecExprConstant<P_numtype> T_expr;
185 (*this) += _bz_VecExpr<T_expr>(T_expr(x));
186 return *this;
187}
188
189template<class P_numtype, int N_length>
190inline TinyVector<P_numtype, N_length>&
191TinyVector<P_numtype, N_length>::operator-=(P_numtype x)
192{
193 typedef _bz_VecExprConstant<P_numtype> T_expr;
194 (*this) -= _bz_VecExpr<T_expr>(T_expr(x));
195 return *this;
196}
197
198template<class P_numtype, int N_length>
199inline TinyVector<P_numtype, N_length>&
200TinyVector<P_numtype, N_length>::operator*=(P_numtype x)
201{
202 typedef _bz_VecExprConstant<P_numtype> T_expr;
203 (*this) *= _bz_VecExpr<T_expr>(T_expr(x));
204 return *this;
205}
206
207template<class P_numtype, int N_length>
208inline TinyVector<P_numtype, N_length>&
209TinyVector<P_numtype, N_length>::operator/=(P_numtype x)
210{
211 typedef _bz_VecExprConstant<P_numtype> T_expr;
212 (*this) /= _bz_VecExpr<T_expr>(T_expr(x));
213 return *this;
214}
215
216template<class P_numtype, int N_length>
217inline TinyVector<P_numtype, N_length>&
218TinyVector<P_numtype, N_length>::operator%=(P_numtype x)
219{
220 typedef _bz_VecExprConstant<P_numtype> T_expr;
221 (*this) %= _bz_VecExpr<T_expr>(T_expr(x));
222 return *this;
223}
224
225template<class P_numtype, int N_length>
226inline TinyVector<P_numtype, N_length>&
227TinyVector<P_numtype, N_length>::operator^=(P_numtype x)
228{
229 typedef _bz_VecExprConstant<P_numtype> T_expr;
230 (*this) ^= _bz_VecExpr<T_expr>(T_expr(x));
231 return *this;
232}
233
234template<class P_numtype, int N_length>
235inline TinyVector<P_numtype, N_length>&
236TinyVector<P_numtype, N_length>::operator&=(P_numtype x)
237{
238 typedef _bz_VecExprConstant<P_numtype> T_expr;
239 (*this) &= _bz_VecExpr<T_expr>(T_expr(x));
240 return *this;
241}
242
243template<class P_numtype, int N_length>
244inline TinyVector<P_numtype, N_length>&
245TinyVector<P_numtype, N_length>::operator|=(P_numtype x)
246{
247 typedef _bz_VecExprConstant<P_numtype> T_expr;
248 (*this) |= _bz_VecExpr<T_expr>(T_expr(x));
249 return *this;
250}
251
252template<class P_numtype, int N_length>
253inline TinyVector<P_numtype, N_length>&
254TinyVector<P_numtype, N_length>::operator<<=(int x)
255{
256 typedef _bz_VecExprConstant<int> T_expr;
257 (*this) <<= _bz_VecExpr<T_expr>(T_expr(x));
258 return *this;
259}
260
261template<class P_numtype, int N_length>
262inline TinyVector<P_numtype, N_length>&
263TinyVector<P_numtype, N_length>::operator>>=(int x)
264{
265 typedef _bz_VecExprConstant<int> T_expr;
266 (*this) >>= _bz_VecExpr<T_expr>(T_expr(x));
267 return *this;
268}
269
270/*****************************************************************************
271 * Assignment operators with TinyVector operand
272 */
273
274template<class P_numtype, int N_length> template<class P_numtype2>
275inline TinyVector<P_numtype, N_length>&
276TinyVector<P_numtype, N_length>::operator=(const
277 TinyVector<P_numtype2, N_length>& x)
278{
279 (*this) = _bz_VecExpr<_bz_typename
280 TinyVector<P_numtype2, N_length>::T_constIterator>(x.begin());
281 return *this;
282}
283
284template<class P_numtype, int N_length> template<class P_numtype2>
285inline TinyVector<P_numtype, N_length>&
286TinyVector<P_numtype, N_length>::operator+=(const
287 TinyVector<P_numtype2, N_length>& x)
288{
289 (*this) += _bz_VecExpr<_bz_typename
290 TinyVector<P_numtype2, N_length>::T_constIterator>(x.begin());
291 return *this;
292}
293
294template<class P_numtype, int N_length> template<class P_numtype2>
295inline TinyVector<P_numtype, N_length>&
296TinyVector<P_numtype, N_length>::operator-=(const
297 TinyVector<P_numtype2, N_length>& x)
298{
299 (*this) -= _bz_VecExpr<_bz_typename
300 TinyVector<P_numtype2, N_length>::T_constIterator>(x.begin());
301 return *this;
302}
303
304template<class P_numtype, int N_length> template<class P_numtype2>
305inline TinyVector<P_numtype, N_length>&
306TinyVector<P_numtype, N_length>::operator*=(const
307 TinyVector<P_numtype2, N_length>& x)
308{
309 (*this) *= _bz_VecExpr<_bz_typename
310 TinyVector<P_numtype2, N_length>::T_constIterator>(x.begin());
311 return *this;
312}
313
314template<class P_numtype, int N_length> template<class P_numtype2>
315inline TinyVector<P_numtype, N_length>&
316TinyVector<P_numtype, N_length>::operator/=(const
317 TinyVector<P_numtype2, N_length>& x)
318{
319 (*this) /= _bz_VecExpr<_bz_typename
320 TinyVector<P_numtype2, N_length>::T_constIterator>(x.begin());
321 return *this;
322}
323
324template<class P_numtype, int N_length> template<class P_numtype2>
325inline TinyVector<P_numtype, N_length>&
326TinyVector<P_numtype, N_length>::operator%=(const
327 TinyVector<P_numtype2, N_length>& x)
328{
329 (*this) %= _bz_VecExpr<_bz_typename
330 TinyVector<P_numtype2, N_length>::T_constIterator>(x.begin());
331 return *this;
332}
333
334template<class P_numtype, int N_length> template<class P_numtype2>
335inline TinyVector<P_numtype, N_length>&
336TinyVector<P_numtype, N_length>::operator^=(const
337 TinyVector<P_numtype2, N_length>& x)
338{
339 (*this) ^= _bz_VecExpr<_bz_typename
340 TinyVector<P_numtype2, N_length>::T_constIterator>(x.begin());
341 return *this;
342}
343
344template<class P_numtype, int N_length> template<class P_numtype2>
345inline TinyVector<P_numtype, N_length>&
346TinyVector<P_numtype, N_length>::operator&=(const
347 TinyVector<P_numtype2, N_length>& x)
348{
349 (*this) &= _bz_VecExpr<_bz_typename
350 TinyVector<P_numtype2, N_length>::T_constIterator>(x.begin());
351 return *this;
352}
353
354template<class P_numtype, int N_length> template<class P_numtype2>
355inline TinyVector<P_numtype, N_length>&
356TinyVector<P_numtype, N_length>::operator|=(const
357 TinyVector<P_numtype2, N_length>& x)
358{
359 (*this) |= _bz_VecExpr<_bz_typename
360 TinyVector<P_numtype2, N_length>::T_constIterator>(x.begin());
361 return *this;
362}
363
364template<class P_numtype, int N_length> template<class P_numtype2>
365inline TinyVector<P_numtype, N_length>&
366TinyVector<P_numtype, N_length>::operator<<=(const
367 TinyVector<P_numtype2, N_length>& x)
368{
369 (*this) <<= _bz_VecExpr<_bz_typename
370 TinyVector<P_numtype2, N_length>::T_constIterator>(x.begin());
371 return *this;
372}
373
374template<class P_numtype, int N_length> template<class P_numtype2>
375inline TinyVector<P_numtype, N_length>&
376TinyVector<P_numtype, N_length>::operator>>=(const
377 TinyVector<P_numtype2, N_length>& x)
378{
379 (*this) >>= _bz_VecExpr<_bz_typename
380 TinyVector<P_numtype2, N_length>::T_constIterator>(x.begin());
381 return *this;
382}
383
384/*****************************************************************************
385 * Assignment operators with Vector operand
386 */
387
388template<class P_numtype, int N_length> template<class P_numtype2>
389inline TinyVector<P_numtype, N_length>&
390TinyVector<P_numtype, N_length>::operator=(const Vector<P_numtype2>& x)
391{
392 (*this) = x._bz_asVecExpr();
393 return *this;
394}
395
396template<class P_numtype, int N_length> template<class P_numtype2>
397inline TinyVector<P_numtype, N_length>&
398TinyVector<P_numtype, N_length>::operator+=(const Vector<P_numtype2>& x)
399{
400 (*this) += x._bz_asVecExpr();
401 return *this;
402}
403
404template<class P_numtype, int N_length> template<class P_numtype2>
405inline TinyVector<P_numtype, N_length>&
406TinyVector<P_numtype, N_length>::operator-=(const Vector<P_numtype2>& x)
407{
408 (*this) -= x._bz_asVecExpr();
409 return *this;
410}
411
412template<class P_numtype, int N_length> template<class P_numtype2>
413inline TinyVector<P_numtype, N_length>&
414TinyVector<P_numtype, N_length>::operator*=(const Vector<P_numtype2>& x)
415{
416 (*this) *= x._bz_asVecExpr();
417 return *this;
418}
419
420template<class P_numtype, int N_length> template<class P_numtype2>
421inline TinyVector<P_numtype, N_length>&
422TinyVector<P_numtype, N_length>::operator/=(const Vector<P_numtype2>& x)
423{
424 (*this) /= x._bz_asVecExpr();
425 return *this;
426}
427
428template<class P_numtype, int N_length> template<class P_numtype2>
429inline TinyVector<P_numtype, N_length>&
430TinyVector<P_numtype, N_length>::operator%=(const Vector<P_numtype2>& x)
431{
432 (*this) %= x._bz_asVecExpr();
433 return *this;
434}
435
436template<class P_numtype, int N_length> template<class P_numtype2>
437inline TinyVector<P_numtype, N_length>&
438TinyVector<P_numtype, N_length>::operator^=(const Vector<P_numtype2>& x)
439{
440 (*this) ^= x._bz_asVecExpr();
441 return *this;
442}
443
444template<class P_numtype, int N_length> template<class P_numtype2>
445inline TinyVector<P_numtype, N_length>&
446TinyVector<P_numtype, N_length>::operator&=(const Vector<P_numtype2>& x)
447{
448 (*this) &= x._bz_asVecExpr();
449 return *this;
450}
451
452template<class P_numtype, int N_length> template<class P_numtype2>
453inline TinyVector<P_numtype, N_length>&
454TinyVector<P_numtype, N_length>::operator|=(const Vector<P_numtype2>& x)
455{
456 (*this) |= x._bz_asVecExpr();
457 return *this;
458}
459
460template<class P_numtype, int N_length> template<class P_numtype2>
461inline TinyVector<P_numtype, N_length>&
462TinyVector<P_numtype, N_length>::operator<<=(const Vector<P_numtype2>& x)
463{
464 (*this) <<= x._bz_asVecExpr();
465 return *this;
466}
467
468template<class P_numtype, int N_length> template<class P_numtype2>
469inline TinyVector<P_numtype, N_length>&
470TinyVector<P_numtype, N_length>::operator>>=(const Vector<P_numtype2>& x)
471{
472 (*this) >>= x._bz_asVecExpr();
473 return *this;
474}
475
476/*****************************************************************************
477 * Assignment operators with Range operand
478 */
479
480template<class P_numtype, int N_length>
481inline TinyVector<P_numtype, N_length>&
482TinyVector<P_numtype, N_length>::operator=(Range r)
483{
484 (*this) = r._bz_asVecExpr();
485 return *this;
486}
487
488template<class P_numtype, int N_length>
489inline TinyVector<P_numtype, N_length>&
490TinyVector<P_numtype, N_length>::operator+=(Range r)
491{
492 (*this) += r._bz_asVecExpr();
493 return *this;
494}
495
496template<class P_numtype, int N_length>
497inline TinyVector<P_numtype, N_length>&
498TinyVector<P_numtype, N_length>::operator-=(Range r)
499{
500 (*this) -= r._bz_asVecExpr();
501 return *this;
502}
503
504template<class P_numtype, int N_length>
505inline TinyVector<P_numtype, N_length>&
506TinyVector<P_numtype, N_length>::operator*=(Range r)
507{
508 (*this) *= r._bz_asVecExpr();
509 return *this;
510}
511
512template<class P_numtype, int N_length>
513inline TinyVector<P_numtype, N_length>&
514TinyVector<P_numtype, N_length>::operator/=(Range r)
515{
516 (*this) /= r._bz_asVecExpr();
517 return *this;
518}
519
520template<class P_numtype, int N_length>
521inline TinyVector<P_numtype, N_length>&
522TinyVector<P_numtype, N_length>::operator%=(Range r)
523{
524 (*this) %= r._bz_asVecExpr();
525 return *this;
526}
527
528template<class P_numtype, int N_length>
529inline TinyVector<P_numtype, N_length>&
530TinyVector<P_numtype, N_length>::operator^=(Range r)
531{
532 (*this) ^= r._bz_asVecExpr();
533 return *this;
534}
535
536template<class P_numtype, int N_length>
537inline TinyVector<P_numtype, N_length>&
538TinyVector<P_numtype, N_length>::operator&=(Range r)
539{
540 (*this) &= r._bz_asVecExpr();
541 return *this;
542}
543
544template<class P_numtype, int N_length>
545inline TinyVector<P_numtype, N_length>&
546TinyVector<P_numtype, N_length>::operator|=(Range r)
547{
548 (*this) |= r._bz_asVecExpr();
549 return *this;
550}
551
552template<class P_numtype, int N_length>
553inline TinyVector<P_numtype, N_length>&
554TinyVector<P_numtype, N_length>::operator<<=(Range r)
555{
556 (*this) <<= r._bz_asVecExpr();
557 return *this;
558}
559
560template<class P_numtype, int N_length>
561inline TinyVector<P_numtype, N_length>&
562TinyVector<P_numtype, N_length>::operator>>=(Range r)
563{
564 (*this) >>= r._bz_asVecExpr();
565 return *this;
566}
567
568/*****************************************************************************
569 * Assignment operators with VectorPick operand
570 */
571
572template<class P_numtype, int N_length> template<class P_numtype2>
573inline TinyVector<P_numtype, N_length>&
574TinyVector<P_numtype, N_length>::operator=(const VectorPick<P_numtype2>& x)
575{
576 (*this) = x._bz_asVecExpr();
577 return *this;
578}
579
580template<class P_numtype, int N_length> template<class P_numtype2>
581inline TinyVector<P_numtype, N_length>&
582TinyVector<P_numtype, N_length>::operator+=(const VectorPick<P_numtype2>& x)
583{
584 (*this) += x._bz_asVecExpr();
585 return *this;
586}
587
588template<class P_numtype, int N_length> template<class P_numtype2>
589inline TinyVector<P_numtype, N_length>&
590TinyVector<P_numtype, N_length>::operator-=(const VectorPick<P_numtype2>& x)
591{
592 (*this) -= x._bz_asVecExpr();
593 return *this;
594}
595
596template<class P_numtype, int N_length> template<class P_numtype2>
597inline TinyVector<P_numtype, N_length>&
598TinyVector<P_numtype, N_length>::operator*=(const VectorPick<P_numtype2>& x)
599{
600 (*this) *= x._bz_asVecExpr();
601 return *this;
602}
603
604template<class P_numtype, int N_length> template<class P_numtype2>
605inline TinyVector<P_numtype, N_length>&
606TinyVector<P_numtype, N_length>::operator/=(const VectorPick<P_numtype2>& x)
607{
608 (*this) /= x._bz_asVecExpr();
609 return *this;
610}
611
612template<class P_numtype, int N_length> template<class P_numtype2>
613inline TinyVector<P_numtype, N_length>&
614TinyVector<P_numtype, N_length>::operator%=(const VectorPick<P_numtype2>& x)
615{
616 (*this) %= x._bz_asVecExpr();
617 return *this;
618}
619
620template<class P_numtype, int N_length> template<class P_numtype2>
621inline TinyVector<P_numtype, N_length>&
622TinyVector<P_numtype, N_length>::operator^=(const VectorPick<P_numtype2>& x)
623{
624 (*this) ^= x._bz_asVecExpr();
625 return *this;
626}
627
628template<class P_numtype, int N_length> template<class P_numtype2>
629inline TinyVector<P_numtype, N_length>&
630TinyVector<P_numtype, N_length>::operator&=(const VectorPick<P_numtype2>& x)
631{
632 (*this) &= x._bz_asVecExpr();
633 return *this;
634}
635
636template<class P_numtype, int N_length> template<class P_numtype2>
637inline TinyVector<P_numtype, N_length>&
638TinyVector<P_numtype, N_length>::operator|=(const VectorPick<P_numtype2>& x)
639{
640 (*this) |= x._bz_asVecExpr();
641 return *this;
642}
643
644template<class P_numtype, int N_length> template<class P_numtype2>
645inline TinyVector<P_numtype, N_length>&
646TinyVector<P_numtype, N_length>::operator>>=(const VectorPick<P_numtype2>& x)
647{
648 (*this) <<= x._bz_asVecExpr();
649 return *this;
650}
651
652BZ_NAMESPACE_END
653
654#endif // BZ_TINYVEC_CC
Note: See TracBrowser for help on using the repository browser.