blitz Version 0.10
|
00001 // -*- C++ -*- 00002 /*************************************************************************** 00003 * blitz/indexexpr.h Declaration of the IndexPlaceholder<N> class 00004 * 00005 * $Id: indexexpr.h,v 1.10 2011/03/25 22:41:16 julianc Exp $ 00006 * 00007 * Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org> 00008 * 00009 * This file is a part of Blitz. 00010 * 00011 * Blitz is free software: you can redistribute it and/or modify 00012 * it under the terms of the GNU Lesser General Public License 00013 * as published by the Free Software Foundation, either version 3 00014 * of the License, or (at your option) any later version. 00015 * 00016 * Blitz is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Lesser General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU Lesser General Public 00022 * License along with Blitz. If not, see <http://www.gnu.org/licenses/>. 00023 * 00024 * Suggestions: blitz-devel@lists.sourceforge.net 00025 * Bugs: blitz-support@lists.sourceforge.net 00026 * 00027 * For more information, please see the Blitz++ Home Page: 00028 * https://sourceforge.net/projects/blitz/ 00029 * 00030 ***************************************************************************/ 00031 00032 #ifndef BZ_INDEXEXPR_H 00033 #define BZ_INDEXEXPR_H 00034 00035 #include <blitz/tinyvec.h> 00036 #include <blitz/prettyprint.h> 00037 #include <blitz/etbase.h> 00038 #include <blitz/array/domain.h> 00039 #include <blitz/array/slice.h> 00040 00041 BZ_NAMESPACE(blitz) 00042 00043 template<int N> 00044 class IndexPlaceholder 00045 #ifdef BZ_NEW_EXPRESSION_TEMPLATES 00046 : public ETBase<IndexPlaceholder<N> > 00047 #endif 00048 { 00049 public: 00050 IndexPlaceholder() 00051 { } 00052 00053 #ifdef BZ_NEW_EXPRESSION_TEMPLATES 00054 IndexPlaceholder(const IndexPlaceholder<N>& x) 00055 : ETBase< IndexPlaceholder<N> >(x) 00056 { } 00057 #else 00058 IndexPlaceholder(const IndexPlaceholder<N>&) 00059 { } 00060 #endif 00061 00062 ~IndexPlaceholder() 00063 { } 00064 00065 void operator=(const IndexPlaceholder<N>&) 00066 { } 00067 00068 typedef int T_numtype; 00069 typedef int T_ctorArg1; // Dummy; not used 00070 typedef int T_ctorArg2; // Ditto 00071 typedef int T_range_result; // dummy 00072 00073 static const int 00074 numArrayOperands = 0, 00075 numIndexPlaceholders = 1, 00076 rank = N+1; 00077 00078 // If you have a precondition failure on this routine, it means 00079 // you are trying to use stack iteration mode on an expression 00080 // which contains an index placeholder. You must use index 00081 // iteration mode instead. 00082 int operator*() const { 00083 BZPRECONDITION(0); 00084 return 0; 00085 } 00086 00087 #ifdef BZ_ARRAY_EXPR_PASS_INDEX_BY_VALUE 00088 template<int N_rank> 00089 T_numtype operator()(TinyVector<int, N_rank> i) const { return i[N]; } 00090 #else 00091 template<int N_rank> 00092 T_numtype operator()(const TinyVector<int, N_rank>& i) const { return i[N]; } 00093 #endif 00094 00095 int ascending(int) const { return INT_MIN; } 00096 int ordering(int) const { return INT_MIN; } 00097 int lbound(int) const { return INT_MIN; } // tiny(int()); 00098 int ubound(int) const { return INT_MAX; } // huge(int()); 00099 00100 RectDomain<rank> domain() const 00101 { 00102 const TinyVector<int, rank> lb(lbound(0)), ub(ubound(0)); 00103 return RectDomain<rank>(lb,ub); 00104 } 00105 00106 // See operator*() note 00107 00108 void push(int) { BZPRECONDITION(0); } 00109 void pop(int) { BZPRECONDITION(0); } 00110 void advance() { BZPRECONDITION(0); } 00111 void advance(int) { BZPRECONDITION(0); } 00112 void loadStride(int) { BZPRECONDITION(0); } 00113 template<int N_rank> 00114 void moveTo(const TinyVector<int,N_rank>& i) { BZPRECONDITION(0); } 00115 00116 bool isUnitStride(int) const { 00117 BZPRECONDITION(0); 00118 return false; 00119 } 00120 00121 void advanceUnitStride() { BZPRECONDITION(0); } 00122 00123 bool canCollapse(int,int) const { 00124 BZPRECONDITION(0); 00125 return false; 00126 } 00127 00128 T_numtype operator[](int) const { 00129 BZPRECONDITION(0); 00130 return T_numtype(); 00131 } 00132 00133 T_numtype fastRead(int) const { 00134 BZPRECONDITION(0); 00135 return T_numtype(); 00136 } 00137 00138 diffType suggestStride(int) const { 00139 BZPRECONDITION(0); 00140 return 0; 00141 } 00142 00143 bool isStride(int,diffType) const { 00144 BZPRECONDITION(0); 00145 return true; 00146 } 00147 00148 // don't know how to define shift, as it relies on having an 00149 // implicit position. thus stencils won't work 00150 T_numtype shift(int offset, int dim) const 00151 { BZPRECONDITION(0); return T_numtype(); } 00152 T_numtype shift(int offset1, int dim1,int offset2, int dim2) const { 00153 BZPRECONDITION(0); return T_numtype(); } 00154 void _bz_offsetData(sizeType i) { BZPRECONDITION(0); } 00155 00156 // Unclear how to define this, and stencils don't work anyway 00157 T_range_result operator()(RectDomain<rank> d) const 00158 { BZPRECONDITION(0); } 00159 00160 void prettyPrint(BZ_STD_SCOPE(string) &str, prettyPrintFormat&) const { 00161 // NEEDS_WORK-- do real formatting for reductions 00162 str += "index-expr[NEEDS_WORK]"; 00163 } 00164 00165 template<typename T_shape> 00166 bool shapeCheck(const T_shape&) const { return true; } 00167 00168 // sliceinfo for index placeholder does nothing 00169 template<typename T1, typename T2 = nilArraySection, 00170 class T3 = nilArraySection, typename T4 = nilArraySection, 00171 class T5 = nilArraySection, typename T6 = nilArraySection, 00172 class T7 = nilArraySection, typename T8 = nilArraySection, 00173 class T9 = nilArraySection, typename T10 = nilArraySection, 00174 class T11 = nilArraySection> 00175 class SliceInfo { 00176 public: 00177 static const int new_rank = (N>0) ? ArraySectionInfo<T1>::rank : 0 00178 + (N>1) ? ArraySectionInfo<T2>::rank : 0 00179 + (N>2) ? ArraySectionInfo<T3>::rank : 0 00180 + (N>4) ? ArraySectionInfo<T4>::rank : 0 00181 + (N>5) ? ArraySectionInfo<T5>::rank : 0 00182 + (N>6) ? ArraySectionInfo<T6>::rank : 0 00183 + (N>7) ? ArraySectionInfo<T7>::rank : 0 00184 + (N>8) ? ArraySectionInfo<T8>::rank : 0 00185 + (N>9) ? ArraySectionInfo<T9>::rank : 0 00186 + (N>10) ? ArraySectionInfo<T10>::rank : 0 00187 + (N>11) ? ArraySectionInfo<T11>::rank : 0; 00188 typedef IndexPlaceholder<new_rank> T_slice; 00189 }; 00190 00191 template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, 00192 typename T7, typename T8, typename T9, typename T10, typename T11> 00193 typename SliceInfo<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11>::T_slice 00194 operator()(T1 r1, T2 r2, T3 r3, T4 r4, T5 r5, T6 r6, T7 r7, T8 r8, T9 r9, T10 r10, T11 r11) const 00195 { 00196 // slicing of index placeholders is not implemented. there are 00197 // two problems: First, if you slice the dimension of the index 00198 // placeholder, it should be replaced with a constant. Second, 00199 // if you restrict the range of that dimension, the index 00200 // placeholder should start from a nonzero value. 00201 BZPRECONDITION(0); 00202 } 00203 }; 00204 00205 typedef IndexPlaceholder<0> firstIndex; 00206 typedef IndexPlaceholder<1> secondIndex; 00207 typedef IndexPlaceholder<2> thirdIndex; 00208 typedef IndexPlaceholder<3> fourthIndex; 00209 typedef IndexPlaceholder<4> fifthIndex; 00210 typedef IndexPlaceholder<5> sixthIndex; 00211 typedef IndexPlaceholder<6> seventhIndex; 00212 typedef IndexPlaceholder<7> eighthIndex; 00213 typedef IndexPlaceholder<8> ninthIndex; 00214 typedef IndexPlaceholder<9> tenthIndex; 00215 typedef IndexPlaceholder<10> eleventhIndex; 00216 00217 #ifndef BZ_NO_TENSOR_INDEX_OBJECTS 00218 00219 BZ_NAMESPACE(tensor) 00220 _bz_global blitz::IndexPlaceholder<0> i; 00221 _bz_global blitz::IndexPlaceholder<1> j; 00222 _bz_global blitz::IndexPlaceholder<2> k; 00223 _bz_global blitz::IndexPlaceholder<3> l; 00224 _bz_global blitz::IndexPlaceholder<4> m; 00225 _bz_global blitz::IndexPlaceholder<5> n; 00226 _bz_global blitz::IndexPlaceholder<6> o; 00227 _bz_global blitz::IndexPlaceholder<7> p; 00228 _bz_global blitz::IndexPlaceholder<8> q; 00229 _bz_global blitz::IndexPlaceholder<9> r; 00230 _bz_global blitz::IndexPlaceholder<10> s; 00231 _bz_global blitz::IndexPlaceholder<11> t; 00232 BZ_NAMESPACE_END // tensor 00233 00234 #endif 00235 00236 BZ_NAMESPACE_END 00237 00238 #endif // BZ_INDEXEXPR_H 00239