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 #ifdef BZ_HAVE_CSTRING
00036 #include <cstring>
00037 #endif
00038
00039 BZ_NAMESPACE(blitz)
00040
00041
00042
00043
00044
00045 template<typename P_numtype, int N_length, int N_stride BZ_TEMPLATE_DEFAULT(1) >
00046 class TinyVectorIter;
00047
00048 template<typename P_numtype, int N_length, int N_stride BZ_TEMPLATE_DEFAULT(1) >
00049 class TinyVectorIterConst;
00050
00051 template<typename P_numtype>
00052 class Vector;
00053
00054 template<typename P_expr>
00055 class _bz_VecExpr;
00056
00057 template<typename P_distribution>
00058 class Random;
00059
00060 template<typename P_numtype>
00061 class VectorPick;
00062
00063 template<typename T_numtype1, typename T_numtype2, int N_rows, int N_columns,
00064 int N_vecStride>
00065 class _bz_matrixVectorProduct;
00066
00067
00068
00069
00070
00071
00072
00073 template<typename P_numtype, int N_length>
00074 class TinyVector {
00075 public:
00076
00078
00080
00081 typedef P_numtype T_numtype;
00082 typedef TinyVector<T_numtype,N_length> T_vector;
00083 typedef TinyVectorIter<T_numtype,N_length,1> T_iterator;
00084 typedef TinyVectorIterConst<T_numtype,N_length,1> T_constIterator;
00085 typedef T_numtype* iterator;
00086 typedef const T_numtype* const_iterator;
00087 enum { numElements = N_length };
00088
00089 TinyVector() { }
00090 ~TinyVector() { }
00091
00092 inline TinyVector(const TinyVector<T_numtype,N_length>& x);
00093
00094 template <typename T_numtype2>
00095 inline TinyVector(const TinyVector<T_numtype2,N_length>& x);
00096
00097 inline TinyVector(const T_numtype initValue);
00098
00099 inline TinyVector(const T_numtype x[]) {
00100 memcpy(data_,x,N_length*sizeof(T_numtype));
00101 }
00102
00103 TinyVector(T_numtype x0, T_numtype x1)
00104 {
00105 data_[0] = x0;
00106 data_[1] = x1;
00107 }
00108
00109 TinyVector(T_numtype x0, T_numtype x1, T_numtype x2)
00110 {
00111 data_[0] = x0;
00112 data_[1] = x1;
00113 data_[2] = x2;
00114 }
00115
00116 TinyVector(T_numtype x0, T_numtype x1, T_numtype x2,
00117 T_numtype x3)
00118 {
00119 data_[0] = x0;
00120 data_[1] = x1;
00121 data_[2] = x2;
00122 data_[3] = x3;
00123 }
00124
00125 TinyVector(T_numtype x0, T_numtype x1, T_numtype x2,
00126 T_numtype x3, T_numtype x4)
00127 {
00128 data_[0] = x0;
00129 data_[1] = x1;
00130 data_[2] = x2;
00131 data_[3] = x3;
00132 data_[4] = x4;
00133 }
00134
00135 TinyVector(T_numtype x0, T_numtype x1, T_numtype x2,
00136 T_numtype x3, T_numtype x4, T_numtype x5)
00137 {
00138 data_[0] = x0;
00139 data_[1] = x1;
00140 data_[2] = x2;
00141 data_[3] = x3;
00142 data_[4] = x4;
00143 data_[5] = x5;
00144 }
00145
00146 TinyVector(T_numtype x0, T_numtype x1, T_numtype x2,
00147 T_numtype x3, T_numtype x4, T_numtype x5, T_numtype x6)
00148 {
00149 data_[0] = x0;
00150 data_[1] = x1;
00151 data_[2] = x2;
00152 data_[3] = x3;
00153 data_[4] = x4;
00154 data_[5] = x5;
00155 data_[6] = x6;
00156 }
00157
00158 TinyVector(T_numtype x0, T_numtype x1, T_numtype x2,
00159 T_numtype x3, T_numtype x4, T_numtype x5, T_numtype x6,
00160 T_numtype x7)
00161 {
00162 data_[0] = x0;
00163 data_[1] = x1;
00164 data_[2] = x2;
00165 data_[3] = x3;
00166 data_[4] = x4;
00167 data_[5] = x5;
00168 data_[6] = x6;
00169 data_[7] = x7;
00170 }
00171
00172 TinyVector(T_numtype x0, T_numtype x1, T_numtype x2,
00173 T_numtype x3, T_numtype x4, T_numtype x5, T_numtype x6,
00174 T_numtype x7, T_numtype x8)
00175 {
00176 data_[0] = x0;
00177 data_[1] = x1;
00178 data_[2] = x2;
00179 data_[3] = x3;
00180 data_[4] = x4;
00181 data_[5] = x5;
00182 data_[6] = x6;
00183 data_[7] = x7;
00184 data_[8] = x8;
00185 }
00186
00187 TinyVector(T_numtype x0, T_numtype x1, T_numtype x2,
00188 T_numtype x3, T_numtype x4, T_numtype x5, T_numtype x6,
00189 T_numtype x7, T_numtype x8, T_numtype x9)
00190 {
00191 data_[0] = x0;
00192 data_[1] = x1;
00193 data_[2] = x2;
00194 data_[3] = x3;
00195 data_[4] = x4;
00196 data_[5] = x5;
00197 data_[6] = x6;
00198 data_[7] = x7;
00199 data_[8] = x8;
00200 data_[9] = x9;
00201 }
00202
00203 TinyVector(T_numtype x0, T_numtype x1, T_numtype x2,
00204 T_numtype x3, T_numtype x4, T_numtype x5, T_numtype x6,
00205 T_numtype x7, T_numtype x8, T_numtype x9, T_numtype x10)
00206 {
00207 data_[0] = x0;
00208 data_[1] = x1;
00209 data_[2] = x2;
00210 data_[3] = x3;
00211 data_[4] = x4;
00212 data_[5] = x5;
00213 data_[6] = x6;
00214 data_[7] = x7;
00215 data_[8] = x8;
00216 data_[9] = x9;
00217 data_[10] = x10;
00218 }
00219
00220
00221 template<typename P_expr>
00222 inline TinyVector(_bz_VecExpr<P_expr> expr);
00223
00224 T_iterator beginFast() { return T_iterator(*this); }
00225 T_constIterator beginFast() const { return T_constIterator(*this); }
00226
00227 iterator begin() { return data_; }
00228 const_iterator begin() const { return data_; }
00229
00230 iterator end() { return data_ + N_length; }
00231 const_iterator end() const { return data_ + N_length; }
00232
00233 T_numtype * restrict data()
00234 { return data_; }
00235
00236 const T_numtype * restrict data() const
00237 { return data_; }
00238
00239 T_numtype * restrict dataFirst()
00240 { return data_; }
00241
00242 const T_numtype * restrict dataFirst() const
00243 { return data_; }
00244
00245 unsigned length() const
00246 { return N_length; }
00247
00249
00250
00251
00253
00254 unsigned _bz_suggestLength() const
00255 { return N_length; }
00256
00257 bool _bz_hasFastAccess() const
00258 { return true; }
00259
00260 T_numtype& restrict _bz_fastAccess(unsigned i)
00261 { return data_[i]; }
00262
00263 T_numtype _bz_fastAccess(unsigned i) const
00264 { return data_[i]; }
00265
00266 template<typename P_expr, typename P_updater>
00267 void _bz_assign(P_expr, P_updater);
00268
00269 _bz_VecExpr<T_constIterator> _bz_asVecExpr() const
00270 { return _bz_VecExpr<T_constIterator>(beginFast()); }
00271
00273
00275
00276 bool lengthCheck(unsigned i) const
00277 {
00278 BZPRECHECK(i < N_length,
00279 "TinyVector<" << BZ_DEBUG_TEMPLATE_AS_STRING_LITERAL(T_numtype)
00280 << "," << N_length << "> index out of bounds: " << i);
00281 return true;
00282 }
00283
00284 const T_numtype& operator()(unsigned i) const
00285 {
00286 BZPRECONDITION(lengthCheck(i));
00287 return data_[i];
00288 }
00289
00290 T_numtype& restrict operator()(unsigned i)
00291 {
00292 BZPRECONDITION(lengthCheck(i));
00293 return data_[i];
00294 }
00295
00296 const T_numtype& operator[](unsigned i) const
00297 {
00298 BZPRECONDITION(lengthCheck(i));
00299 return data_[i];
00300 }
00301
00302 T_numtype& restrict operator[](unsigned i)
00303 {
00304 BZPRECONDITION(lengthCheck(i));
00305 return data_[i];
00306 }
00307
00309
00311
00312
00313 ListInitializationSwitch<T_vector,T_numtype*> operator=(T_numtype x)
00314 {
00315 return ListInitializationSwitch<T_vector,T_numtype*>(*this, x);
00316 }
00317
00318 T_vector& initialize(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 T_numtype);
00324 T_vector& operator^=(const T_numtype);
00325 T_vector& operator&=(const T_numtype);
00326 T_vector& operator|=(const T_numtype);
00327 T_vector& operator>>=(const int);
00328 T_vector& operator<<=(const int);
00329
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 template<typename P_numtype2>
00349 T_vector& operator>>=(const TinyVector<P_numtype2, N_length> &);
00350 template<typename P_numtype2>
00351 T_vector& operator<<=(const TinyVector<P_numtype2, N_length> &);
00352
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 template<typename P_numtype2> T_vector& operator&=(const Vector<P_numtype2> &);
00361 template<typename P_numtype2> T_vector& operator|=(const Vector<P_numtype2> &);
00362 template<typename P_numtype2> T_vector& operator>>=(const Vector<P_numtype2> &);
00363 template<typename P_numtype2> T_vector& operator<<=(const Vector<P_numtype2> &);
00364
00365
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 template<typename P_expr> T_vector& operator&=(_bz_VecExpr<P_expr>);
00374 template<typename P_expr> T_vector& operator|=(_bz_VecExpr<P_expr>);
00375 template<typename P_expr> T_vector& operator>>=(_bz_VecExpr<P_expr>);
00376 template<typename P_expr> T_vector& operator<<=(_bz_VecExpr<P_expr>);
00377
00378
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 template<typename P_numtype2>
00398 T_vector& operator>>=(const VectorPick<P_numtype2> &);
00399 template<typename P_numtype2>
00400 T_vector& operator<<=(const VectorPick<P_numtype2> &);
00401
00402
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 T_vector& operator&=(const Range&);
00411 T_vector& operator|=(const Range&);
00412 T_vector& operator>>=(const Range&);
00413 T_vector& operator<<=(const Range&);
00414
00415 T_numtype* restrict getInitializationIterator()
00416 { return dataFirst(); }
00417
00418 private:
00419 T_numtype data_[N_length];
00420 };
00421
00422
00423
00424
00425
00426 template<typename T>
00427 class TinyVector<T,0> {
00428 };
00429
00430 BZ_NAMESPACE_END
00431
00432 #include <blitz/tinyveciter.h>
00433 #include <blitz/tvecglobs.h>
00434 #include <blitz/vector.h>
00435 #include <blitz/tinyvec.cc>
00436 #include <blitz/tinyvecio.cc>
00437
00438 #endif // BZ_TINYVEC_H
00439