TinyMatrixExpression.hxx
1 #ifndef SELDON_FILE_TINY_MATRIX_EXPRESSION_HXX
2 
3 namespace Seldon
4 {
5 
7  template<class T, int m, int n, class E>
9  {
10  public:
11  const T operator()(int, int) const;
12 
13  inline operator E&() { return static_cast<E&>(*this); }
14  inline operator E const&() const { return static_cast<const E&>(*this); }
15 
16  };
17 
18 
20  template<class T, int m, int n, class E1, class E2>
21  class TinyMatrixDifference : public TinyMatrixExpression<T, m, n, TinyMatrixDifference<T, m, n, E1, E2> >
22  {
23  const E1& u_;
24  const E2& v_;
25 
26  public:
27  template<class T1, class T2>
29 
30  const T operator()(int, int) const;
31 
32  };
33 
34 
36  template<class T, int m, int n, class E1, class E2>
37  class TinyMatrixSum : public TinyMatrixExpression<T, m, n, TinyMatrixSum<T, m, n, E1, E2> >
38  {
39  const E1& u_;
40  const E2& v_;
41 
42  public:
43  template<class T1, class T2>
45 
46  const T operator()(int, int) const;
47 
48  };
49 
50 
52  template<class T, int m, int n, class E1, class E2>
53  class TinyMatrixProduct : public TinyMatrixExpression<T, m, n, TinyMatrixProduct<T, m, n, E1, E2> >
54  {
55  const E1& u_;
56  const E2& v_;
57 
58  public:
59  template<class T1, class T2>
61 
62  const T operator()(int, int) const;
63 
64  };
65 
66 
68  template<class T, int m, int n, class E1, class E2>
69  class TinyMatrixDivision : public TinyMatrixExpression<T, m, n, TinyMatrixDivision<T, m, n, E1, E2> >
70  {
71  const E1& u_;
72  const E2& v_;
73 
74  public:
75  template<class T1, class T2>
77 
78  const T operator()(int, int) const;
79 
80  };
81 
82 
84  template<class T, int m, int n, class T0, class E>
85  class TinyMatrixScaled : public TinyMatrixExpression<T, m, n, TinyMatrixScaled<T, m, n, T0, E> >
86  {
87  const T0 alpha_;
88  const E& u_;
89 
90  public:
91  template<class T1>
93 
94  const T operator()(int, int) const;
95 
96  };
97 
98 
100  template<class T, int m, int n, class T0, class E>
101  class TinyMatrixScalDiv : public TinyMatrixExpression<T, m, n, TinyMatrixScalDiv<T, m, n, T0, E> >
102  {
103  const T0 alpha_;
104  const E& u_;
105 
106  public:
107  template<class T1>
109 
110  const T operator()(int, int) const;
111 
112  };
113 
114 
116  template<class T, int m, int n, class T0, class E>
117  class TinyMatrixScalSum : public TinyMatrixExpression<T, m, n, TinyMatrixScalSum<T, m, n, T0, E> >
118  {
119  const T0 alpha_;
120  const E& u_;
121 
122  public:
123  template<class T1>
125 
126  const T operator()(int, int) const;
127 
128  };
129 
130 
132  template<class T, int m, int n, class T0, class E>
133  class TinyMatrixScalDiff : public TinyMatrixExpression<T, m, n, TinyMatrixScalDiff<T, m, n, T0, E> >
134  {
135  const T0 alpha_;
136  const E& u_;
137 
138  public:
139  template<class T1>
141 
142  const T operator()(int, int) const;
143 
144  };
145 
146 
148  template<class T, int m, int n, class E>
149  class TinyMatrixOpposite : public TinyMatrixExpression<T, m, n, TinyMatrixOpposite<T, m, n, E> >
150  {
151  const E& u_;
152 
153  public:
155 
156  const T operator()(int, int) const;
157 
158  };
159 
160 
162  template<class T, int m, int n, class E>
163  class TinyMatrixTranspose : public TinyMatrixExpression<T, m, n, TinyMatrixTranspose<T, m, n, E> >
164  {
165  const E& u_;
166 
167  public:
169 
170  const T operator()(int, int) const;
171 
172  };
173 
174 
175  /*************
176  * Operators *
177  *************/
178 
179 
180  template<class T, int m, int n, class E1, class E2>
184 
185  template<class T, int m, int n, class E1, class E2>
186  const TinyMatrixSum<complex<T>, m, n, E1, E2>
187  operator +(const TinyMatrixExpression<complex<T>, m, n, E1>& u,
189 
190  template<class T, int m, int n, class E1, class E2>
191  const TinyMatrixSum<complex<T>, m, n, E1, E2>
193  const TinyMatrixExpression<complex<T>, m, n, E2>& v);
194 
195  template<class T, int m, int n, class E1, class E2>
199 
200  template<class T, int m, int n, class E1, class E2>
201  inline const TinyMatrixDifference<complex<T>, m, n, E1, E2>
202  operator -(const TinyMatrixExpression<complex<T>, m, n, E1>& u,
204 
205  template<class T, int m, int n, class E1, class E2>
206  const TinyMatrixDifference<complex<T>, m, n, E1, E2>
208  const TinyMatrixExpression<complex<T>, m, n, E2>& v);
209 
210  template<class T, int m, int n, class E1, class E2>
214 
215  template<class T, int m, int n, class E1, class E2>
216  const TinyMatrixProduct<complex<T>, m, n, E1, E2>
217  operator *(const TinyMatrixExpression<complex<T>, m, n, E1>& u,
219 
220  template<class T, int m, int n, class E1, class E2>
221  const TinyMatrixProduct<complex<T>, m, n, E1, E2>
223  const TinyMatrixExpression<complex<T>, m, n, E2>& v);
224 
225  template<class T, int m, int n, class E1, class E2>
229 
230  template<class T, int m, int n, class E1, class E2>
231  const TinyMatrixDivision<complex<T>, m, n, E1, E2>
232  operator /(const TinyMatrixExpression<complex<T>, m, n, E1>& u,
234 
235  template<class T, int m, int n, class E1, class E2>
236  const TinyMatrixDivision<complex<T>, m, n, E1, E2>
238  const TinyMatrixExpression<complex<T>, m, n, E2>& v);
239 
240  template<class T, int m, int n, class E>
241  const TinyMatrixScaled<T, m, n, T, E> operator *(const T& alpha,
243 
244  template<class T, int m, int n, class E>
245  const TinyMatrixScaled<complex<T>, m, n, complex<T>, E>
246  operator *(const complex<T>& alpha,
248 
249  template<class T, int m, int n, class E>
250  const TinyMatrixScaled<complex<T>, m, n, T, E>
251  operator *(const T& alpha,
252  const TinyMatrixExpression<complex<T>, m, n, E>& u);
253 
254  template<class T, int m, int n, class E>
256  const T& alpha);
257 
258  template<class T, int m, int n, class E>
259  const TinyMatrixScaled<complex<T>, m, n, complex<T>, E>
261  const complex<T>& alpha);
262 
263  template<class T, int m, int n, class E>
264  const TinyMatrixScaled<complex<T>, m, n, T, E>
265  operator *(const TinyMatrixExpression<complex<T>, m, n, E>& u,
266  const T& alpha);
267 
268  template<class T, int m, int n, class E>
269  const TinyMatrixScalDiv<T, m, n, T, E> operator /(const T& alpha,
271 
272  template<class T, int m, int n, class E>
273  const TinyMatrixScalDiv<complex<T>, m, n, complex<T>, E>
274  operator /(const complex<T>& alpha,
276 
277  template<class T, int m, int n, class E>
278  const TinyMatrixScalDiv<complex<T>, m, n, T, E>
279  operator /(const T& alpha,
280  const TinyMatrixExpression<complex<T>, m, n, E>& u);
281 
282  template<class T, int m, int n, class E>
284  const T& alpha);
285 
286  template<class T, int m, int n, class E>
287  const TinyMatrixScaled<complex<T>, m, n, complex<T>, E>
289  const complex<T>& alpha);
290 
291  template<class T, int m, int n, class E>
292  const TinyMatrixScaled<complex<T>, m, n, T, E>
293  operator /(const TinyMatrixExpression<complex<T>, m, n, E>& u,
294  const T& alpha);
295 
296  template<class T, int m, int n, class E>
297  const TinyMatrixScalSum<T, m, n, T, E> operator +(const T& alpha,
299 
300  template<class T, int m, int n, class E>
301  const TinyMatrixScalSum<complex<T>, m, n, complex<T>, E>
302  operator +(const complex<T>& alpha,
304 
305  template<class T, int m, int n, class E>
306  const TinyMatrixScalSum<complex<T>, m, n, T, E>
307  operator +(const T& alpha,
308  const TinyMatrixExpression<complex<T>, m, n, E>& u);
309 
310  template<class T, int m, int n, class E>
312  const T& alpha);
313 
314  template<class T, int m, int n, class E>
315  const TinyMatrixScalSum<complex<T>, m, n, complex<T>, E>
317  const complex<T>& alpha);
318 
319  template<class T, int m, int n, class E>
320  const TinyMatrixScalSum<complex<T>, m, n, T, E>
321  operator +(const TinyMatrixExpression<complex<T>, m, n, E>& u,
322  const T& alpha);
323 
324  template<class T, int m, int n, class E>
326  const T& alpha);
327 
328  template<class T, int m, int n, class E>
329  const TinyMatrixScalSum<complex<T>, m, n, complex<T>, E>
331  const complex<T>& alpha);
332 
333  template<class T, int m, int n, class E>
334  const TinyMatrixScalSum<complex<T>, m, n, T, E>
335  operator -(const TinyMatrixExpression<complex<T>, m, n, E>& u,
336  const T& alpha);
337 
338  template<class T, int m, int n, class E>
339  const TinyMatrixScalDiff<T, m, n, T, E> operator -(const T& alpha,
341 
342  template<class T, int m, int n, class E>
343  const TinyMatrixScalDiff<complex<T>, m, n, complex<T>, E>
344  operator -(const complex<T>& alpha,
346 
347  template<class T, int m, int n, class E>
348  const TinyMatrixScalDiff<complex<T>, m, n, T, E>
349  operator -(const T& alpha,
350  const TinyMatrixExpression<complex<T>, m, n, E>& u);
351 
352  template<class T, int m, int n, class E>
354 
355  template<class T, int m, int n, class E>
357 
358 }
359 
360 #define SELDON_FILE_TINY_MATRIX_EXPRESSION_HXX
361 #endif
Seldon::operator*
const TinyMatrixProduct< T, m, n, E1, E2 > operator*(const TinyMatrixExpression< T, m, n, E1 > &u, const TinyMatrixExpression< T, m, n, E2 > &v)
returns u*v element-wise
Definition: TinyMatrixExpressionInline.cxx:257
Seldon::TinyMatrixScalDiff::operator()
const T operator()(int, int) const
returns the i-th element of alpha - u
Definition: TinyMatrixExpressionInline.cxx:151
Seldon::operator+
const TinyMatrixSum< T, m, n, E1, E2 > operator+(const TinyMatrixExpression< T, m, n, E1 > &u, const TinyMatrixExpression< T, m, n, E2 > &v)
returns u+v
Definition: TinyMatrixExpressionInline.cxx:197
Seldon::TinyMatrixScalDiff::TinyMatrixScalDiff
TinyMatrixScalDiff(const T0 &, const TinyMatrixExpression< T1, m, n, E > &)
Constructor alpha - u with a scalar alpha and an expression u.
Definition: TinyMatrixExpressionInline.cxx:142
Seldon::TinyMatrixScalSum::TinyMatrixScalSum
TinyMatrixScalSum(const T0 &, const TinyMatrixExpression< T1, m, n, E > &)
Constructor alpha + u with a scalar alpha and an expression u.
Definition: TinyMatrixExpressionInline.cxx:124
Seldon::TinyMatrixScaled
Multiplication between a scalar and a matrix.
Definition: TinyMatrixExpression.hxx:85
Seldon::TinyMatrixSum::operator()
const T operator()(int, int) const
returns the i-th element of the sum
Definition: TinyMatrixExpressionInline.cxx:44
Seldon::TinyMatrixDifference
Difference between two expressions.
Definition: TinyMatrixExpression.hxx:21
Seldon::TinyMatrixTranspose
Transpose of a matrix.
Definition: TinyMatrixExpression.hxx:163
Seldon::TinyMatrixOpposite::operator()
const T operator()(int, int) const
returns the i-th element of -u
Definition: TinyMatrixExpressionInline.cxx:167
Seldon::TinyMatrixDivision::TinyMatrixDivision
TinyMatrixDivision(const TinyMatrixExpression< T1, m, n, E1 > &, const TinyMatrixExpression< T2, m, n, E2 > &)
Constructor u / v with two expressions u and v.
Definition: TinyMatrixExpressionInline.cxx:71
Seldon::TinyMatrixDifference::operator()
const T operator()(int, int) const
returns the i-th element of the difference
Definition: TinyMatrixExpressionInline.cxx:26
Seldon::TinyMatrixDivision
Division between two expressions (elementwise)
Definition: TinyMatrixExpression.hxx:69
Seldon::TinyMatrixOpposite::TinyMatrixOpposite
TinyMatrixOpposite(const TinyMatrixExpression< T, m, n, E > &)
Constructor -u with an expression u.
Definition: TinyMatrixExpressionInline.cxx:159
Seldon::TinyMatrixScalSum
Addition between a scalar and a matrix.
Definition: TinyMatrixExpression.hxx:117
Seldon::TinyMatrixTranspose::TinyMatrixTranspose
TinyMatrixTranspose(const TinyMatrixExpression< T, n, m, E > &)
Constructor transpose(u) with an expression u.
Definition: TinyMatrixExpressionInline.cxx:175
Seldon::TinyMatrixScalDiv::TinyMatrixScalDiv
TinyMatrixScalDiv(const T0 &, const TinyMatrixExpression< T1, m, n, E > &)
Constructor alpha / u with a scalar alpha and an expression u.
Definition: TinyMatrixExpressionInline.cxx:106
Seldon::operator/
const TinyMatrixDivision< T, m, n, E1, E2 > operator/(const TinyMatrixExpression< T, m, n, E1 > &u, const TinyMatrixExpression< T, m, n, E2 > &v)
returns u/v element-wise
Definition: TinyMatrixExpressionInline.cxx:287
Seldon::transpose
const TinyMatrixTranspose< T, m, n, E > transpose(const TinyMatrixExpression< T, n, m, E > &u)
returns transpose(u)
Definition: TinyMatrixExpressionInline.cxx:559
Seldon::TinyMatrixScaled::TinyMatrixScaled
TinyMatrixScaled(const T0 &, const TinyMatrixExpression< T1, m, n, E > &)
Constructor alpha * u with a scalar alpha and an expression u.
Definition: TinyMatrixExpressionInline.cxx:89
Seldon::TinyMatrixProduct::operator()
const T operator()(int, int) const
returns the i-th element of the element-wise product
Definition: TinyMatrixExpressionInline.cxx:62
Seldon::TinyMatrixScaled::operator()
const T operator()(int, int) const
returns the i-th element of alpha*u
Definition: TinyMatrixExpressionInline.cxx:98
Seldon::TinyMatrixProduct::TinyMatrixProduct
TinyMatrixProduct(const TinyMatrixExpression< T1, m, n, E1 > &, const TinyMatrixExpression< T2, m, n, E2 > &)
Constructor u*v with two expressions u and v.
Definition: TinyMatrixExpressionInline.cxx:53
Seldon::TinyMatrixExpression::operator()
const T operator()(int, int) const
returns the element i of expression
Definition: TinyMatrixExpressionInline.cxx:8
Seldon::TinyMatrixScalDiv
Division between a scalar and a matrix.
Definition: TinyMatrixExpression.hxx:101
Seldon::TinyMatrixExpression
Expression between vectors.
Definition: TinyMatrixExpression.hxx:8
Seldon::operator-
const TinyMatrixDifference< T, m, n, E1, E2 > operator-(const TinyMatrixExpression< T, m, n, E1 > &u, const TinyMatrixExpression< T, m, n, E2 > &v)
returns u-v
Definition: TinyMatrixExpressionInline.cxx:227
Seldon::TinyMatrixProduct
Product between two expressions (elementwise)
Definition: TinyMatrixExpression.hxx:53
Seldon::TinyMatrixTranspose::operator()
const T operator()(int, int) const
returns the i-th element of -u
Definition: TinyMatrixExpressionInline.cxx:183
Seldon::TinyMatrixScalDiv::operator()
const T operator()(int, int) const
returns the i-th element of alpha / u
Definition: TinyMatrixExpressionInline.cxx:115
Seldon::TinyMatrixScalDiff
Subtraction between a scalar and a matrix.
Definition: TinyMatrixExpression.hxx:133
Seldon::TinyMatrixSum::TinyMatrixSum
TinyMatrixSum(const TinyMatrixExpression< T1, m, n, E1 > &, const TinyMatrixExpression< T2, m, n, E2 > &)
Constructor u+v with two expressions u and v.
Definition: TinyMatrixExpressionInline.cxx:35
Seldon::TinyMatrixSum
Sum between two expressions.
Definition: TinyMatrixExpression.hxx:37
Seldon
Seldon namespace.
Definition: Array.cxx:24
Seldon::TinyMatrixDivision::operator()
const T operator()(int, int) const
returns the i-th element of the element-wise division
Definition: TinyMatrixExpressionInline.cxx:80
Seldon::TinyMatrixDifference::TinyMatrixDifference
TinyMatrixDifference(const TinyMatrixExpression< T1, m, n, E1 > &, const TinyMatrixExpression< T2, m, n, E2 > &)
Constructor u-v with two expressions u and v.
Definition: TinyMatrixExpressionInline.cxx:17
Seldon::TinyMatrixScalSum::operator()
const T operator()(int, int) const
returns the i-th element of alpha + u
Definition: TinyMatrixExpressionInline.cxx:133
Seldon::TinyMatrixOpposite
Opposite of a matrix.
Definition: TinyMatrixExpression.hxx:149