This repository has been archived by the owner on May 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vecpickiter.h
173 lines (141 loc) · 4.29 KB
/
vecpickiter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// -*- C++ -*-
/***************************************************************************
* blitz/vecpickiter.h Declaration of VectorPickIter<T_numtype> and
* VectorPickIterConst<T_numtype> classes
*
* $Id: vecpickiter.h,v 1.5 2005/05/07 04:17:56 julianc Exp $
*
* Copyright (C) 1997-2001 Todd Veldhuizen <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* Suggestions: [email protected]
* Bugs: [email protected]
*
* For more information, please see the Blitz++ Home Page:
* http://oonumerics.org/blitz/
*
***************************************************************************/
#ifndef BZ_VECPICKITER_H
#define BZ_VECPICKITER_H
#ifndef BZ_VECPICK_H
#include <blitz/vecpick.h>
#endif
BZ_NAMESPACE(blitz)
template<typename P_numtype>
class VectorPickIter {
public:
typedef P_numtype T_numtype;
explicit VectorPickIter(VectorPick<T_numtype>& x)
: data_(x.vector().data()), index_(x.indexSet().data())
{
dataStride_ = x.vector().stride();
indexStride_ = x.indexSet().stride();
length_ = x.indexSet().length();
}
#ifdef BZ_MANUAL_VECEXPR_COPY_CONSTRUCTOR
VectorPickIter(const VectorPickIter<T_numtype>& x)
{
data_ = x.data_;
index_ = x.index_;
dataStride_ = x.dataStride_;
indexStride_ = x.indexStride_;
length_ = x.length_;
}
#endif
T_numtype operator[](int i) const
{
BZPRECONDITION(i < length_);
return data_[dataStride_ * index_[i * indexStride_]];
}
T_numtype& operator[](int i)
{
BZPRECONDITION(i < length_);
return data_[dataStride_ * index_[i * indexStride_]];
}
int length(int) const
{ return length_; }
int _bz_suggestLength() const
{ return length_; }
bool isUnitStride() const
{ return (dataStride_ == 1) && (indexStride_ == 1); }
bool _bz_hasFastAccess() const
{ return isUnitStride(); }
T_numtype _bz_fastAccess(int i) const
{
return data_[index_[i]];
}
T_numtype& _bz_fastAccess(int i)
{
return data_[index_[i]];
}
static const int
_bz_staticLengthCount = 0,
_bz_dynamicLengthCount = 1,
_bz_staticLength = 0;
private:
T_numtype * restrict data_;
int dataStride_;
const int * restrict index_;
int indexStride_;
int length_;
};
template<typename P_numtype>
class VectorPickIterConst {
public:
typedef P_numtype T_numtype;
explicit VectorPickIterConst(const VectorPick<T_numtype>& x)
: data_(x.vector().data()), index_(x.indexSet().data())
{
dataStride_ = x.vector().stride();
indexStride_ = x.indexSet().stride();
length_ = x.indexSet().length();
}
#ifdef BZ_MANUAL_VECEXPR_COPY_CONSTRUCTOR
VectorPickIterConst(const VectorPickIterConst<T_numtype>& x)
{
data_ = x.data_;
index_ = x.index_;
dataStride_ = x.dataStride_;
indexStride_ = x.indexStride_;
length_ = x.length_;
}
#endif
T_numtype operator[](int i) const
{
BZPRECONDITION(i < length_);
return data_[dataStride_ * index_[i * indexStride_]];
}
int length(int) const
{ return length_; }
int _bz_suggestLength() const
{ return length_; }
bool isUnitStride() const
{ return (dataStride_ == 1) && (indexStride_ == 1); }
bool _bz_hasFastAccess() const
{ return isUnitStride(); }
T_numtype _bz_fastAccess(int i) const
{
return data_[index_[i]];
}
static const int
_bz_staticLengthCount = 0,
_bz_dynamicLengthCount = 1,
_bz_staticLength = 0;
private:
const T_numtype * restrict data_;
int dataStride_;
const int * restrict index_;
int indexStride_;
int length_;
};
BZ_NAMESPACE_END
#endif // BZ_VECPICKITER_H