00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef BZ_TINYVEC_H
00028 #define BZ_TINYVEC_H
00029
00030 #include <blitz/blitz.h>
00031 #include <blitz/range.h>
00032 #include <blitz/listinit.h>
00033 #include <blitz/tiny.h>
00034
00035 BZ_NAMESPACE(blitz)
00036
00037
00038
00039
00040
00041 template<typename P_numtype, int N_length, int N_stride BZ_TEMPLATE_DEFAULT(1) >
00042 class TinyVectorIter;
00043
00044 template<typename P_numtype, int N_length, int N_stride BZ_TEMPLATE_DEFAULT(1) >
00045 class TinyVectorIterConst;
00046
00047 template<typename P_numtype>
00048 class Vector;
00049
00050 template<typename P_expr>
00051 class _bz_VecExpr;
00052
00053 template<typename P_distribution>
00054 class Random;
00055
00056 template<typename P_numtype>
00057 class VectorPick;
00058
00059 template<typename T_numtype1, typename T_numtype2, int N_rows, int N_columns,
00060 int N_vecStride>
00061 class _bz_matrixVectorProduct;
00062
00063
00064
00065
00066
00067
00068
00069 template<typename P_numtype, int N_length>
00070 class TinyVector {
00071 public:
00072
00074
00076
00077 typedef P_numtype T_numtype;
00078 typedef TinyVector<T_numtype,N_length> T_vector;
00079 typedef TinyVectorIter<T_numtype,N_length,1> T_iterator;
00080 typedef TinyVectorIterConst<T_numtype,N_length,1> T_constIterator;
00081 typedef T_numtype* iterator;
00082 typedef const T_numtype* const_iterator;
00083 enum { numElements = N_length };
00084
00085 TinyVector() { }
00086 ~TinyVector() { }
00087
00088 inline TinyVector(const TinyVector<T_numtype,N_length>& x);
00089
00090 template <typename T_numtype2>
00091 inline TinyVector(const TinyVector<T_numtype2,N_length>& x);
00092
00093 inline TinyVector(const T_numtype initValue);
00094
00095 inline TinyVector(const T_numtype x[]) {
00096 memcpy(data_,x,N_length*sizeof(T_numtype));
00097 }
00098
00099 TinyVector(T_numtype x0, T_numtype x1)
00100 {
00101 data_[0] = x0;
00102 data_[1] = x1;
00103 }
00104
00105 TinyVector(T_numtype x0, T_numtype x1, T_numtype x2)
00106 {
00107 data_[0] = x0;
00108 data_[1] = x1;
00109 data_[2] = x2;
00110 }
00111
00112 TinyVector(T_numtype x0, T_numtype x1, T_numtype x2,
00113 T_numtype x3)
00114 {
00115 data_[0] = x0;
00116 data_[1] = x1;
00117 data_[2] = x2;
00118 data_[3] = x3;
00119 }
00120
00121 TinyVector(T_numtype x0, T_numtype x1, T_numtype x2,
00122 T_numtype x3, T_numtype x4)
00123 {
00124 data_[0] = x0;
00125 data_[1] = x1;
00126 data_[2] = x2;
00127 data_[3] = x3;
00128 data_[4] = x4;
00129 }
00130
00131 TinyVector(T_numtype x0, T_numtype x1, T_numtype x2,
00132 T_numtype x3, T_numtype x4, T_numtype x5)
00133 {
00134 data_[0] = x0;
00135 data_[1] = x1;
00136 data_[2] = x2;
00137 data_[3] = x3;
00138 data_[4] = x4;
00139 data_[5] = x5;
00140 }
00141
00142 TinyVector(T_numtype x0, T_numtype x1, T_numtype x2,
00143 T_numtype x3, T_numtype x4, T_numtype x5, T_numtype x6)
00144 {
00145 data_[0] = x0;
00146 data_[1] = x1;
00147 data_[2] = x2;
00148 data_[3] = x3;
00149 data_[4] = x4;
00150 data_[5] = x5;
00151 data_[6] = x6;
00152 }
00153
00154 TinyVector(T_numtype x0, T_numtype x1, T_numtype x2,
00155 T_numtype x3, T_numtype x4, T_numtype x5, T_numtype x6,
00156 T_numtype x7)
00157 {
00158 data_[0] = x0;
00159 data_[1] = x1;
00160 data_[2] = x2;
00161 data_[3] = x3;
00162 data_[4] = x4;
00163 data_[5] = x5;
00164 data_[6] = x6;
00165 data_[7] = x7;
00166 }
00167
00168 TinyVector(T_numtype x0, T_numtype x1, T_numtype x2,
00169 T_numtype x3, T_numtype x4, T_numtype x5, T_numtype x6,
00170 T_numtype x7, T_numtype x8)
00171 {
00172 data_[0] = x0;
00173 data_[1] = x1;
00174 data_[2] = x2;
00175 data_[3] = x3;
00176 data_[4] = x4;
00177 data_[5] = x5;
00178 data_[6] = x6;
00179 data_[7] = x7;
00180 data_[8] = x8;
00181 }
00182
00183 TinyVector(T_numtype x0, T_numtype x1, T_numtype x2,
00184 T_numtype x3, T_numtype x4, T_numtype x5, T_numtype x6,
00185 T_numtype x7, T_numtype x8, T_numtype x9)
00186 {
00187 data_[0] = x0;
00188 data_[1] = x1;
00189 data_[2] = x2;
00190 data_[3] = x3;
00191 data_[4] = x4;
00192 data_[5] = x5;
00193 data_[6] = x6;
00194 data_[7] = x7;
00195 data_[8] = x8;
00196 data_[9] = x9;
00197 }
00198
00199 TinyVector(T_numtype x0, T_numtype x1, T_numtype x2,
00200 T_numtype x3, T_numtype x4, T_numtype x5, T_numtype x6,
00201 T_numtype x7, T_numtype x8, T_numtype x9, T_numtype x10)
00202 {
00203 data_[0] = x0;
00204 data_[1] = x1;
00205 data_[2] = x2;
00206 data_[3] = x3;
00207 data_[4] = x4;
00208 data_[5] = x5;
00209 data_[6] = x6;
00210 data_[7] = x7;
00211 data_[8] = x8;
00212 data_[9] = x9;
00213 data_[10] = x10;
00214 }
00215
00216
00217 template<typename P_expr>
00218 inline TinyVector(_bz_VecExpr<P_expr> expr);
00219
00220 T_iterator beginFast() { return T_iterator(*this); }
00221 T_constIterator beginFast() const { return T_constIterator(*this); }
00222
00223 iterator begin() { return data_; }
00224 const_iterator begin() const { return data_; }
00225
00226 iterator end() { return data_ + N_length; }
00227 const_iterator end() const { return data_ + N_length; }
00228
00229 T_numtype * restrict data()
00230 { return data_; }
00231
00232 const T_numtype * restrict data() const
00233 { return data_; }
00234
00235 T_numtype * restrict dataFirst()
00236 { return data_; }
00237
00238 const T_numtype * restrict dataFirst() const
00239 { return data_; }
00240
00241 unsigned length() const
00242 { return N_length; }
00243
00245
00246
00247
00249
00250 unsigned _bz_suggestLength() const
00251 { return N_length; }
00252
00253 bool _bz_hasFastAccess() const
00254 { return true; }
00255
00256 T_numtype& restrict _bz_fastAccess(unsigned i)
00257 { return data_[i]; }
00258
00259 T_numtype _bz_fastAccess(unsigned i) const
00260 { return data_[i]; }
00261
00262 template<typename P_expr, typename P_updater>
00263 void _bz_assign(P_expr, P_updater);
00264
00265 _bz_VecExpr<T_constIterator> _bz_asVecExpr() const
00266 { return _bz_VecExpr<T_constIterator>(beginFast()); }
00267
00269
00271
00272 bool lengthCheck(unsigned i) const
00273 {
00274 BZPRECHECK(i < N_length,
00275 "TinyVector<" << BZ_DEBUG_TEMPLATE_AS_STRING_LITERAL(T_numtype)
00276 << "," << N_length << "> index out of bounds: " << i);
00277 return true;
00278 }
00279
00280 const T_numtype& operator()(unsigned i) const
00281 {
00282 BZPRECONDITION(lengthCheck(i));
00283 return data_[i];
00284 }
00285
00286 T_numtype& restrict operator()(unsigned i)
00287 {
00288 BZPRECONDITION(lengthCheck(i));
00289 return data_[i];
00290 }
00291
00292 const T_numtype& operator[](unsigned i) const
00293 {
00294 BZPRECONDITION(lengthCheck(i));
00295 return data_[i];
00296 }
00297
00298 T_numtype& restrict operator[](unsigned i)
00299 {
00300 BZPRECONDITION(lengthCheck(i));
00301 return data_[i];
00302 }
00303
00305
00307
00308
00309 ListInitializationSwitch<T_vector,T_numtype*> operator=(T_numtype x)
00310 {
00311 return ListInitializationSwitch<T_vector,T_numtype*>(*this, x);
00312 }
00313
00314 T_vector& initialize(const T_numtype);
00315 T_vector& operator+=(const T_numtype);
00316 T_vector& operator-=(const T_numtype);
00317 T_vector& operator*=(const T_numtype);
00318 T_vector& operator/=(const T_numtype);
00319 T_vector& operator%=(const T_numtype);
00320 T_vector& operator^=(const T_numtype);
00321 T_vector& operator&=(const T_numtype);
00322 T_vector& operator|=(const T_numtype);
00323 T_vector& operator>>=(const int);
00324 T_vector& operator<<=(const int);
00325
00326 template<typename P_numtype2>
00327 T_vector& operator=(const TinyVector<P_numtype2, N_length> &);
00328 template<typename P_numtype2>
00329 T_vector& operator+=(const TinyVector<P_numtype2, N_length> &);
00330 template<typename P_numtype2>
00331 T_vector& operator-=(const TinyVector<P_numtype2, N_length> &);
00332 template<typename P_numtype2>
00333 T_vector& operator*=(const TinyVector<P_numtype2, N_length> &);
00334 template<typename P_numtype2>
00335 T_vector& operator/=(const TinyVector<P_numtype2, N_length> &);
00336 template<typename P_numtype2>
00337 T_vector& operator%=(const TinyVector<P_numtype2, N_length> &);
00338 template<typename P_numtype2>
00339 T_vector& operator^=(const TinyVector<P_numtype2, N_length> &);
00340 template<typename P_numtype2>
00341 T_vector& operator&=(const TinyVector<P_numtype2, N_length> &);
00342 template<typename P_numtype2>
00343 T_vector& operator|=(const TinyVector<P_numtype2, N_length> &);
00344 template<typename P_numtype2>
00345 T_vector& operator>>=(const TinyVector<P_numtype2, N_length> &);
00346 template<typename P_numtype2>
00347 T_vector& operator<<=(const TinyVector<P_numtype2, N_length> &);
00348
00349 template<typename P_numtype2> T_vector& operator=(const Vector<P_numtype2> &);
00350 template<typename P_numtype2> T_vector& operator+=(const Vector<P_numtype2> &);
00351 template<typename P_numtype2> T_vector& operator-=(const Vector<P_numtype2> &);
00352 template<typename P_numtype2> T_vector& operator*=(const Vector<P_numtype2> &);
00353 template<typename P_numtype2> T_vector& operator/=(const Vector<P_numtype2> &);
00354 template<typename P_numtype2> T_vector& operator%=(const Vector<P_numtype2> &);
00355 template<typename P_numtype2> T_vector& operator^=(const Vector<P_numtype2> &);
00356 template<typename P_numtype2> T_vector& operator&=(const Vector<P_numtype2> &);
00357 template<typename P_numtype2> T_vector& operator|=(const Vector<P_numtype2> &);
00358 template<typename P_numtype2> T_vector& operator>>=(const Vector<P_numtype2> &);
00359 template<typename P_numtype2> T_vector& operator<<=(const Vector<P_numtype2> &);
00360
00361
00362 template<typename P_expr> T_vector& operator=(_bz_VecExpr<P_expr>);
00363 template<typename P_expr> T_vector& operator+=(_bz_VecExpr<P_expr>);
00364 template<typename P_expr> T_vector& operator-=(_bz_VecExpr<P_expr>);
00365 template<typename P_expr> T_vector& operator*=(_bz_VecExpr<P_expr>);
00366 template<typename P_expr> T_vector& operator/=(_bz_VecExpr<P_expr>);
00367 template<typename P_expr> T_vector& operator%=(_bz_VecExpr<P_expr>);
00368 template<typename P_expr> T_vector& operator^=(_bz_VecExpr<P_expr>);
00369 template<typename P_expr> T_vector& operator&=(_bz_VecExpr<P_expr>);
00370 template<typename P_expr> T_vector& operator|=(_bz_VecExpr<P_expr>);
00371 template<typename P_expr> T_vector& operator>>=(_bz_VecExpr<P_expr>);
00372 template<typename P_expr> T_vector& operator<<=(_bz_VecExpr<P_expr>);
00373
00374
00375 template<typename P_numtype2>
00376 T_vector& operator=(const VectorPick<P_numtype2> &);
00377 template<typename P_numtype2>
00378 T_vector& operator+=(const VectorPick<P_numtype2> &);
00379 template<typename P_numtype2>
00380 T_vector& operator-=(const VectorPick<P_numtype2> &);
00381 template<typename P_numtype2>
00382 T_vector& operator*=(const VectorPick<P_numtype2> &);
00383 template<typename P_numtype2>
00384 T_vector& operator/=(const VectorPick<P_numtype2> &);
00385 template<typename P_numtype2>
00386 T_vector& operator%=(const VectorPick<P_numtype2> &);
00387 template<typename P_numtype2>
00388 T_vector& operator^=(const VectorPick<P_numtype2> &);
00389 template<typename P_numtype2>
00390 T_vector& operator&=(const VectorPick<P_numtype2> &);
00391 template<typename P_numtype2>
00392 T_vector& operator|=(const VectorPick<P_numtype2> &);
00393 template<typename P_numtype2>
00394 T_vector& operator>>=(const VectorPick<P_numtype2> &);
00395 template<typename P_numtype2>
00396 T_vector& operator<<=(const VectorPick<P_numtype2> &);
00397
00398
00399 T_vector& operator=(const Range&);
00400 T_vector& operator+=(const Range&);
00401 T_vector& operator-=(const Range&);
00402 T_vector& operator*=(const Range&);
00403 T_vector& operator/=(const Range&);
00404 T_vector& operator%=(const Range&);
00405 T_vector& operator^=(const Range&);
00406 T_vector& operator&=(const Range&);
00407 T_vector& operator|=(const Range&);
00408 T_vector& operator>>=(const Range&);
00409 T_vector& operator<<=(const Range&);
00410
00411 T_numtype* restrict getInitializationIterator()
00412 { return dataFirst(); }
00413
00414 private:
00415 T_numtype data_[N_length];
00416 };
00417
00418
00419
00420
00421
00422 template<typename T>
00423 class TinyVector<T,0> {
00424 };
00425
00426 BZ_NAMESPACE_END
00427
00428 #include <blitz/tinyveciter.h>
00429 #include <blitz/tvecglobs.h>
00430 #include <blitz/vector.h>
00431 #include <blitz/tinyvec.cc>
00432 #include <blitz/tinyvecio.cc>
00433
00434 #endif // BZ_TINYVEC_H
00435