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
00028 #ifndef BZ_VECPICKITER_H
00029 #define BZ_VECPICKITER_H
00030
00031 #ifndef BZ_VECPICK_H
00032 #include <blitz/vecpick.h>
00033 #endif
00034
00035 BZ_NAMESPACE(blitz)
00036
00037 template<typename P_numtype>
00038 class VectorPickIter {
00039
00040 public:
00041 typedef P_numtype T_numtype;
00042
00043 explicit VectorPickIter(VectorPick<T_numtype>& x)
00044 : data_(x.vector().data()), index_(x.indexSet().data())
00045 {
00046 dataStride_ = x.vector().stride();
00047 indexStride_ = x.indexSet().stride();
00048 length_ = x.indexSet().length();
00049 }
00050
00051 #ifdef BZ_MANUAL_VECEXPR_COPY_CONSTRUCTOR
00052 VectorPickIter(const VectorPickIter<T_numtype>& x)
00053 {
00054 data_ = x.data_;
00055 index_ = x.index_;
00056 dataStride_ = x.dataStride_;
00057 indexStride_ = x.indexStride_;
00058 length_ = x.length_;
00059 }
00060 #endif
00061
00062 T_numtype operator[](int i) const
00063 {
00064 BZPRECONDITION(i < length_);
00065 return data_[dataStride_ * index_[i * indexStride_]];
00066 }
00067
00068 T_numtype& operator[](int i)
00069 {
00070 BZPRECONDITION(i < length_);
00071 return data_[dataStride_ * index_[i * indexStride_]];
00072 }
00073
00074 int length(int) const
00075 { return length_; }
00076
00077 int _bz_suggestLength() const
00078 { return length_; }
00079
00080 bool isUnitStride() const
00081 { return (dataStride_ == 1) && (indexStride_ == 1); }
00082
00083 bool _bz_hasFastAccess() const
00084 { return isUnitStride(); }
00085
00086 T_numtype _bz_fastAccess(int i) const
00087 {
00088 return data_[index_[i]];
00089 }
00090
00091 T_numtype& _bz_fastAccess(int i)
00092 {
00093 return data_[index_[i]];
00094 }
00095
00096 static const int
00097 _bz_staticLengthCount = 0,
00098 _bz_dynamicLengthCount = 1,
00099 _bz_staticLength = 0;
00100
00101 private:
00102 T_numtype * restrict data_;
00103 int dataStride_;
00104 const int * restrict index_;
00105 int indexStride_;
00106 int length_;
00107 };
00108
00109 template<typename P_numtype>
00110 class VectorPickIterConst {
00111
00112 public:
00113 typedef P_numtype T_numtype;
00114
00115 explicit VectorPickIterConst(const VectorPick<T_numtype>& x)
00116 : data_(x.vector().data()), index_(x.indexSet().data())
00117 {
00118 dataStride_ = x.vector().stride();
00119 indexStride_ = x.indexSet().stride();
00120 length_ = x.indexSet().length();
00121 }
00122
00123 #ifdef BZ_MANUAL_VECEXPR_COPY_CONSTRUCTOR
00124 VectorPickIterConst(const VectorPickIterConst<T_numtype>& x)
00125 {
00126 data_ = x.data_;
00127 index_ = x.index_;
00128 dataStride_ = x.dataStride_;
00129 indexStride_ = x.indexStride_;
00130 length_ = x.length_;
00131 }
00132 #endif
00133
00134 T_numtype operator[](int i) const
00135 {
00136 BZPRECONDITION(i < length_);
00137 return data_[dataStride_ * index_[i * indexStride_]];
00138 }
00139
00140 int length(int) const
00141 { return length_; }
00142
00143 int _bz_suggestLength() const
00144 { return length_; }
00145
00146 bool isUnitStride() const
00147 { return (dataStride_ == 1) && (indexStride_ == 1); }
00148
00149 bool _bz_hasFastAccess() const
00150 { return isUnitStride(); }
00151
00152 T_numtype _bz_fastAccess(int i) const
00153 {
00154 return data_[index_[i]];
00155 }
00156
00157 static const int
00158 _bz_staticLengthCount = 0,
00159 _bz_dynamicLengthCount = 1,
00160 _bz_staticLength = 0;
00161
00162 private:
00163 const T_numtype * restrict data_;
00164 int dataStride_;
00165 const int * restrict index_;
00166 int indexStride_;
00167 int length_;
00168 };
00169
00170 BZ_NAMESPACE_END
00171
00172 #endif // BZ_VECPICKITER_H
00173