blitz Version 1.0.2
Loading...
Searching...
No Matches
indexexpr.h
Go to the documentation of this file.
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
41namespace blitz {
42
43template<int N>
46 : public ETBase<IndexPlaceholder<N> >
47#endif
48{
49public:
52
53#ifdef BZ_NEW_EXPRESSION_TEMPLATES
55 : ETBase< IndexPlaceholder<N> >(x)
56 { }
57#else
60#endif
61
64
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
84 rank_ = N+1;
85
91 template<int M> struct tvresult {
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
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
156 BZPRECONDITION(0);
157 return T_numtype();
158 }
159
160 template<int M>
162 BZPRECONDITION(0);
164 }
165
167 bool isVectorAligned(diffType offset) const {
168 return true; }
169
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
192 { BZPRECHECK(0,"Stencils of index expressions are not implemented");
193 return T_range_result(); }
194
195 void prettyPrint(std::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 =
213 ((N>0) ? ArraySectionInfo<T1>::rank : 0)
214 + ((N>1) ? ArraySectionInfo<T2>::rank : 0)
215 + ((N>2) ? ArraySectionInfo<T3>::rank : 0)
216 + ((N>3) ? ArraySectionInfo<T4>::rank : 0)
217 + ((N>4) ? ArraySectionInfo<T5>::rank : 0)
218 + ((N>5) ? ArraySectionInfo<T6>::rank : 0)
219 + ((N>6) ? ArraySectionInfo<T7>::rank : 0)
220 + ((N>7) ? ArraySectionInfo<T8>::rank : 0)
221 + ((N>8) ? ArraySectionInfo<T9>::rank : 0)
222 + ((N>9) ? ArraySectionInfo<T10>::rank : 0)
223 + ((N>10) ? ArraySectionInfo<T11>::rank : 0);
225 };
226
227 template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6,
228 typename T7, typename T8, typename T9, typename T10, typename T11>
230 operator()(T1 r1, T2 r2, T3 r3, T4 r4, T5 r5, T6 r6, T7 r7, T8 r8, T9 r9, T10 r10, T11 r11) const
231 {
232 // slicing of index placeholders is not implemented. there are
233 // two problems: First, if you slice the dimension of the index
234 // placeholder, it should be replaced with a constant. Second,
235 // if you restrict the range of that dimension, the index
236 // placeholder should start from a nonzero value.
237 BZPRECONDITION(0);
238 }
239};
240
252
253#ifndef BZ_NO_TENSOR_INDEX_OBJECTS
254
269
270#endif
271
272}
273
274#endif // BZ_INDEXEXPR_H
275
#define _bz_global
Definition blitz.h:93
Definition etbase.h:38
Definition tv2fastiter.h:383
Definition indexexpr.h:210
IndexPlaceholder< new_rank > T_slice
Definition indexexpr.h:224
static const int new_rank
Definition indexexpr.h:212
Definition tinymat2.h:65
void prettyPrint(std::string &str, prettyPrintFormat &) const
Definition indexexpr.h:195
IndexPlaceholder()
Definition indexexpr.h:50
bool isVectorAligned(diffType offset) const
There are no alignment issues here, so just return true.
Definition indexexpr.h:167
tvresult< M >::Type fastRead_tv(diffType) const
Definition indexexpr.h:161
static const int numArrayOperands
Definition indexexpr.h:78
T_result shift(int offset, int dim) const
Definition indexexpr.h:182
unwrapET< T_typeprop >::T_unwrapped T_result
Definition indexexpr.h:75
int T_numtype
Definition indexexpr.h:68
int T_range_result
Definition indexexpr.h:71
static const int numTVOperands
Definition indexexpr.h:79
void loadStride(int)
Definition indexexpr.h:129
T_result fastRead(diffType) const
Definition indexexpr.h:155
int ubound(int) const
Definition indexexpr.h:115
T_result operator()(const TinyVector< int, N_rank > &i) const
Definition indexexpr.h:109
int ascending(int) const
Definition indexexpr.h:112
bool isUnitStride() const
Definition indexexpr.h:138
void advance(int)
Definition indexexpr.h:128
RectDomain< rank_ > domain() const
Definition indexexpr.h:117
int operator*() const
Definition indexexpr.h:99
void operator=(const IndexPlaceholder< N > &)
Definition indexexpr.h:65
static const int numIndexPlaceholders
Definition indexexpr.h:81
diffType suggestStride(int) const
Definition indexexpr.h:170
static const int maxWidth
Definition indexexpr.h:83
~IndexPlaceholder()
Definition indexexpr.h:62
void advance()
Definition indexexpr.h:127
int ordering(int) const
Definition indexexpr.h:113
int T_ctorArg2
Definition indexexpr.h:70
bool canCollapse(int, int) const
Definition indexexpr.h:145
void _bz_offsetData(sizeType i)
Definition indexexpr.h:188
void pop(int)
Definition indexexpr.h:126
static const int rank_
Definition indexexpr.h:84
static const int numTMOperands
Definition indexexpr.h:80
void advanceUnitStride()
Definition indexexpr.h:143
opType< T_numtype >::T_optype T_optype
Definition indexexpr.h:73
IndexPlaceholder(const IndexPlaceholder< N > &)
Definition indexexpr.h:58
static const int minWidth
Definition indexexpr.h:82
T_range_result operator()(RectDomain< rank_ > d) const
Definition indexexpr.h:191
T_result shift(int offset1, int dim1, int offset2, int dim2) const
Definition indexexpr.h:185
void push(int)
Definition indexexpr.h:125
bool isUnitStride(int) const
Definition indexexpr.h:133
asET< T_numtype >::T_wrapped T_typeprop
Definition indexexpr.h:74
int T_ctorArg1
Definition indexexpr.h:69
bool isStride(int, diffType) const
Definition indexexpr.h:175
SliceInfo< T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11 >::T_slice operator()(T1 r1, T2 r2, T3 r3, T4 r4, T5 r5, T6 r6, T7 r7, T8 r8, T9 r9, T10 r10, T11 r11) const
Definition indexexpr.h:230
bool shapeCheck(const T_shape &) const
Definition indexexpr.h:201
int lbound(int) const
Definition indexexpr.h:114
T_result operator[](int) const
Definition indexexpr.h:150
void moveTo(const TinyVector< int, N_rank > &i)
Definition indexexpr.h:131
Definition range.h:58
The TinyVector class is a one-dimensional, fixed length vector that implements the blitz expression t...
Definition tinyvec2.h:73
Definition prettyprint.h:40
static const size_t vecWidth
SIMD width of types in number of elements.
Definition simdtypes.h:39
Definition indexexpr.h:255
_bz_global blitz::IndexPlaceholder< 5 > n
Definition indexexpr.h:261
_bz_global blitz::IndexPlaceholder< 1 > j
Definition indexexpr.h:257
_bz_global blitz::IndexPlaceholder< 0 > i
Definition indexexpr.h:256
_bz_global blitz::IndexPlaceholder< 10 > s
Definition indexexpr.h:266
_bz_global blitz::IndexPlaceholder< 8 > q
Definition indexexpr.h:264
_bz_global blitz::IndexPlaceholder< 2 > k
Definition indexexpr.h:258
_bz_global blitz::IndexPlaceholder< 4 > m
Definition indexexpr.h:260
_bz_global blitz::IndexPlaceholder< 6 > o
Definition indexexpr.h:262
_bz_global blitz::IndexPlaceholder< 3 > l
Definition indexexpr.h:259
_bz_global blitz::IndexPlaceholder< 7 > p
Definition indexexpr.h:263
_bz_global blitz::IndexPlaceholder< 9 > r
Definition indexexpr.h:265
_bz_global blitz::IndexPlaceholder< 11 > t
Definition indexexpr.h:267
Definition array-impl.h:66
IndexPlaceholder< 7 > eighthIndex
Definition indexexpr.h:248
IndexPlaceholder< 8 > ninthIndex
Definition indexexpr.h:249
IndexPlaceholder< 9 > tenthIndex
Definition indexexpr.h:250
IndexPlaceholder< 3 > fourthIndex
Definition indexexpr.h:244
IndexPlaceholder< 5 > sixthIndex
Definition indexexpr.h:246
ptrdiff_t diffType
Definition blitz.h:111
IndexPlaceholder< 0 > firstIndex
Definition indexexpr.h:241
IndexPlaceholder< 10 > eleventhIndex
Definition indexexpr.h:251
IndexPlaceholder< 1 > secondIndex
Definition indexexpr.h:242
size_t sizeType
Definition blitz.h:110
IndexPlaceholder< 2 > thirdIndex
Definition indexexpr.h:243
IndexPlaceholder< 4 > fifthIndex
Definition indexexpr.h:245
IndexPlaceholder< 6 > seventhIndex
Definition indexexpr.h:247
The vectorized return type for an IndexPlaceholder should be some form of range, but that's not usefu...
Definition indexexpr.h:91
FastTV2Iterator< T_numtype, M > Type
Definition indexexpr.h:92
#define BZ_NEW_EXPRESSION_TEMPLATES
Definition tuning.h:70