| 1 | /***************************************************************************
 | 
|---|
| 2 |  * blitz/vecpick.h      Declaration of the VectorPick<T_numtype> class
 | 
|---|
| 3 |  *
 | 
|---|
| 4 |  * $Id: vecpick.h,v 1.1.1.1 1999-11-26 16:37:06 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:00  ansari
 | 
|---|
| 27 |  * Creation module DPC/Blitz (blitz 0.4) Reza 09/04/99
 | 
|---|
| 28 |  *
 | 
|---|
| 29 |  * Revision 1.5  1998/03/14 00:04:47  tveldhui
 | 
|---|
| 30 |  * 0.2-alpha-05
 | 
|---|
| 31 |  *
 | 
|---|
| 32 |  * Revision 1.4  1997/07/16 14:51:20  tveldhui
 | 
|---|
| 33 |  * Update: Alpha release 0.2 (Arrays)
 | 
|---|
| 34 |  *
 | 
|---|
| 35 |  * Revision 1.3  1997/01/24 14:42:00  tveldhui
 | 
|---|
| 36 |  * Periodic RCS update
 | 
|---|
| 37 |  *
 | 
|---|
| 38 |  * Revision 1.2  1997/01/23 03:28:28  tveldhui
 | 
|---|
| 39 |  * Periodic RCS update
 | 
|---|
| 40 |  *
 | 
|---|
| 41 |  * Revision 1.1  1997/01/13 22:19:58  tveldhui
 | 
|---|
| 42 |  * Periodic RCS update
 | 
|---|
| 43 |  *
 | 
|---|
| 44 |  *
 | 
|---|
| 45 |  */
 | 
|---|
| 46 | 
 | 
|---|
| 47 | #ifndef BZ_VECPICK_H
 | 
|---|
| 48 | #define BZ_VECPICK_H
 | 
|---|
| 49 | 
 | 
|---|
| 50 | #ifndef BZ_VECTOR_H
 | 
|---|
| 51 |  #include <blitz/vector.h>
 | 
|---|
| 52 | #endif
 | 
|---|
| 53 | 
 | 
|---|
| 54 | BZ_NAMESPACE(blitz)
 | 
|---|
| 55 | 
 | 
|---|
| 56 | // Forward declarations
 | 
|---|
| 57 | 
 | 
|---|
| 58 | template<class P_numtype> class VectorPickIter;
 | 
|---|
| 59 | template<class P_numtype> class VectorPickIterConst;
 | 
|---|
| 60 | 
 | 
|---|
| 61 | // Declaration of class VectorPick<P_numtype>
 | 
|---|
| 62 | 
 | 
|---|
| 63 | template<class P_numtype>
 | 
