blitz  Version 1.0.2
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 
41 namespace blitz {
42 
43 template<int N>
44 class IndexPlaceholder
46  : public ETBase<IndexPlaceholder<N> >
47 #endif
48 {
49 public:
51  { }
52 
53 #ifdef BZ_NEW_EXPRESSION_TEMPLATES
55  : ETBase< IndexPlaceholder<N> >(x)
56  { }
57 #else
59  { }
60 #endif
61 
63  { }
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 
155  T_result fastRead(diffType) const {
156  BZPRECONDITION(0);
157  return T_numtype();
158  }
159 
160  template<int M>
162  BZPRECONDITION(0);
163  return TinyVector<T_numtype, M>();
164  }
165 
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(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 
255 namespace tensor {
268 } // tensor
269 
270 #endif
271 
272 }
273 
274 #endif // BZ_INDEXEXPR_H
275 
_bz_global blitz::IndexPlaceholder< 9 > r
Definition: indexexpr.h:265
IndexPlaceholder< 3 > fourthIndex
Definition: indexexpr.h:244
bool isVectorAligned(diffType offset) const
There are no alignment issues here, so just return true.
Definition: indexexpr.h:167
Definition: range.h:58
_bz_global blitz::IndexPlaceholder< 11 > t
Definition: indexexpr.h:267
IndexPlaceholder< 10 > eleventhIndex
Definition: indexexpr.h:251
IndexPlaceholder< 4 > fifthIndex
Definition: indexexpr.h:245
static const int numTMOperands
Definition: indexexpr.h:80
T_result shift(int offset, int dim) const
Definition: indexexpr.h:182
static const int minWidth
Definition: indexexpr.h:82
_bz_global blitz::IndexPlaceholder< 6 > o
Definition: indexexpr.h:262
_bz_global blitz::IndexPlaceholder< 0 > i
Definition: indexexpr.h:256
_bz_global blitz::IndexPlaceholder< 4 > m
Definition: indexexpr.h:260
Helper class that defines the width of the simd instructions for a given type.
Definition: simdtypes.h:31
IndexPlaceholder< 1 > secondIndex
Definition: indexexpr.h:242
diffType suggestStride(int) const
Definition: indexexpr.h:170
_bz_global blitz::IndexPlaceholder< 1 > j
Definition: indexexpr.h:257
_bz_global blitz::IndexPlaceholder< 8 > q
Definition: indexexpr.h:264
void advance(int)
Definition: indexexpr.h:128
~IndexPlaceholder()
Definition: indexexpr.h:62
T_result operator()(const TinyVector< int, N_rank > &i) const
Definition: indexexpr.h:109
T_result fastRead(diffType) const
Definition: indexexpr.h:155
int ascending(int) const
Definition: indexexpr.h:112
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
IndexPlaceholder(const IndexPlaceholder< N > &)
Definition: indexexpr.h:58
static const int rank_
Definition: indexexpr.h:84
bool canCollapse(int, int) const
Definition: indexexpr.h:145
Definition: et-forward.h:10
bool isStride(int, diffType) const
Definition: indexexpr.h:175
IndexPlaceholder< 7 > eighthIndex
Definition: indexexpr.h:248
bool shapeCheck(const T_shape &) const
Definition: indexexpr.h:201
T_result operator[](int) const
Definition: indexexpr.h:150
void operator=(const IndexPlaceholder< N > &)
Definition: indexexpr.h:65
tvresult< M >::Type fastRead_tv(diffType) const
Definition: indexexpr.h:161
opType< T_numtype >::T_optype T_optype
Definition: indexexpr.h:73
#define _bz_global
Definition: blitz.h:93
RectDomain< rank_ > domain() const
Definition: indexexpr.h:117
void advanceUnitStride()
Definition: indexexpr.h:143
Definition: et-forward.h:20
IndexPlaceholder< new_rank > T_slice
Definition: indexexpr.h:224
static const int numIndexPlaceholders
Definition: indexexpr.h:81
Definition: array-impl.h:66
Definition: et-forward.h:48
ptrdiff_t diffType
Definition: blitz.h:111
void push(int)
Definition: indexexpr.h:125
IndexPlaceholder()
Definition: indexexpr.h:50
void advance()
Definition: indexexpr.h:127
IndexPlaceholder< 8 > ninthIndex
Definition: indexexpr.h:249
IndexPlaceholder< 0 > firstIndex
Definition: indexexpr.h:241
static const int new_rank
Definition: indexexpr.h:212
unwrapET< T_typeprop >::T_unwrapped T_result
Definition: indexexpr.h:75
int T_numtype
Definition: indexexpr.h:68
int ubound(int) const
Definition: indexexpr.h:115
int lbound(int) const
Definition: indexexpr.h:114
int T_ctorArg1
Definition: indexexpr.h:69
#define BZ_NEW_EXPRESSION_TEMPLATES
Definition: tuning.h:70
size_t sizeType
Definition: blitz.h:110
static const int maxWidth
Definition: indexexpr.h:83
_bz_global blitz::IndexPlaceholder< 2 > k
Definition: indexexpr.h:258
void prettyPrint(std::string &str, prettyPrintFormat &) const
Definition: indexexpr.h:195
void loadStride(int)
Definition: indexexpr.h:129
static const int numTVOperands
Definition: indexexpr.h:79
bool isUnitStride() const
Definition: indexexpr.h:138
int T_range_result
Definition: indexexpr.h:71
_bz_global blitz::IndexPlaceholder< 3 > l
Definition: indexexpr.h:259
IndexPlaceholder< 6 > seventhIndex
Definition: indexexpr.h:247
asET< T_numtype >::T_wrapped T_typeprop
Definition: indexexpr.h:74
IndexPlaceholder< 5 > sixthIndex
Definition: indexexpr.h:246
T_result shift(int offset1, int dim1, int offset2, int dim2) const
Definition: indexexpr.h:185
T_range_result operator()(RectDomain< rank_ > d) const
Definition: indexexpr.h:191
Definition: indexexpr.h:210
FastTV2Iterator< T_numtype, M > Type
Definition: indexexpr.h:92
int ordering(int) const
Definition: indexexpr.h:113
int T_ctorArg2
Definition: indexexpr.h:70
IndexPlaceholder< 2 > thirdIndex
Definition: indexexpr.h:243
IndexPlaceholder< 9 > tenthIndex
Definition: indexexpr.h:250
_bz_global blitz::IndexPlaceholder< 10 > s
Definition: indexexpr.h:266
bool isUnitStride(int) const
Definition: indexexpr.h:133
_bz_global blitz::IndexPlaceholder< 5 > n
Definition: indexexpr.h:261
_bz_global blitz::IndexPlaceholder< 7 > p
Definition: indexexpr.h:263
int operator*() const
Definition: indexexpr.h:99
void _bz_offsetData(sizeType i)
Definition: indexexpr.h:188
void pop(int)
Definition: indexexpr.h:126
void moveTo(const TinyVector< int, N_rank > &i)
Definition: indexexpr.h:131
static const int numArrayOperands
Definition: indexexpr.h:78
Definition: prettyprint.h:40
The vectorized return type for an IndexPlaceholder should be some form of range, but that's not usefu...
Definition: indexexpr.h:91