blitz  Version 1.0.2
levicivita.h
Go to the documentation of this file.
1 #ifndef BZ_LEVICIVITA_H
2 #define BZ_LEVICIVITA_H
3 
4 #include <blitz/prettyprint.h>
5 #include <blitz/shapecheck.h>
6 #include <blitz/numinquire.h>
7 #include <blitz/array/domain.h>
8 #include <blitz/etbase.h>
9 #include <blitz/tinyvec2io.cc>
10 
11 namespace blitz {
12 
13 /* Defines an object which represents the 3-dimensional
14  levi-civita symbol used for cross products. That way the cross
15  product can be represented as an expression. */
16 class LeviCivita : public ETBase<LeviCivita> {
17 public:
18  typedef char T_numtype;
19 
20  typedef opType<T_numtype>::T_optype T_optype;
21  typedef asET<T_numtype>::T_wrapped T_typeprop;
22  typedef unwrapET<T_typeprop>::T_unwrapped T_result;
23 
24  typedef void T_ctorArg1;
25  typedef char T_ctorArg2; // dummy
28  static const int
35  rank_ = 3;
36 
37  // copy constructor and default constructors are implicit
38 
39  int ascending(const int) const { return true; }
40  int ordering(const int) const { return INT_MIN; }
41  int lbound(const int) const { return 0; }
42  int ubound(const int) const { return 2; }
43 
45  {
48  }
49 
50  T_numtype operator*() const { BZPRECONDITION(0); return 0; }
51  T_numtype first_value() const { BZPRECONDITION(0); return 0; }
52 
53  bool assertInRange(const T_index& BZ_DEBUG_PARAM(index)) const {
54  BZPRECHECK((index[0]<3) && (index[0]>=0) &&
55  (index[1]<3) && (index[1]>=0) &&
56  (index[2]<3) && (index[2]>=0),
57  "LeviCivita index out of range: " << index
58  << endl << "Lower bounds: 0" << endl
59  << "Length: 3" << endl);
60  return true;
61  }
62 
63 #ifdef BZ_ARRAY_EXPR_PASS_INDEX_BY_VALUE
64  template<int N_rank>
65  T_numtype operator()(const TinyVector<int,N_rank> i) const
66  { assertInRange(i); return (i[1]-i[0])*(i[2]-i[0])*(i[2]-i[1])/2; }
67 #else
68  template<int N_rank>
69  T_numtype operator()(const TinyVector<int,N_rank>& i) const
70  { assertInRange(i); return (i[1]-i[0])*(i[2]-i[0])*(i[2]-i[1])/2; }
71 #endif
72 
73  // can't set domain
74  template<int N_rank>
76  {
77  BZPRECONDITION(0); return *this;
78  }
79 
80  void push(int) { }
81  void pop(int) { }
82  void advance() { }
83  void advance(int) { }
84  void loadStride(int) { }
85 
86  bool isUnitStride(int) const
87  { return true; }
88 
90  { }
91 
92  bool canCollapse(int,int) const
93  { return true; }
94 
95  T_numtype operator[](int) const
96  { BZPRECONDITION(0); return 0; }
97 
98  T_numtype fastRead(diffType) const
99  { BZPRECONDITION(0); return 0; }
100 
101  T_numtype fastRead_tv(diffType) const
102  { BZPRECONDITION(0); return 0; }
103 
104  // this is needed for the stencil expression fastRead to work
105  void _bz_offsetData(sizeType i) const{BZPRECONDITION(0);};
106 
107  // and these are needed for stencil expression shift to work
108  void _bz_offsetData(sizeType offset, int dim) const {BZPRECONDITION(0);};
109 
110  void _bz_offsetData(sizeType offset1, int dim1, sizeType offset2, int dim2) const {BZPRECONDITION(0);};
111 
113  { return 1; }
114 
115  bool isStride(int,diffType) const
116  { return true; }
117 
118  void moveTo(int) const { BZPRECONDITION(0); }
119 
120  T_numtype shift(int offset, int dim) const {
121  BZPRECONDITION(0); return T_numtype(); }
122 
123  T_numtype shift(int offset1, int dim1,int offset2, int dim2) const
124  { BZPRECONDITION(0); return T_numtype();}
125 
126  template<int N_rank>
127  void moveTo(const TinyVector<int,N_rank>&) const { BZPRECONDITION(0); }
128 
129  void prettyPrint(std::string &str,
130  prettyPrintFormat& format) const
131  {
132  str += "epsilon_ijk";
133  }
134 
135  template<typename T_shape>
136  bool shapeCheck(const T_shape& shape) const
137  { return areShapesConformable(shape, TinyVector<int,3>(3,3,3)); }
138 
139 
140  // we can't reduce the rank of this object, so we can't slice it
141  template<typename T1, typename T2 = nilArraySection,
142  class T3 = nilArraySection, typename T4 = nilArraySection,
143  class T5 = nilArraySection, typename T6 = nilArraySection,
144  class T7 = nilArraySection, typename T8 = nilArraySection,
145  class T9 = nilArraySection, typename T10 = nilArraySection,
146  class T11 = nilArraySection>
147  class SliceInfo {
148  public:
149  typedef void T_slice;
150 };
151 
152  template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6,
153  typename T7, typename T8, typename T9, typename T10, typename T11>
155  operator()(T1 r1, T2 r2, T3 r3, T4 r4, T5 r5, T6 r6, T7 r7, T8 r8, T9 r9, T10 r10, T11 r11) const
156  {
157  return *this;
158  }
159 };
160 
161 }
162 
163 #endif
void push(int)
Definition: levicivita.h:80
static const int numTMOperands
Definition: levicivita.h:31
void _bz_offsetData(sizeType i) const
Definition: levicivita.h:105
Definition: range.h:58
void loadStride(int)
Definition: levicivita.h:84
_bz_global blitz::IndexPlaceholder< 0 > i
Definition: indexexpr.h:256
bool canCollapse(int, int) const
Definition: levicivita.h:92
Helper class that defines the width of the simd instructions for a given type.
Definition: simdtypes.h:31
static const int rank_
Definition: levicivita.h:35
void prettyPrint(std::string &str, prettyPrintFormat &format) const
Definition: levicivita.h:129
T_numtype fastRead_tv(diffType) const
Definition: levicivita.h:101
diffType suggestStride(int) const
Definition: levicivita.h:112
static const int maxWidth
Definition: levicivita.h:34
void advanceUnitStride()
Definition: levicivita.h:89
void moveTo(int) const
Definition: levicivita.h:118
T_numtype operator*() const
Definition: levicivita.h:50
static const int numArrayOperands
Definition: levicivita.h:29
const LeviCivita operator()(const RectDomain< N_rank > &d) const
Definition: levicivita.h:75
static const int numTVOperands
Definition: levicivita.h:30
Definition: et-forward.h:10
asET< T_numtype >::T_wrapped T_typeprop
Definition: levicivita.h:21
bool shapeCheck(const T_shape &shape) const
Definition: levicivita.h:136
static const int minWidth
Definition: levicivita.h:33
RectDomain< rank_ > domain() const
Definition: levicivita.h:44
T_numtype fastRead(diffType) const
Definition: levicivita.h:98
Definition: array-impl.h:66
T_numtype operator[](int) const
Definition: levicivita.h:95
ptrdiff_t diffType
Definition: blitz.h:111
bool isUnitStride(int) const
Definition: levicivita.h:86
bool areShapesConformable(const T_shape1 &, const T_shape2 &)
Definition: shapecheck.h:50
T_numtype shift(int offset1, int dim1, int offset2, int dim2) const
Definition: levicivita.h:123
char T_ctorArg2
Definition: levicivita.h:25
size_t sizeType
Definition: blitz.h:110
static const int numIndexPlaceholders
Definition: levicivita.h:32
T_numtype first_value() const
Definition: levicivita.h:51
opType< T_numtype >::T_optype T_optype
Definition: levicivita.h:20
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: levicivita.h:155
int ascending(const int) const
Definition: levicivita.h:39
char T_numtype
Definition: levicivita.h:18
void _bz_offsetData(sizeType offset1, int dim1, sizeType offset2, int dim2) const
Definition: levicivita.h:110
int ubound(const int) const
Definition: levicivita.h:42
TinyVector< int, 3 > T_index
Definition: levicivita.h:26
unwrapET< T_typeprop >::T_unwrapped T_result
Definition: levicivita.h:22
bool isStride(int, diffType) const
Definition: levicivita.h:115
int ordering(const int) const
Definition: levicivita.h:40
void T_ctorArg1
Definition: levicivita.h:24
void T_slice
Definition: levicivita.h:149
void pop(int)
Definition: levicivita.h:81
T_numtype shift(int offset, int dim) const
Definition: levicivita.h:120
int lbound(const int) const
Definition: levicivita.h:41
void _bz_offsetData(sizeType offset, int dim) const
Definition: levicivita.h:108
void moveTo(const TinyVector< int, N_rank > &) const
Definition: levicivita.h:127
Definition: levicivita.h:147
The TinyVector class is a one-dimensional, fixed length vector that implements the blitz expression t...
Definition: et-forward.h:14
void advance(int)
Definition: levicivita.h:83
bool assertInRange(const T_index &BZ_DEBUG_PARAM(index)) const
Definition: levicivita.h:53
void advance()
Definition: levicivita.h:82
T_numtype operator()(const TinyVector< int, N_rank > &i) const
Definition: levicivita.h:69
LeviCivita T_range_result
Definition: levicivita.h:27
Definition: prettyprint.h:40
Definition: levicivita.h:16