|---|
| 64 | class VectorPick {
 | 
|---|
| 65 | 
 | 
|---|
| 66 | public:
 | 
|---|
| 67 |     //////////////////////////////////////////////
 | 
|---|
| 68 |     // Public Types
 | 
|---|
| 69 |     //////////////////////////////////////////////
 | 
|---|
| 70 | 
 | 
|---|
| 71 |     typedef P_numtype                      T_numtype;
 | 
|---|
| 72 |     typedef Vector<T_numtype>              T_vector;
 | 
|---|
| 73 |     typedef Vector<int>                    T_indexVector;
 | 
|---|
| 74 |     typedef VectorPick<T_numtype>          T_pick;
 | 
|---|
| 75 |     typedef VectorPickIter<T_numtype>      T_iterator;
 | 
|---|
| 76 |     typedef VectorPickIterConst<T_numtype> T_constIterator;
 | 
|---|
| 77 | 
 | 
|---|
| 78 |     //////////////////////////////////////////////
 | 
|---|
| 79 |     // Constructors                             //
 | 
|---|
| 80 |     //////////////////////////////////////////////
 | 
|---|
| 81 | 
 | 
|---|
| 82 |     VectorPick(T_vector& vector, T_indexVector& indexarg)
 | 
|---|
| 83 |         : vector_(vector), index_(indexarg)
 | 
|---|
| 84 |     { }
 | 
|---|
| 85 | 
 | 
|---|
| 86 |     VectorPick(const T_pick& vecpick)
 | 
|---|
| 87 |         : vector_(const_cast<T_vector&>(vecpick.vector_)), 
 | 
|---|
| 88 |           index_(const_cast<T_indexVector&>(vecpick.index_))
 | 
|---|
| 89 |     { }
 | 
|---|
| 90 | 
 | 
|---|
| 91 |     VectorPick(T_pick& vecpick, Range r)
 | 
|---|
| 92 |         : vector_(vecpick.vector_), index_(vecpick.index_[r])
 | 
|---|
| 93 |     { }
 | 
|---|
| 94 |  
 | 
|---|
| 95 |     //////////////////////////////////////////////
 | 
|---|
| 96 |     // Member functions
 | 
|---|
| 97 |     //////////////////////////////////////////////
 | 
|---|
| 98 | 
 | 
|---|
| 99 |     T_iterator         begin()
 | 
|---|
| 100 |     { return VectorPickIter<T_numtype>(*this); }
 | 
|---|
| 101 | 
 | 
|---|
| 102 |     T_constIterator    begin()      const
 | 
|---|
| 103 |     { return VectorPickIterConst<T_numtype>(*this); }
 | 
|---|
| 104 | 
 | 
|---|
| 105 |     // T_vector           copy()       const;
 | 
|---|
| 106 | 
 | 
|---|
| 107 |     // T_iterator         end();
 | 
|---|
| 108 | 
 | 
|---|
| 109 |     // T_constIterator    end()        const;
 | 
|---|
| 110 | 
 | 
|---|
| 111 |     T_indexVector&     indexSet()
 | 
|---|
| 112 |     { return index_; }
 | 
|---|
| 113 |  
 | 
|---|
| 114 |     const T_indexVector& indexSet()      const
 | 
|---|
| 115 |     { return index_; }
 | 
|---|
| 116 | 
 | 
|---|
| 117 |     int           length()     const
 | 
|---|
| 118 |     { return index_.length(); }
 | 
|---|
| 119 | 
 | 
|---|
| 120 |     void               setVector(Vector<T_numtype>& x)
 | 
|---|
| 121 |     { vector_.reference(x); }
 | 
|---|
| 122 | 
 | 
|---|
| 123 |     void               setIndex(Vector<int>& index)
 | 
|---|
| 124 |     { index_.reference(index); }
 | 
|---|
| 125 | 
 | 
|---|
| 126 |     T_vector&          vector()
 | 
|---|
| 127 |     { return vector_; }
 | 
|---|
| 128 | 
 | 
|---|
| 129 |     const T_vector&    vector()     const
 | 
|---|
| 130 |     { return vector_; }
 | 
|---|
| 131 | 
 | 
|---|
| 132 |     /////////////////////////////////////////////
 | 
|---|
| 133 |     // Library-internal member functions
 | 
|---|
| 134 |     // These are undocumented and may change or
 | 
|---|
| 135 |     // disappear in future releases.
 | 
|---|
| 136 |     /////////////////////////////////////////////
 | 
|---|
| 137 | 
 | 
|---|
| 138 |     int        _bz_suggestLength() const
 | 
|---|
| 139 |     { return index_.length(); }
 | 
|---|
| 140 | 
 | 
|---|
| 141 |     _bz_bool        _bz_hasFastAccess() const
 | 
|---|
| 142 |     { return vector_._bz_hasFastAccess() && index_._bz_hasFastAccess(); }
 | 
|---|
| 143 | 
 | 
|---|
| 144 |     T_numtype&      _bz_fastAccess(int i)
 | 
|---|
| 145 |     { return vector_._bz_fastAccess(index_._bz_fastAccess(i)); }
 | 
|---|
| 146 | 
 | 
|---|
| 147 |     T_numtype       _bz_fastAccess(int i) const
 | 
|---|
| 148 |     { return vector_._bz_fastAccess(index_._bz_fastAccess(i)); }
 | 
|---|
| 149 | 
 | 
|---|
| 150 |     _bz_VecExpr<T_constIterator> _bz_asVecExpr() const
 | 
|---|
| 151 |     { return _bz_VecExpr<T_constIterator>(begin()); }
 | 
|---|
| 152 | 
 | 
|---|
| 153 |     //////////////////////////////////////////////
 | 
|---|
| 154 |     // Subscripting operators
 | 
|---|
| 155 |     //////////////////////////////////////////////
 | 
|---|
| 156 | 
 | 
|---|
| 157 |     T_numtype       operator()(int i) const
 | 
|---|
| 158 |     { 
 | 
|---|
| 159 |         BZPRECONDITION(index_.stride() == 1);
 | 
|---|
| 160 |         BZPRECONDITION(vector_.stride() == 1);
 | 
|---|
| 161 |         BZPRECONDITION(i < index_.length());
 | 
|---|
| 162 |         BZPRECONDITION(index_[i] < vector_.length());
 | 
|---|
| 163 |         return vector_(index_(i));
 | 
|---|
| 164 |     }
 | 
|---|
| 165 | 
 | 
|---|
| 166 |     T_numtype&      operator()(int i)
 | 
|---|
| 167 |     {
 | 
|---|
| 168 |         BZPRECONDITION(index_.stride() == 1);
 | 
|---|
| 169 |         BZPRECONDITION(vector_.stride() == 1);
 | 
|---|
| 170 |         BZPRECONDITION(i < index_.length());
 | 
|---|
| 171 |         BZPRECONDITION(index_[i] < vector_.length());
 | 
|---|
| 172 |         return vector_(index_(i));
 | 
|---|
| 173 |     }
 | 
|---|
| 174 | 
 | 
|---|
| 175 |     T_numtype       operator[](int i) const
 | 
|---|
| 176 |     {
 | 
|---|
| 177 |         BZPRECONDITION(index_.stride() == 1);
 | 
|---|
| 178 |         BZPRECONDITION(vector_.stride() == 1);
 | 
|---|
| 179 |         BZPRECONDITION(i < index_.length());
 | 
|---|
| 180 |         BZPRECONDITION(index_[i] < vector_.length());
 | 
|---|
| 181 |         return vector_[index_[i]];
 | 
|---|
| 182 |     }
 | 
|---|
| 183 | 
 | 
|---|
| 184 |     T_numtype&      operator[](int i)
 | 
|---|
| 185 |     {
 | 
|---|
| 186 |         BZPRECONDITION(index_.stride() == 1);
 | 
|---|
| 187 |         BZPRECONDITION(vector_.stride() == 1);
 | 
|---|
| 188 |         BZPRECONDITION(i < index_.length());
 | 
|---|
| 189 |         BZPRECONDITION(index_[i] < vector_.length());
 | 
|---|
| 190 |         return vector_[index_[i]];
 | 
|---|
| 191 |     }
 | 
|---|
| 192 | 
 | 
|---|
| 193 |     T_pick          operator()(Range r)
 | 
|---|
| 194 |     {
 | 
|---|
| 195 |         return T_pick(*this, index_[r]);
 | 
|---|
| 196 |     }
 | 
|---|
| 197 | 
 | 
|---|
| 198 |     T_pick          operator[](Range r)
 | 
|---|
| 199 |     {
 | 
|---|
| 200 |         return T_pick(*this, index_[r]);
 | 
|---|
| 201 |     }
 | 
|---|
| 202 | 
 | 
|---|
| 203 |     //////////////////////////////////////////////
 | 
|---|
| 204 |     // Assignment operators
 | 
|---|
| 205 |     //////////////////////////////////////////////
 | 
|---|
| 206 | 
 | 
|---|
| 207 |     // Scalar operand
 | 
|---|
| 208 |     T_pick& operator=(T_numtype);
 | 
|---|
| 209 |     T_pick& operator+=(T_numtype);
 | 
|---|
| 210 |     T_pick& operator-=(T_numtype);
 | 
|---|
| 211 |     T_pick& operator*=(T_numtype);
 | 
|---|
| 212 |     T_pick& operator/=(T_numtype);
 | 
|---|
| 213 |     T_pick& operator%=(T_numtype);
 | 
|---|
| 214 |     T_pick& operator^=(T_numtype);
 | 
|---|
| 215 |     T_pick& operator&=(T_numtype);
 | 
|---|
| 216 |     T_pick& operator|=(T_numtype);
 | 
|---|
| 217 |     T_pick& operator>>=(int);
 | 
|---|
| 218 |     T_pick& operator<<=(int);
 | 
|---|
| 219 | 
 | 
|---|
| 220 |     // Vector operand
 | 
|---|
| 221 |     template<class P_numtype2> T_pick& operator=(const Vector<P_numtype2> &);
 | 
|---|
| 222 |     template<class P_numtype2> T_pick& operator+=(const Vector<P_numtype2> &);
 | 
|---|
| 223 |     template<class P_numtype2> T_pick& operator-=(const Vector<P_numtype2> &);
 | 
|---|
| 224 |     template<class P_numtype2> T_pick& operator*=(const Vector<P_numtype2> &);
 | 
|---|
| 225 |     template<class P_numtype2> T_pick& operator/=(const Vector<P_numtype2> &);
 | 
|---|
| 226 |     template<class P_numtype2> T_pick& operator%=(const Vector<P_numtype2> &);
 | 
|---|
| 227 |     template<class P_numtype2> T_pick& operator^=(const Vector<P_numtype2> &);
 | 
|---|
| 228 |     template<class P_numtype2> T_pick& operator&=(const Vector<P_numtype2> &);
 | 
|---|
| 229 |     template<class P_numtype2> T_pick& operator|=(const Vector<P_numtype2> &);
 | 
|---|
| 230 |     template<class P_numtype2> T_pick& operator>>=(const Vector<P_numtype2> &);
 | 
|---|
| 231 |     template<class P_numtype2> T_pick& operator<<=(const Vector<P_numtype2> &);
 | 
|---|
| 232 | 
 | 
|---|
| 233 |     // Vector expression operand
 | 
|---|
| 234 |     template<class P_expr> T_pick& operator=(_bz_VecExpr<P_expr>);
 | 
|---|
| 235 |     template<class P_expr> T_pick& operator+=(_bz_VecExpr<P_expr>);
 | 
|---|
| 236 |     template<class P_expr> T_pick& operator-=(_bz_VecExpr<P_expr>);
 | 
|---|
| 237 |     template<class P_expr> T_pick& operator*=(_bz_VecExpr<P_expr>);
 | 
|---|
| 238 |     template<class P_expr> T_pick& operator/=(_bz_VecExpr<P_expr>);
 | 
|---|
| 239 |     template<class P_expr> T_pick& operator%=(_bz_VecExpr<P_expr>);
 | 
|---|
| 240 |     template<class P_expr> T_pick& operator^=(_bz_VecExpr<P_expr>);
 | 
|---|
| 241 |     template<class P_expr> T_pick& operator&=(_bz_VecExpr<P_expr>);
 | 
|---|
| 242 |     template<class P_expr> T_pick& operator|=(_bz_VecExpr<P_expr>);
 | 
|---|
| 243 |     template<class P_expr> T_pick& operator>>=(_bz_VecExpr<P_expr>);
 | 
|---|
| 244 |     template<class P_expr> T_pick& operator<<=(_bz_VecExpr<P_expr>);
 | 
|---|
| 245 | 
 | 
|---|
| 246 |     // Range operand
 | 
|---|
| 247 |     T_pick& operator=(Range);
 | 
|---|
| 248 |     T_pick& operator+=(Range);
 | 
|---|
| 249 |     T_pick& operator-=(Range);
 | 
|---|
| 250 |     T_pick& operator*=(Range);
 | 
|---|
| 251 |     T_pick& operator/=(Range);
 | 
|---|
| 252 |     T_pick& operator%=(Range);
 | 
|---|
| 253 |     T_pick& operator^=(Range);
 | 
|---|
| 254 |     T_pick& operator&=(Range);
 | 
|---|
| 255 |     T_pick& operator|=(Range);
 | 
|---|
| 256 |     T_pick& operator>>=(Range);
 | 
|---|
| 257 |     T_pick& operator<<=(Range);
 | 
|---|
| 258 | 
 | 
|---|
| 259 |     // Vector pick operand
 | 
|---|
| 260 |     template<class P_numtype2> 
 | 
|---|
| 261 |     T_pick& operator=(const VectorPick<P_numtype2> &);
 | 
|---|
| 262 |     template<class P_numtype2> 
 | 
|---|
| 263 |     T_pick& operator+=(const VectorPick<P_numtype2> &);
 | 
|---|
| 264 |     template<class P_numtype2> 
 | 
|---|
| 265 |     T_pick& operator-=(const VectorPick<P_numtype2> &);
 | 
|---|
| 266 |     template<class P_numtype2> 
 | 
|---|
| 267 |     T_pick& operator*=(const VectorPick<P_numtype2> &);
 | 
|---|
| 268 |     template<class P_numtype2> 
 | 
|---|
| 269 |     T_pick& operator/=(const VectorPick<P_numtype2> &);
 | 
|---|
| 270 |     template<class P_numtype2> 
 | 
|---|
| 271 |     T_pick& operator%=(const VectorPick<P_numtype2> &);
 | 
|---|
| 272 |     template<class P_numtype2> 
 | 
|---|
| 273 |     T_pick& operator^=(const VectorPick<P_numtype2> &);
 | 
|---|
| 274 |     template<class P_numtype2> 
 | 
|---|
| 275 |     T_pick& operator&=(const VectorPick<P_numtype2> &);
 | 
|---|
| 276 |     template<class P_numtype2> 
 | 
|---|
| 277 |     T_pick& operator|=(const VectorPick<P_numtype2> &);
 | 
|---|
| 278 |     template<class P_numtype2> 
 | 
|---|
| 279 |     T_pick& operator>>=(const VectorPick<P_numtype2> &);
 | 
|---|
| 280 |     template<class P_numtype2> 
 | 
|---|
| 281 |     T_pick& operator<<=(const VectorPick<P_numtype2> &);
 | 
|---|
| 282 | 
 | 
|---|
| 283 |     // Random operand
 | 
|---|
| 284 |     template<class P_distribution>
 | 
|---|
| 285 |     T_pick& operator=(Random<P_distribution>& random);
 | 
|---|
| 286 |     template<class P_distribution>
 | 
|---|
| 287 |     T_pick& operator+=(Random<P_distribution>& random);
 | 
|---|
| 288 |     template<class P_distribution>
 | 
|---|
| 289 |     T_pick& operator-=(Random<P_distribution>& random);
 | 
|---|
| 290 |     template<class P_distribution>
 | 
|---|
| 291 |     T_pick& operator*=(Random<P_distribution>& random);
 | 
|---|
| 292 |     template<class P_distribution>
 | 
|---|
| 293 |     T_pick& operator/=(Random<P_distribution>& random);
 | 
|---|
| 294 |     template<class P_distribution>
 | 
|---|
| 295 |     T_pick& operator%=(Random<P_distribution>& random);
 | 
|---|
| 296 |     template<class P_distribution>
 | 
|---|
| 297 |     T_pick& operator^=(Random<P_distribution>& random);
 | 
|---|
| 298 |     template<class P_distribution>
 | 
|---|
| 299 |     T_pick& operator&=(Random<P_distribution>& random);
 | 
|---|
| 300 |     template<class P_distribution>
 | 
|---|
| 301 |     T_pick& operator|=(Random<P_distribution>& random);
 | 
|---|
| 302 | 
 | 
|---|
| 303 | private:
 | 
|---|
| 304 |     VectorPick() { }
 | 
|---|
| 305 | 
 | 
|---|
| 306 |     template<class P_expr, class P_updater>
 | 
|---|
| 307 |     inline void _bz_assign(P_expr, P_updater);
 | 
|---|
| 308 | 
 | 
|---|
| 309 | private:
 | 
|---|
| 310 |     T_vector vector_;
 | 
|---|
| 311 |     T_indexVector index_;
 | 
|---|
| 312 | };
 | 
|---|
| 313 | 
 | 
|---|
| 314 | BZ_NAMESPACE_END
 | 
|---|
| 315 | 
 | 
|---|
| 316 | #include <blitz/vecpick.cc>
 | 
|---|
| 317 | #include <blitz/vecpickio.cc>
 | 
|---|
| 318 | #include <blitz/vecpickiter.h>
 | 
|---|
| 319 | 
 | 
|---|
| 320 | #endif // BZ_VECPICK_H
 | 
|---|