[658] | 1 | /***************************************************************************
|
---|
| 2 | * blitz/tinyvec.h Declaration of the TinyVector<T, N> class
|
---|
| 3 | *
|
---|
| 4 | * $Id: tinyvec.h,v 1.1.1.1 1999-11-26 16:37:04 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.1.1.1 1999/04/09 17:59:01 ansari
|
---|
| 27 | * Creation module DPC/Blitz (blitz 0.4) Reza 09/04/99
|
---|
| 28 | *
|
---|
| 29 | * Revision 1.2 1998/03/14 00:04:47 tveldhui
|
---|
| 30 | * 0.2-alpha-05
|
---|
| 31 | *
|
---|
| 32 | * Revision 1.1 1997/07/16 14:51:20 tveldhui
|
---|
| 33 | * Update: Alpha release 0.2 (Arrays)
|
---|
| 34 | *
|
---|
| 35 | */
|
---|
| 36 |
|
---|
| 37 | #ifndef BZ_TINYVEC_H
|
---|
| 38 | #define BZ_TINYVEC_H
|
---|
| 39 |
|
---|
| 40 | #ifndef BZ_BLITZ_H
|
---|
| 41 | #include <blitz/blitz.h>
|
---|
| 42 | #endif
|
---|
| 43 |
|
---|
| 44 | #ifndef BZ_RANGE_H
|
---|
| 45 | #include <blitz/range.h>
|
---|
| 46 | #endif
|
---|
| 47 |
|
---|
| 48 | #ifndef BZ_LISTINIT_H
|
---|
| 49 | #include <blitz/listinit.h>
|
---|
| 50 | #endif
|
---|
| 51 |
|
---|
| 52 | #include <blitz/tiny.h>
|
---|
| 53 |
|
---|
| 54 | BZ_NAMESPACE(blitz)
|
---|
| 55 |
|
---|
| 56 | /*****************************************************************************
|
---|
| 57 | * Forward declarations
|
---|
| 58 | */
|
---|
| 59 |
|
---|
| 60 | template<class P_numtype, int N_length, int N_stride BZ_TEMPLATE_DEFAULT(1) >
|
---|
| 61 | class TinyVectorIter;
|
---|
| 62 |
|
---|
| 63 | template<class P_numtype, int N_length, int N_stride BZ_TEMPLATE_DEFAULT(1) >
|
---|
| 64 | class TinyVectorIterConst;
|
---|
| 65 |
|
---|
| 66 | template<class P_numtype>
|
---|
| 67 | class Vector;
|
---|
| 68 |
|
---|
| 69 | template<class P_expr>
|
---|
| 70 | class _bz_VecExpr;
|
---|
| 71 |
|
---|
| 72 | template<class P_distribution>
|
---|
| 73 | class Random;
|
---|
| 74 |
|
---|
| 75 | template<class P_numtype>
|
---|
| 76 | class VectorPick;
|
---|
| 77 |
|
---|
| 78 | template<class T_numtype1, class T_numtype2, int N_rows, int N_columns,
|
---|
| 79 | int N_vecStride>
|
---|
| 80 | class _bz_matrixVectorProduct;
|
---|
| 81 |
|
---|
| 82 |
|
---|
| 83 |
|
---|
| 84 | /*****************************************************************************
|
---|
| 85 | * Declaration of class TinyVector
|
---|
| 86 | */
|
---|
| 87 |
|
---|
| 88 | template<class P_numtype, int N_length>
|
---|
| 89 | class TinyVector {
|
---|
| 90 |
|
---|
| 91 | public:
|
---|
| 92 | //////////////////////////////////////////////
|
---|
| 93 | // Public Types
|
---|
| 94 | //////////////////////////////////////////////
|
---|
| 95 |
|
---|
| 96 | typedef P_numtype T_numtype;
|
---|
| 97 | typedef TinyVector<T_numtype,N_length> T_vector;
|
---|
| 98 | typedef TinyVectorIter<T_numtype,N_length,1> T_iterator;
|
---|
| 99 | typedef TinyVectorIterConst<T_numtype,N_length,1> T_constIterator;
|
---|
| 100 | enum { numElements = N_length };
|
---|
| 101 |
|
---|
| 102 | TinyVector()
|
---|
| 103 | { }
|
---|
| 104 |
|
---|
| 105 | ~TinyVector()
|
---|
| 106 | { }
|
---|
| 107 |
|
---|
| 108 | inline TinyVector(const TinyVector<P_numtype,N_length>& x);
|
---|
| 109 |
|
---|
| 110 | inline TinyVector(T_numtype initValue);
|
---|
| 111 |
|
---|
| 112 | TinyVector(T_numtype x0, T_numtype x1)
|
---|
| 113 | {
|
---|
| 114 | data_[0] = x0;
|
---|
| 115 | data_[1] = x1;
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | TinyVector(T_numtype x0, T_numtype x1, T_numtype x2)
|
---|
| 119 | {
|
---|
| 120 | data_[0] = x0;
|
---|
| 121 | data_[1] = x1;
|
---|
| 122 | data_[2] = x2;
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 | TinyVector(T_numtype x0, T_numtype x1, T_numtype x2,
|
---|
| 126 | T_numtype x3)
|
---|
| 127 | {
|
---|
| 128 | data_[0] = x0;
|
---|
| 129 | data_[1] = x1;
|
---|
| 130 | data_[2] = x2;
|
---|
| 131 | data_[3] = x3;
|
---|
| 132 | }
|
---|
| 133 |
|
---|
| 134 | TinyVector(T_numtype x0, T_numtype x1, T_numtype x2,
|
---|
| 135 | T_numtype x3, T_numtype x4)
|
---|
| 136 | {
|
---|
| 137 | data_[0] = x0;
|
---|
| 138 | data_[1] = x1;
|
---|
| 139 | data_[2] = x2;
|
---|
| 140 | data_[3] = x3;
|
---|
| 141 | data_[4] = x4;
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | TinyVector(T_numtype x0, T_numtype x1, T_numtype x2,
|
---|
| 145 | T_numtype x3, T_numtype x4, T_numtype x5)
|
---|
| 146 | {
|
---|
| 147 | data_[0] = x0;
|
---|
| 148 | data_[1] = x1;
|
---|
| 149 | data_[2] = x2;
|
---|
| 150 | data_[3] = x3;
|
---|
| 151 | data_[4] = x4;
|
---|
| 152 | data_[5] = x5;
|
---|
| 153 | }
|
---|
| 154 |
|
---|
| 155 | TinyVector(T_numtype x0, T_numtype x1, T_numtype x2,
|
---|
| 156 | T_numtype x3, T_numtype x4, T_numtype x5, T_numtype x6)
|
---|
| 157 | {
|
---|
| 158 | data_[0] = x0;
|
---|
| 159 | data_[1] = x1;
|
---|
| 160 | data_[2] = x2;
|
---|
| 161 | data_[3] = x3;
|
---|
| 162 | data_[4] = x4;
|
---|
| 163 | data_[5] = x5;
|
---|
| 164 | data_[6] = x6;
|
---|
| 165 | }
|
---|
| 166 |
|
---|
| 167 | TinyVector(T_numtype x0, T_numtype x1, T_numtype x2,
|
---|
| 168 | T_numtype x3, T_numtype x4, T_numtype x5, T_numtype x6,
|
---|
| 169 | T_numtype x7)
|
---|
| 170 | {
|
---|
| 171 | data_[0] = x0;
|
---|
| 172 | data_[1] = x1;
|
---|
| 173 | data_[2] = x2;
|
---|
| 174 | data_[3] = x3;
|
---|
| 175 | data_[4] = x4;
|
---|
| 176 | data_[5] = x5;
|
---|
| 177 | data_[6] = x6;
|
---|
| 178 | data_[7] = x7;
|
---|
| 179 | }
|
---|
| 180 |
|
---|
| 181 | TinyVector(T_numtype x0, T_numtype x1, T_numtype x2,
|
---|
| 182 | T_numtype x3, T_numtype x4, T_numtype x5, T_numtype x6,
|
---|
| 183 | T_numtype x7, T_numtype x8)
|
---|
| 184 | {
|
---|
| 185 | data_[0] = x0;
|
---|
| 186 | data_[1] = x1;
|
---|
| 187 | data_[2] = x2;
|
---|
| 188 | data_[3] = x3;
|
---|
| 189 | data_[4] = x4;
|
---|
| 190 | data_[5] = x5;
|
---|
| 191 | data_[6] = x6;
|
---|
| 192 | data_[7] = x7;
|
---|
| 193 | data_[8] = x8;
|
---|
| 194 | }
|
---|
| 195 |
|
---|
| 196 | TinyVector(T_numtype x0, T_numtype x1, T_numtype x2,
|
---|
| 197 | T_numtype x3, T_numtype x4, T_numtype x5, T_numtype x6,
|
---|
| 198 | T_numtype x7, T_numtype x8, T_numtype x9)
|
---|
| 199 | {
|
---|
| 200 | data_[0] = x0;
|
---|
| 201 | data_[1] = x1;
|
---|
| 202 | data_[2] = x2;
|
---|
| 203 | data_[3] = x3;
|
---|
| 204 | data_[4] = x4;
|
---|
| 205 | data_[5] = x5;
|
---|
| 206 | data_[6] = x6;
|
---|
| 207 | data_[7] = x7;
|
---|
| 208 | data_[8] = x8;
|
---|
| 209 | data_[9] = x9;
|
---|
| 210 | }
|
---|
| 211 |
|
---|
| 212 | TinyVector(T_numtype x0, T_numtype x1, T_numtype x2,
|
---|
| 213 | T_numtype x3, T_numtype x4, T_numtype x5, T_numtype x6,
|
---|
| 214 | T_numtype x7, T_numtype x8, T_numtype x9, T_numtype x10)
|
---|
| 215 | {
|
---|
| 216 | data_[0] = x0;
|
---|
| 217 | data_[1] = x1;
|
---|
| 218 | data_[2] = x2;
|
---|
| 219 | data_[3] = x3;
|
---|
| 220 | data_[4] = x4;
|
---|
| 221 | data_[5] = x5;
|
---|
| 222 | data_[6] = x6;
|
---|
| 223 | data_[7] = x7;
|
---|
| 224 | data_[8] = x8;
|
---|
| 225 | data_[9] = x9;
|
---|
| 226 | data_[10] = x10;
|
---|
| 227 | }
|
---|
| 228 |
|
---|
| 229 | T_iterator begin()
|
---|
| 230 | { return T_iterator(*this); }
|
---|
| 231 |
|
---|
| 232 | T_constIterator begin() const
|
---|
| 233 | { return T_constIterator(*this); }
|
---|
| 234 |
|
---|
| 235 | // T_iterator end();
|
---|
| 236 | // T_constIterator end() const;
|
---|
| 237 |
|
---|
| 238 | T_numtype * _bz_restrict data()
|
---|
| 239 | { return data_; }
|
---|
| 240 |
|
---|
| 241 | const T_numtype * _bz_restrict data() const
|
---|
| 242 | { return data_; }
|
---|
| 243 |
|
---|
| 244 | T_numtype * _bz_restrict dataFirst()
|
---|
| 245 | { return data_; }
|
---|
| 246 |
|
---|
| 247 | const T_numtype * _bz_restrict dataFirst() const
|
---|
| 248 | { return data_; }
|
---|
| 249 |
|
---|
| 250 | unsigned length() const
|
---|
| 251 | { return N_length; }
|
---|
| 252 |
|
---|
| 253 | /////////////////////////////////////////////
|
---|
| 254 | // Library-internal member functions
|
---|
| 255 | // These are undocumented and may change or
|
---|
| 256 | // disappear in future releases.
|
---|
| 257 | /////////////////////////////////////////////
|
---|
| 258 |
|
---|
| 259 | unsigned _bz_suggestLength() const
|
---|
| 260 | { return N_length; }
|
---|
| 261 |
|
---|
| 262 | _bz_bool _bz_hasFastAccess() const
|
---|
| 263 | { return _bz_true; }
|
---|
| 264 |
|
---|
| 265 | T_numtype& _bz_restrict _bz_fastAccess(unsigned i)
|
---|
| 266 | { return data_[i]; }
|
---|
| 267 |
|
---|
| 268 | T_numtype _bz_fastAccess(unsigned i) const
|
---|
| 269 | { return data_[i]; }
|
---|
| 270 |
|
---|
| 271 | template<class P_expr, class P_updater>
|
---|
| 272 | void _bz_assign(P_expr, P_updater);
|
---|
| 273 |
|
---|
| 274 | _bz_VecExpr<T_constIterator> _bz_asVecExpr() const
|
---|
| 275 | { return _bz_VecExpr<T_constIterator>(begin()); }
|
---|
| 276 |
|
---|
| 277 | //////////////////////////////////////////////
|
---|
| 278 | // Subscripting operators
|
---|
| 279 | //////////////////////////////////////////////
|
---|
| 280 |
|
---|
| 281 | int lengthCheck(unsigned i) const
|
---|
| 282 | {
|
---|
| 283 | BZPRECHECK(i < N_length,
|
---|
| 284 | "TinyVector<" << BZ_DEBUG_TEMPLATE_AS_STRING_LITERAL(T_numtype)
|
---|
| 285 | << "," << N_length << "> index out of bounds: " << i);
|
---|
| 286 | return 1;
|
---|
| 287 | }
|
---|
| 288 |
|
---|
| 289 | T_numtype operator()(unsigned i) const
|
---|
| 290 | {
|
---|
| 291 | BZPRECONDITION(lengthCheck(i));
|
---|
| 292 | return data_[i];
|
---|
| 293 | }
|
---|
| 294 |
|
---|
| 295 | T_numtype& _bz_restrict operator()(unsigned i)
|
---|
| 296 | {
|
---|
| 297 | BZPRECONDITION(lengthCheck(i));
|
---|
| 298 | return data_[i];
|
---|
| 299 | }
|
---|
| 300 |
|
---|
| 301 | T_numtype operator[](unsigned i) const
|
---|
| 302 | {
|
---|
| 303 | BZPRECONDITION(lengthCheck(i));
|
---|
| 304 | return data_[i];
|
---|
| 305 | }
|
---|
| 306 |
|
---|
| 307 | T_numtype& _bz_restrict operator[](unsigned i)
|
---|
| 308 | {
|
---|
| 309 | BZPRECONDITION(lengthCheck(i));
|
---|
| 310 | return data_[i];
|
---|
| 311 | }
|
---|
| 312 |
|
---|
| 313 | //////////////////////////////////////////////
|
---|
| 314 | // Assignment operators
|
---|
| 315 | //////////////////////////////////////////////
|
---|
| 316 |
|
---|
| 317 | // Scalar operand
|
---|
| 318 | ListInitializationSwitch<T_vector> operator=(T_numtype x)
|
---|
| 319 | {
|
---|
| 320 | return ListInitializationSwitch<T_vector>(*this, x);
|
---|
| 321 | }
|
---|
| 322 |
|
---|
| 323 | T_vector& initialize(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^=(T_numtype);
|
---|
| 330 | T_vector& operator&=(T_numtype);
|
---|
| 331 | T_vector& operator|=(T_numtype);
|
---|
| 332 | T_vector& operator>>=(int);
|
---|
| 333 | T_vector& operator<<=(int);
|
---|
| 334 |
|
---|
| 335 | template<class P_numtype2>
|
---|
| 336 | T_vector& operator=(const TinyVector<P_numtype2, N_length> &);
|
---|
| 337 | template<class P_numtype2>
|
---|
| 338 | T_vector& operator+=(const TinyVector<P_numtype2, N_length> &);
|
---|
| 339 | template<class P_numtype2>
|
---|
| 340 | T_vector& operator-=(const TinyVector<P_numtype2, N_length> &);
|
---|
| 341 | template<class P_numtype2>
|
---|
| 342 | T_vector& operator*=(const TinyVector<P_numtype2, N_length> &);
|
---|
| 343 | template<class P_numtype2>
|
---|
| 344 | T_vector& operator/=(const TinyVector<P_numtype2, N_length> &);
|
---|
| 345 | template<class P_numtype2>
|
---|
| 346 | T_vector& operator%=(const TinyVector<P_numtype2, N_length> &);
|
---|
| 347 | template<class P_numtype2>
|
---|
| 348 | T_vector& operator^=(const TinyVector<P_numtype2, N_length> &);
|
---|
| 349 | template<class P_numtype2>
|
---|
| 350 | T_vector& operator&=(const TinyVector<P_numtype2, N_length> &);
|
---|
| 351 | template<class P_numtype2>
|
---|
| 352 | T_vector& operator|=(const TinyVector<P_numtype2, N_length> &);
|
---|
| 353 | template<class P_numtype2>
|
---|
| 354 | T_vector& operator>>=(const TinyVector<P_numtype2, N_length> &);
|
---|
| 355 | template<class P_numtype2>
|
---|
| 356 | T_vector& operator<<=(const TinyVector<P_numtype2, N_length> &);
|
---|
| 357 |
|
---|
| 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 | template<class P_numtype2> T_vector& operator|=(const Vector<P_numtype2> &);
|
---|
| 367 | template<class P_numtype2> T_vector& operator>>=(const Vector<P_numtype2> &);
|
---|
| 368 | template<class P_numtype2> T_vector& operator<<=(const Vector<P_numtype2> &);
|
---|
| 369 |
|
---|
| 370 | // Vector expression operand
|
---|
| 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 | template<class P_expr> T_vector& operator|=(_bz_VecExpr<P_expr>);
|
---|
| 380 | template<class P_expr> T_vector& operator>>=(_bz_VecExpr<P_expr>);
|
---|
| 381 | template<class P_expr> T_vector& operator<<=(_bz_VecExpr<P_expr>);
|
---|
| 382 |
|
---|
| 383 | // VectorPick operand
|
---|
| 384 | template<class P_numtype2>
|
---|
| 385 | T_vector& operator=(const VectorPick<P_numtype2> &);
|
---|
| 386 | template<class P_numtype2>
|
---|
| 387 | T_vector& operator+=(const VectorPick<P_numtype2> &);
|
---|
| 388 | template<class P_numtype2>
|
---|
| 389 | T_vector& operator-=(const VectorPick<P_numtype2> &);
|
---|
| 390 | template<class P_numtype2>
|
---|
| 391 | T_vector& operator*=(const VectorPick<P_numtype2> &);
|
---|
| 392 | template<class P_numtype2>
|
---|
| 393 | T_vector& operator/=(const VectorPick<P_numtype2> &);
|
---|
| 394 | template<class P_numtype2>
|
---|
| 395 | T_vector& operator%=(const VectorPick<P_numtype2> &);
|
---|
| 396 | template<class P_numtype2>
|
---|
| 397 | T_vector& operator^=(const VectorPick<P_numtype2> &);
|
---|
| 398 | template<class P_numtype2>
|
---|
| 399 | T_vector& operator&=(const VectorPick<P_numtype2> &);
|
---|
| 400 | template<class P_numtype2>
|
---|
| 401 | T_vector& operator|=(const VectorPick<P_numtype2> &);
|
---|
| 402 | template<class P_numtype2>
|
---|
| 403 | T_vector& operator>>=(const VectorPick<P_numtype2> &);
|
---|
| 404 | template<class P_numtype2>
|
---|
| 405 | T_vector& operator<<=(const VectorPick<P_numtype2> &);
|
---|
| 406 |
|
---|
| 407 | // Range operand
|
---|
| 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 | T_vector& operator|=(Range);
|
---|
| 417 | T_vector& operator>>=(Range);
|
---|
| 418 | T_vector& operator<<=(Range);
|
---|
| 419 |
|
---|
| 420 | T_numtype* _bz_restrict getInitializationIterator()
|
---|
| 421 | { return dataFirst(); }
|
---|
| 422 |
|
---|
| 423 | private:
|
---|
| 424 | T_numtype data_[N_length];
|
---|
| 425 | };
|
---|
| 426 |
|
---|
| 427 | BZ_NAMESPACE_END
|
---|
| 428 |
|
---|
| 429 | #include <blitz/tinyveciter.h> // Iterators
|
---|
| 430 | #include <blitz/tvecglobs.h> // Global functions
|
---|
| 431 | #include <blitz/vector.h> // Expression templates
|
---|
| 432 | #include <blitz/tinyvec.cc> // Member functions
|
---|
| 433 | #include <blitz/tinyvecio.cc> // I/O functions
|
---|
| 434 |
|
---|
| 435 | #endif // BZ_TINYVEC_H
|
---|
| 436 |
|
---|