blitz/indexexpr.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 /***************************************************************************
00003  * blitz/indexexpr.h     Declaration of the IndexPlaceholder<N> class
00004  *
00005  * $Id: indexexpr.h,v 1.7 2005/05/07 04:17:56 julianc Exp $
00006  *
00007  * Copyright (C) 1997-2001 Todd Veldhuizen <tveldhui@oonumerics.org>
00008  *
00009  * This program is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU General Public License
00011  * as published by the Free Software Foundation; either version 2
00012  * of the License, or (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * Suggestions:          blitz-dev@oonumerics.org
00020  * Bugs:                 blitz-bugs@oonumerics.org
00021  *
00022  * For more information, please see the Blitz++ Home Page:
00023  *    p://seurat.uhttwaterloo.ca/blitz/
00024  *
00025  ***************************************************************************/
00026 
00027 #ifndef BZ_INDEXEXPR_H
00028 #define BZ_INDEXEXPR_H
00029 
00030 #include <blitz/tinyvec.h>
00031 #include <blitz/prettyprint.h>
00032 #include <blitz/etbase.h>
00033 
00034 BZ_NAMESPACE(blitz)
00035 
00036 template<int N>
00037 class IndexPlaceholder 
00038 #ifdef BZ_NEW_EXPRESSION_TEMPLATES
00039   : public ETBase<IndexPlaceholder<N> > 
00040 #endif
00041 {
00042 public:
00043     IndexPlaceholder()
00044     { }
00045 
00046 #ifdef BZ_NEW_EXPRESSION_TEMPLATES
00047     IndexPlaceholder(const IndexPlaceholder<N>& x)
00048         : ETBase< IndexPlaceholder<N> >(x)
00049     { }
00050 #else
00051     IndexPlaceholder(const IndexPlaceholder<N>&)
00052     { }
00053 #endif
00054 
00055     ~IndexPlaceholder()
00056     { }
00057 
00058     void operator=(const IndexPlaceholder<N>&)
00059     { }
00060 
00061     typedef int T_numtype;
00062     typedef int T_ctorArg1;     // Dummy; not used
00063     typedef int T_ctorArg2;     // Ditto
00064 
00065     static const int 
00066         numArrayOperands = 0, 
00067         numIndexPlaceholders = 1,
00068         rank = N+1;
00069 
00070     // If you have a precondition failure on this routine, it means
00071     // you are trying to use stack iteration mode on an expression
00072     // which contains an index placeholder.  You must use index 
00073     // iteration mode instead.
00074     int operator*() { 
00075         BZPRECONDITION(0); 
00076         return 0;
00077     }
00078 
00079 #ifdef BZ_ARRAY_EXPR_PASS_INDEX_BY_VALUE
00080     template<int N_rank>
00081     T_numtype operator()(TinyVector<int, N_rank> i) { return i[N]; }
00082 #else
00083     template<int N_rank>
00084     T_numtype operator()(const TinyVector<int, N_rank>& i) { return i[N]; }
00085 #endif
00086 
00087     int ascending(int) const { return INT_MIN; }
00088     int ordering(int)  const { return INT_MIN; }
00089     int lbound(int)    const { return INT_MIN; }  // tiny(int());
00090     int ubound(int)    const { return INT_MAX; }  // huge(int()); 
00091 
00092     // See operator*() note
00093 
00094     void push(int)       { BZPRECONDITION(0); }
00095     void pop(int)        { BZPRECONDITION(0); }
00096     void advance()       { BZPRECONDITION(0); }
00097     void advance(int)    { BZPRECONDITION(0); }
00098     void loadStride(int) { BZPRECONDITION(0); }
00099 
00100     bool isUnitStride(int) const { 
00101         BZPRECONDITION(0);
00102         return false;
00103     }
00104 
00105     void advanceUnitStride() { BZPRECONDITION(0); }
00106 
00107     bool canCollapse(int,int) const {   
00108         BZPRECONDITION(0); 
00109         return false; 
00110     }
00111 
00112     T_numtype operator[](int) {
00113         BZPRECONDITION(0);
00114         return T_numtype();
00115     }
00116 
00117     T_numtype fastRead(int) {
00118         BZPRECONDITION(0);
00119         return T_numtype();
00120     }
00121 
00122     int suggestStride(int) const {
00123         BZPRECONDITION(0);
00124         return 0;
00125     }
00126 
00127     bool isStride(int,int) const {
00128         BZPRECONDITION(0);
00129         return true;
00130     }
00131 
00132     void prettyPrint(BZ_STD_SCOPE(string) &str, prettyPrintFormat&) const {
00133         // NEEDS_WORK-- do real formatting for reductions
00134         str += "index-expr[NEEDS_WORK]";
00135     }
00136 
00137     template<typename T_shape>
00138     bool shapeCheck(const T_shape&) const { return true; }
00139 };
00140 
00141 typedef IndexPlaceholder<0> firstIndex;
00142 typedef IndexPlaceholder<1> secondIndex;
00143 typedef IndexPlaceholder<2> thirdIndex;
00144 typedef IndexPlaceholder<3> fourthIndex;
00145 typedef IndexPlaceholder<4> fifthIndex;
00146 typedef IndexPlaceholder<5> sixthIndex;
00147 typedef IndexPlaceholder<6> seventhIndex;
00148 typedef IndexPlaceholder<7> eighthIndex;
00149 typedef IndexPlaceholder<8> ninthIndex;
00150 typedef IndexPlaceholder<9> tenthIndex;
00151 typedef IndexPlaceholder<10> eleventhIndex;
00152 
00153 #ifndef BZ_NO_TENSOR_INDEX_OBJECTS
00154 
00155 BZ_NAMESPACE(tensor)
00156     _bz_global blitz::IndexPlaceholder<0> i;
00157     _bz_global blitz::IndexPlaceholder<1> j;
00158     _bz_global blitz::IndexPlaceholder<2> k;
00159     _bz_global blitz::IndexPlaceholder<3> l;
00160     _bz_global blitz::IndexPlaceholder<4> m;
00161     _bz_global blitz::IndexPlaceholder<5> n;
00162     _bz_global blitz::IndexPlaceholder<6> o;
00163     _bz_global blitz::IndexPlaceholder<7> p;
00164     _bz_global blitz::IndexPlaceholder<8> q;
00165     _bz_global blitz::IndexPlaceholder<9> r;
00166     _bz_global blitz::IndexPlaceholder<10> s;
00167     _bz_global blitz::IndexPlaceholder<11> t;
00168 BZ_NAMESPACE_END // tensor
00169 
00170 #endif
00171 
00172 BZ_NAMESPACE_END
00173 
00174 #endif // BZ_INDEXEXPR_H
00175 

Generated on Wed Oct 17 16:27:10 2007 for blitz by  doxygen 1.5.2