source: Sophya/trunk/SophyaExt/Blitz/blitz/tinyvec.h@ 3123

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

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

File size: 12.8 KB
Line 
1/***************************************************************************
2 * blitz/tinyvec.h Declaration of the TinyVector<T, N> class
3 *
4 * $Id: tinyvec.h,v 1.1.1.1 1999-04-09 17:59:01 ansari Exp $
5 *
6 * Copyright (C) 1997,1998 Todd Veldhuizen <tveldhui@seurat.uwaterloo.ca>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * Suggestions: blitz-suggest@cybervision.com
19 * Bugs: blitz-bugs@cybervision.com
20 *
21 * For more information, please see the Blitz++ Home Page:
22 * http://seurat.uwaterloo.ca/blitz/
23 *
24 ***************************************************************************
25 * $Log: not supported by cvs2svn $
26 * Revision 1.2 1998/03/14 00:04:47 tveldhui
27 * 0.2-alpha-05
28 *
29 * Revision 1.1 1997/07/16 14:51:20 tveldhui
30 * Update: Alpha release 0.2 (Arrays)
31 *
32 */
33
34#ifndef BZ_TINYVEC_H
35#define BZ_TINYVEC_H
36
37#ifndef BZ_BLITZ_H
38 #include <blitz/blitz.h>
39#endif
40
41#ifndef BZ_RANGE_H
42 #include <blitz/range.h>
43#endif
44
45#ifndef BZ_LISTINIT_H
46 #include <blitz/listinit.h>
47#endif
48
49#include <blitz/tiny.h>
50
51BZ_NAMESPACE(blitz)
52
53/*****************************************************************************
54 * Forward declarations
55 */
56
57template<class P_numtype, int N_length, int N_stride BZ_TEMPLATE_DEFAULT(1) >
58class TinyVectorIter;
59
60template<class P_numtype, int N_length, int N_stride BZ_TEMPLATE_DEFAULT(1) >
61class TinyVectorIterConst;
62
63template<class P_numtype>
64class Vector;
65
66template<class P_expr>
67class _bz_VecExpr;
68
69template<class P_distribution>
70class Random;
71
72template<class P_numtype>
73class VectorPick;
74
75template<class T_numtype1, class T_numtype2, int N_rows, int N_columns,
76 int N_vecStride>
77class _bz_matrixVectorProduct;
78
79
80
81/*****************************************************************************
82 * Declaration of class TinyVector
83 */
84
85template<class P_numtype, int N_length>
86class TinyVector {
87
88public:
89 //////////////////////////////////////////////
90 // Public Types
91 //////////////////////////////////////////////
92
93 typedef P_numtype T_numtype;
94 typedef TinyVector<T_numtype,N_length> T_vector;
95 typedef TinyVectorIter<T_numtype,N_length,1> T_iterator;
96 typedef TinyVectorIterConst<T_numtype,N_length,1> T_constIterator;
97 enum { numElements = N_length };
98
99 TinyVector()
100 { }
101
102 ~TinyVector()
103 { }
104
105 inline TinyVector(const TinyVector<P_numtype,N_length>& x);
106
107 inline TinyVector(T_numtype initValue);
108
109 TinyVector(T_numtype x0, T_numtype x1)
110 {
111 data_[0] = x0;
112 data_[1] = x1;
113 }
114
115 TinyVector(T_numtype x0, T_numtype x1, T_numtype x2)
116 {
117 data_[0] = x0;
118 data_[1] = x1;
119 data_[2] = x2;
120 }
121
122 TinyVector(T_numtype x0, T_numtype x1, T_numtype x2,
123 T_numtype x3)
124 {
125 data_[0] = x0;
126 data_[1] = x1;
127 data_[2] = x2;
128 data_[3] = x3;
129 }
130
131 TinyVector(T_numtype x0, T_numtype x1, T_numtype x2,
132 T_numtype x3, T_numtype x4)
133 {
134 data_[0] = x0;
135 data_[1] = x1;
136 data_[2] = x2;
137 data_[3] = x3;
138 data_[4] = x4;
139 }
140
141 TinyVector(T_numtype x0, T_numtype x1, T_numtype x2,
142 T_numtype x3, T_numtype x4, T_numtype x5)
143 {
144 data_[0] = x0;
145 data_[1] = x1;
146 data_[2] = x2;
147 data_[3] = x3;
148 data_[4] = x4;
149 data_[5] = x5;
150 }
151
152 TinyVector(T_numtype x0, T_numtype x1, T_numtype x2,
153 T_numtype x3, T_numtype x4, T_numtype x5, T_numtype x6)
154 {
155 data_[0] = x0;
156 data_[1] = x1;
157 data_[2] = x2;
158 data_[3] = x3;
159 data_[4] = x4;
160 data_[5] = x5;
161 data_[6] = x6;
162 }
163
164 TinyVector(T_numtype x0, T_numtype x1, T_numtype x2,
165 T_numtype x3, T_numtype x4, T_numtype x5, T_numtype x6,
166 T_numtype x7)
167 {
168 data_[0] = x0;
169 data_[1] = x1;
170 data_[2] = x2;
171 data_[3] = x3;
172 data_[4] = x4;
173 data_[5] = x5;
174 data_[6] = x6;
175 data_[7] = x7;
176 }
177
178 TinyVector(T_numtype x0, T_numtype x1, T_numtype x2,
179 T_numtype x3, T_numtype x4, T_numtype x5, T_numtype x6,
180 T_numtype x7, T_numtype x8)
181 {
182 data_[0] = x0;
183 data_[1] = x1;
184 data_[2] = x2;
185 data_[3] = x3;
186 data_[4] = x4;
187 data_[5] = x5;
188 data_[6] = x6;
189 data_[7] = x7;
190 data_[8] = x8;
191 }
192
193 TinyVector(T_numtype x0, T_numtype x1, T_numtype x2,
194 T_numtype x3, T_numtype x4, T_numtype x5, T_numtype x6,
195 T_numtype x7, T_numtype x8, T_numtype x9)
196 {
197 data_[0] = x0;
198 data_[1] = x1;
199 data_[2] = x2;
200 data_[3] = x3;
201 data_[4] = x4;
202 data_[5] = x5;
203 data_[6] = x6;
204 data_[7] = x7;
205 data_[8] = x8;
206 data_[9] = x9;
207 }
208
209 TinyVector(T_numtype x0, T_numtype x1, T_numtype x2,
210 T_numtype x3, T_numtype x4, T_numtype x5, T_numtype x6,
211 T_numtype x7, T_numtype x8, T_numtype x9, T_numtype x10)
212 {
213 data_[0] = x0;
214 data_[1] = x1;
215 data_[2] = x2;
216 data_[3] = x3;
217 data_[4] = x4;
218 data_[5] = x5;
219 data_[6] = x6;
220 data_[7] = x7;
221 data_[8] = x8;
222 data_[9] = x9;
223 data_[10] = x10;
224 }
225
226 T_iterator begin()
227 { return T_iterator(*this); }
228
229 T_constIterator begin() const
230 { return T_constIterator(*this); }
231
232 // T_iterator end();
233 // T_constIterator end() const;
234
235 T_numtype * _bz_restrict data()
236 { return data_; }
237
238 const T_numtype * _bz_restrict data() const
239 { return data_; }
240
241 T_numtype * _bz_restrict dataFirst()
242 { return data_; }
243
244 const T_numtype * _bz_restrict dataFirst() const
245 { return data_; }
246
247 unsigned length() const
248 { return N_length; }
249
250 /////////////////////////////////////////////
251 // Library-internal member functions
252 // These are undocumented and may change or
253 // disappear in future releases.
254 /////////////////////////////////////////////
255
256 unsigned _bz_suggestLength() const
257 { return N_length; }
258
259 _bz_bool _bz_hasFastAccess() const
260 { return _bz_true; }
261
262 T_numtype& _bz_restrict _bz_fastAccess(unsigned i)
263 { return data_[i]; }
264
265 T_numtype _bz_fastAccess(unsigned i) const
266 { return data_[i]; }
267
268 template<class P_expr, class P_updater>
269 void _bz_assign(P_expr, P_updater);
270
271 _bz_VecExpr<T_constIterator> _bz_asVecExpr() const
272 { return _bz_VecExpr<T_constIterator>(begin()); }
273
274 //////////////////////////////////////////////
275 // Subscripting operators
276 //////////////////////////////////////////////
277
278 int lengthCheck(unsigned i) const
279 {
280 BZPRECHECK(i < N_length,
281 "TinyVector<" << BZ_DEBUG_TEMPLATE_AS_STRING_LITERAL(T_numtype)
282 << "," << N_length << "> index out of bounds: " << i);
283 return 1;
284 }
285
286 T_numtype operator()(unsigned i) const
287 {
288 BZPRECONDITION(lengthCheck(i));
289 return data_[i];
290 }
291
292 T_numtype& _bz_restrict operator()(unsigned i)
293 {
294 BZPRECONDITION(lengthCheck(i));
295 return data_[i];
296 }
297
298 T_numtype operator[](unsigned i) const
299 {
300 BZPRECONDITION(lengthCheck(i));
301 return data_[i];
302 }
303
304 T_numtype& _bz_restrict operator[](unsigned i)
305 {
306 BZPRECONDITION(lengthCheck(i));
307 return data_[i];
308 }
309
310 //////////////////////////////////////////////
311 // Assignment operators
312 //////////////////////////////////////////////
313
314 // Scalar operand
315 ListInitializationSwitch<T_vector> operator=(T_numtype x)
316 {
317 return ListInitializationSwitch<T_vector>(*this, x);
318 }
319
320 T_vector& initialize(T_numtype);
321 T_vector& operator+=(T_numtype);
322 T_vector& operator-=(T_numtype);
323 T_vector& operator*=(T_numtype);
324 T_vector& operator/=(T_numtype);
325 T_vector& operator%=(T_numtype);
326 T_vector& operator^=(T_numtype);
327 T_vector& operator&=(T_numtype);
328 T_vector& operator|=(T_numtype);
329 T_vector& operator>>=(int);
330 T_vector& operator<<=(int);
331
332 template<class P_numtype2>
333 T_vector& operator=(const TinyVector<P_numtype2, N_length> &);
334 template<class P_numtype2>
335 T_vector& operator+=(const TinyVector<P_numtype2, N_length> &);
336 template<class P_numtype2>
337 T_vector& operator-=(const TinyVector<P_numtype2, N_length> &);
338 template<class P_numtype2>
339 T_vector& operator*=(const TinyVector<P_numtype2, N_length> &);
340 template<class P_numtype2>
341 T_vector& operator/=(const TinyVector<P_numtype2, N_length> &);
342 template<class P_numtype2>
343 T_vector& operator%=(const TinyVector<P_numtype2, N_length> &);
344 template<class P_numtype2>
345 T_vector& operator^=(const TinyVector<P_numtype2, N_length> &);
346 template<class P_numtype2>
347 T_vector& operator&=(const TinyVector<P_numtype2, N_length> &);
348 template<class P_numtype2>
349 T_vector& operator|=(const TinyVector<P_numtype2, N_length> &);
350 template<class P_numtype2>
351 T_vector& operator>>=(const TinyVector<P_numtype2, N_length> &);
352 template<class P_numtype2>
353 T_vector& operator<<=(const TinyVector<P_numtype2, N_length> &);
354
355 template<class P_numtype2> T_vector& operator=(const Vector<P_numtype2> &);
356 template<class P_numtype2> T_vector& operator+=(const Vector<P_numtype2> &);
357 template<class P_numtype2> T_vector& operator-=(const Vector<P_numtype2> &);
358 template<class P_numtype2> T_vector& operator*=(const Vector<P_numtype2> &);
359 template<class P_numtype2> T_vector& operator/=(const Vector<P_numtype2> &);
360 template<class P_numtype2> T_vector& operator%=(const Vector<P_numtype2> &);
361 template<class P_numtype2> T_vector& operator^=(const Vector<P_numtype2> &);
362 template<class P_numtype2> T_vector& operator&=(const Vector<P_numtype2> &);
363 template<class P_numtype2> T_vector& operator|=(const Vector<P_numtype2> &);
364 template<class P_numtype2> T_vector& operator>>=(const Vector<P_numtype2> &);
365 template<class P_numtype2> T_vector& operator<<=(const Vector<P_numtype2> &);
366
367 // Vector expression operand
368 template<class P_expr> T_vector& operator=(_bz_VecExpr<P_expr>);
369 template<class P_expr> T_vector& operator+=(_bz_VecExpr<P_expr>);
370 template<class P_expr> T_vector& operator-=(_bz_VecExpr<P_expr>);
371 template<class P_expr> T_vector& operator*=(_bz_VecExpr<P_expr>);
372 template<class P_expr> T_vector& operator/=(_bz_VecExpr<P_expr>);
373 template<class P_expr> T_vector& operator%=(_bz_VecExpr<P_expr>);
374 template<class P_expr> T_vector& operator^=(_bz_VecExpr<P_expr>);
375 template<class P_expr> T_vector& operator&=(_bz_VecExpr<P_expr>);
376 template<class P_expr> T_vector& operator|=(_bz_VecExpr<P_expr>);
377 template<class P_expr> T_vector& operator>>=(_bz_VecExpr<P_expr>);
378 template<class P_expr> T_vector& operator<<=(_bz_VecExpr<P_expr>);
379
380 // VectorPick operand
381 template<class P_numtype2>
382 T_vector& operator=(const VectorPick<P_numtype2> &);
383 template<class P_numtype2>
384 T_vector& operator+=(const VectorPick<P_numtype2> &);
385 template<class P_numtype2>
386 T_vector& operator-=(const VectorPick<P_numtype2> &);
387 template<class P_numtype2>
388 T_vector& operator*=(const VectorPick<P_numtype2> &);
389 template<class P_numtype2>
390 T_vector& operator/=(const VectorPick<P_numtype2> &);
391 template<class P_numtype2>
392 T_vector& operator%=(const VectorPick<P_numtype2> &);
393 template<class P_numtype2>
394 T_vector& operator^=(const VectorPick<P_numtype2> &);
395 template<class P_numtype2>
396 T_vector& operator&=(const VectorPick<P_numtype2> &);
397 template<class P_numtype2>
398 T_vector& operator|=(const VectorPick<P_numtype2> &);
399 template<class P_numtype2>
400 T_vector& operator>>=(const VectorPick<P_numtype2> &);
401 template<class P_numtype2>
402 T_vector& operator<<=(const VectorPick<P_numtype2> &);
403
404 // Range operand
405 T_vector& operator=(Range);
406 T_vector& operator+=(Range);
407 T_vector& operator-=(Range);
408 T_vector& operator*=(Range);
409 T_vector& operator/=(Range);
410 T_vector& operator%=(Range);
411 T_vector& operator^=(Range);
412 T_vector& operator&=(Range);
413 T_vector& operator|=(Range);
414 T_vector& operator>>=(Range);
415 T_vector& operator<<=(Range);
416
417 T_numtype* _bz_restrict getInitializationIterator()
418 { return dataFirst(); }
419
420private:
421 T_numtype data_[N_length];
422};
423
424BZ_NAMESPACE_END
425
426#include <blitz/tinyveciter.h> // Iterators
427#include <blitz/tvecglobs.h> // Global functions
428#include <blitz/vector.h> // Expression templates
429#include <blitz/tinyvec.cc> // Member functions
430#include <blitz/tinyvecio.cc> // I/O functions
431
432#endif // BZ_TINYVEC_H
433
Note: See TracBrowser for help on using the repository browser.