1 | // -*- C++ -*- |
---|
2 | /*************************************************************************** |
---|
3 | * blitz/indexexpr.h Declaration of the IndexPlaceholder<N> class |
---|
4 | * |
---|
5 | * $Id$ |
---|
6 | * |
---|
7 | * Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org> |
---|
8 | * |
---|
9 | * This file is a part of Blitz. |
---|
10 | * |
---|
11 | * Blitz is free software: you can redistribute it and/or modify |
---|
12 | * it under the terms of the GNU Lesser General Public License |
---|
13 | * as published by the Free Software Foundation, either version 3 |
---|
14 | * of the License, or (at your option) any later version. |
---|
15 | * |
---|
16 | * Blitz is distributed in the hope that it will be useful, |
---|
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
19 | * GNU Lesser General Public License for more details. |
---|
20 | * |
---|
21 | * You should have received a copy of the GNU Lesser General Public |
---|
22 | * License along with Blitz. If not, see <http://www.gnu.org/licenses/>. |
---|
23 | * |
---|
24 | * Suggestions: blitz-devel@lists.sourceforge.net |
---|
25 | * Bugs: blitz-support@lists.sourceforge.net |
---|
26 | * |
---|
27 | * For more information, please see the Blitz++ Home Page: |
---|
28 | * https://sourceforge.net/projects/blitz/ |
---|
29 | * |
---|
30 | ***************************************************************************/ |
---|
31 | |
---|
32 | #ifndef BZ_INDEXEXPR_H |
---|
33 | #define BZ_INDEXEXPR_H |
---|
34 | |
---|
35 | #include <blitz/tinyvec2.h> |
---|
36 | #include <blitz/prettyprint.h> |
---|
37 | #include <blitz/etbase.h> |
---|
38 | #include <blitz/array/domain.h> |
---|
39 | #include <blitz/array/slice.h> |
---|
40 | |
---|
41 | BZ_NAMESPACE(blitz) |
---|
42 | |
---|
43 | template<int N> |
---|
44 | class IndexPlaceholder |
---|
45 | #ifdef BZ_NEW_EXPRESSION_TEMPLATES |
---|
46 | : public ETBase<IndexPlaceholder<N> > |
---|
47 | #endif |
---|
48 | { |
---|
49 | public: |
---|
50 | IndexPlaceholder() |
---|
51 | { } |
---|
52 | |
---|
53 | #ifdef BZ_NEW_EXPRESSION_TEMPLATES |
---|
54 | IndexPlaceholder(const IndexPlaceholder<N>& x) |
---|
55 | : ETBase< IndexPlaceholder<N> >(x) |
---|
56 | { } |
---|
57 | #else |
---|
58 | IndexPlaceholder(const IndexPlaceholder<N>&) |
---|
59 | { } |
---|
60 | #endif |
---|
61 | |
---|
62 | ~IndexPlaceholder() |
---|
63 | { } |
---|
64 | |
---|
65 | void operator=(const IndexPlaceholder<N>&) |
---|
66 | { } |
---|
67 | |
---|
68 | typedef int T_numtype; |
---|
69 | typedef int T_ctorArg1; // Dummy; not used |
---|
70 | typedef int T_ctorArg2; // Ditto |
---|
71 | typedef int T_range_result; // dummy |
---|
72 | |
---|
73 | typedef typename opType<T_numtype>::T_optype T_optype; |
---|
74 | typedef typename asET<T_numtype>::T_wrapped T_typeprop; |
---|
75 | typedef typename unwrapET<T_typeprop>::T_unwrapped T_result; |
---|
76 | |
---|
77 | static const int |
---|
78 | numArrayOperands = 0, |
---|
79 | numTVOperands = 0, |
---|
80 | numTMOperands = 0, |
---|
81 | numIndexPlaceholders = 1, |
---|
82 | minWidth = simdTypes<T_numtype>::vecWidth, |
---|
83 | maxWidth = simdTypes<T_numtype>::vecWidth, |
---|
84 | rank_ = N+1; |
---|
85 | |
---|
86 | /** The vectorized return type for an IndexPlaceholder should be |
---|
87 | some form of range, but that's not useful since a vectorized |
---|
88 | TinyVector assignment can not contain index placeholders. In |
---|
89 | fact, since vectorization doesn't work for index expressions |
---|
90 | anyway, we can just set this to a dummy. */ |
---|
91 | template<int M> struct tvresult { |
---|
92 | typedef FastTV2Iterator<T_numtype, M> Type; |
---|
93 | }; |
---|
94 | |
---|
95 | // If you have a precondition failure on this routine, it means |
---|
96 | // you are trying to use stack iteration mode on an expression |
---|
97 | // which contains an index placeholder. You must use index |
---|
98 | // iteration mode instead. |
---|
99 | int operator*() const { |
---|
100 | BZPRECONDITION(0); |
---|
101 | return 0; |
---|
102 | } |
---|
103 | |
---|
104 | #ifdef BZ_ARRAY_EXPR_PASS_INDEX_BY_VALUE |
---|
105 | template<int N_rank> |
---|
106 | T_result operator()(TinyVector<int, N_rank> i) const { return i[N]; } |
---|
107 | #else |
---|
108 | template<int N_rank> |
---|
109 | T_result operator()(const TinyVector<int, N_rank>& i) const { return i[N]; } |
---|
110 | #endif |
---|
111 | |
---|
112 | int ascending(int) const { return INT_MIN; } |
---|
113 | int ordering(int) const { return INT_MIN; } |
---|
114 | int lbound(int) const { return INT_MIN; } // tiny(int()); |
---|
115 | int ubound(int) const { return INT_MAX; } // huge(int()); |
---|
116 | |
---|
117 | RectDomain<rank_> domain() const |
---|
118 | { |
---|
119 | const TinyVector<int, rank_> lb(lbound(0)), ub(ubound(0)); |
---|
120 | return RectDomain<rank_>(lb,ub); |
---|
121 | } |
---|
122 | |
---|
123 | // See operator*() note |
---|
124 | |
---|
125 | void push(int) { BZPRECONDITION(0); } |
---|
126 | void pop(int) { BZPRECONDITION(0); } |
---|
127 | void advance() { BZPRECONDITION(0); } |
---|
128 | void advance(int) { BZPRECONDITION(0); } |
---|
129 | void loadStride(int) { BZPRECONDITION(0); } |
---|
130 | template<int N_rank> |
---|
131 | void moveTo(const TinyVector<int,N_rank>& i) { BZPRECONDITION(0); } |
---|
132 | |
---|
133 | bool isUnitStride(int) const { |
---|
134 | BZPRECONDITION(0); |
---|
135 | return false; |
---|
136 | } |
---|
137 | |
---|
138 | bool isUnitStride() const { |
---|
139 | BZPRECONDITION(0); |
---|
140 | return false; |
---|
141 | } |
---|
142 | |
---|
143 | void advanceUnitStride() { BZPRECONDITION(0); } |
---|
144 | |
---|
145 | bool canCollapse(int,int) const { |
---|
146 | BZPRECONDITION(0); |
---|
147 | return false; |
---|
148 | } |
---|
149 | |
---|
150 | T_result operator[](int) const { |
---|
151 | BZPRECONDITION(0); |
---|
152 | return T_numtype(); |
---|
153 | } |
---|
154 | |
---|
155 | T_result fastRead(diffType) const { |
---|
156 | BZPRECONDITION(0); |
---|
157 | return T_numtype(); |
---|
158 | } |
---|
159 | |
---|
160 | template<int M> |
---|
161 | typename tvresult<M>::Type fastRead_tv(diffType) const { |
---|
162 | BZPRECONDITION(0); |
---|
163 | return TinyVector<T_numtype, M>(); |
---|
164 | } |
---|
165 | |
---|
166 | /** There are no alignment issues here, so just return true. */ |
---|
167 | bool isVectorAligned(diffType offset) const { |
---|
168 | return true; } |
---|
169 | |
---|
170 | diffType suggestStride(int) const { |
---|
171 | BZPRECONDITION(0); |
---|
172 | return 0; |
---|
173 | } |
---|
174 | |
---|
175 | bool isStride(int,diffType) const { |
---|
176 | BZPRECONDITION(0); |
---|
177 | return true; |
---|
178 | } |
---|
179 | |
---|
180 | // don't know how to define shift, as it relies on having an |
---|
181 | // implicit position. thus stencils won't work |
---|
182 | T_result shift(int offset, int dim) const |
---|
183 | { BZPRECHECK(0,"Stencils of index expressions are not implemented"); |
---|
184 | return T_numtype(); } |
---|
185 | T_result shift(int offset1, int dim1,int offset2, int dim2) const { |
---|
186 | BZPRECHECK(0,"Stencils of index expressions are not implemented"); |
---|
187 | return T_numtype(); } |
---|
188 | void _bz_offsetData(sizeType i) { BZPRECONDITION(0); } |
---|
189 | |
---|
190 | // Unclear how to define this, and stencils don't work anyway |
---|
191 | T_range_result operator()(RectDomain<rank_> d) const |
---|
192 | { BZPRECHECK(0,"Stencils of index expressions are not implemented"); |
---|
193 | return T_range_result(); } |
---|
194 | |
---|
195 | void prettyPrint(BZ_STD_SCOPE(string) &str, prettyPrintFormat&) const { |
---|
196 | // NEEDS_WORK-- do real formatting for reductions |
---|
197 | str += "index-expr[NEEDS_WORK]"; |
---|
198 | } |
---|
199 | |
---|
200 | template<typename T_shape> |
---|
201 | bool shapeCheck(const T_shape&) const { return true; } |
---|
202 | |
---|
203 | // sliceinfo for index placeholder does nothing |
---|
204 | template<typename T1, typename T2 = nilArraySection, |
---|
205 | class T3 = nilArraySection, typename T4 = nilArraySection, |
---|
206 | class T5 = nilArraySection, typename T6 = nilArraySection, |
---|
207 | class T7 = nilArraySection, typename T8 = nilArraySection, |
---|
208 | class T9 = nilArraySection, typename T10 = nilArraySection, |
---|
209 | class T11 = nilArraySection> |
---|
210 | class SliceInfo { |
---|
211 | public: |
---|
212 | static const int new_rank = (N>0) ? ArraySectionInfo<T1>::rank : 0 |
---|
213 | + (N>1) ? ArraySectionInfo<T2>::rank : 0 |
---|
214 | + (N>2) ? ArraySectionInfo<T3>::rank : 0 |
---|
215 | + (N>4) ? ArraySectionInfo<T4>::rank : 0 |
---|
216 | + (N>5) ? ArraySectionInfo<T5>::rank : 0 |
---|
217 | + (N>6) ? ArraySectionInfo<T6>::rank : 0 |
---|
218 | + (N>7) ? ArraySectionInfo<T7>::rank : 0 |
---|
219 | + (N>8) ? ArraySectionInfo<T8>::rank : 0 |
---|
220 | + (N>9) ? ArraySectionInfo<T9>::rank : 0 |
---|
221 | + (N>10) ? ArraySectionInfo<T10>::rank : 0 |
---|
222 | + (N>11) ? ArraySectionInfo<T11>::rank : 0; |
---|
223 | typedef IndexPlaceholder<new_rank> T_slice; |
---|
224 | }; |
---|
225 | |
---|
226 | template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, |
---|
227 | typename T7, typename T8, typename T9, typename T10, typename T11> |
---|
228 | typename SliceInfo<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11>::T_slice |
---|
229 | operator()(T1 r1, T2 r2, T3 r3, T4 r4, T5 r5, T6 r6, T7 r7, T8 r8, T9 r9, T10 r10, T11 r11) const |
---|
230 | { |
---|
231 | // slicing of index placeholders is not implemented. there are |
---|
232 | // two problems: First, if you slice the dimension of the index |
---|
233 | // placeholder, it should be replaced with a constant. Second, |
---|
234 | // if you restrict the range of that dimension, the index |
---|
235 | // placeholder should start from a nonzero value. |
---|
236 | BZPRECONDITION(0); |
---|
237 | } |
---|
238 | }; |
---|
239 | |
---|
240 | typedef IndexPlaceholder<0> firstIndex; |
---|
241 | typedef IndexPlaceholder<1> secondIndex; |
---|
242 | typedef IndexPlaceholder<2> thirdIndex; |
---|
243 | typedef IndexPlaceholder<3> fourthIndex; |
---|
244 | typedef IndexPlaceholder<4> fifthIndex; |
---|
245 | typedef IndexPlaceholder<5> sixthIndex; |
---|
246 | typedef IndexPlaceholder<6> seventhIndex; |
---|
247 | typedef IndexPlaceholder<7> eighthIndex; |
---|
248 | typedef IndexPlaceholder<8> ninthIndex; |
---|
249 | typedef IndexPlaceholder<9> tenthIndex; |
---|
250 | typedef IndexPlaceholder<10> eleventhIndex; |
---|
251 | |
---|
252 | #ifndef BZ_NO_TENSOR_INDEX_OBJECTS |
---|
253 | |
---|
254 | BZ_NAMESPACE(tensor) |
---|
255 | _bz_global blitz::IndexPlaceholder<0> i; |
---|
256 | _bz_global blitz::IndexPlaceholder<1> j; |
---|
257 | _bz_global blitz::IndexPlaceholder<2> k; |
---|
258 | _bz_global blitz::IndexPlaceholder<3> l; |
---|
259 | _bz_global blitz::IndexPlaceholder<4> m; |
---|
260 | _bz_global blitz::IndexPlaceholder<5> n; |
---|
261 | _bz_global blitz::IndexPlaceholder<6> o; |
---|
262 | _bz_global blitz::IndexPlaceholder<7> p; |
---|
263 | _bz_global blitz::IndexPlaceholder<8> q; |
---|
264 | _bz_global blitz::IndexPlaceholder<9> r; |
---|
265 | _bz_global blitz::IndexPlaceholder<10> s; |
---|
266 | _bz_global blitz::IndexPlaceholder<11> t; |
---|
267 | BZ_NAMESPACE_END // tensor |
---|
268 | |
---|
269 | #endif |
---|
270 | |
---|
271 | BZ_NAMESPACE_END |
---|
272 | |
---|
273 | #endif // BZ_INDEXEXPR_H |
---|
274 | |
---|