1 | /*************************************************************************** |
---|
2 | * blitz/tinyvec.cc Declaration of TinyVector methods |
---|
3 | * |
---|
4 | * $Id$ |
---|
5 | * |
---|
6 | * Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org> |
---|
7 | * |
---|
8 | * This file is a part of Blitz. |
---|
9 | * |
---|
10 | * Blitz is free software: you can redistribute it and/or modify |
---|
11 | * it under the terms of the GNU Lesser General Public License |
---|
12 | * as published by the Free Software Foundation, either version 3 |
---|
13 | * of the License, or (at your option) any later version. |
---|
14 | * |
---|
15 | * Blitz is distributed in the hope that it will be useful, |
---|
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
18 | * GNU Lesser General Public License for more details. |
---|
19 | * |
---|
20 | * You should have received a copy of the GNU Lesser General Public |
---|
21 | * License along with Blitz. If not, see <http://www.gnu.org/licenses/>. |
---|
22 | * |
---|
23 | * Suggestions: blitz-devel@lists.sourceforge.net |
---|
24 | * Bugs: blitz-support@lists.sourceforge.net |
---|
25 | * |
---|
26 | * For more information, please see the Blitz++ Home Page: |
---|
27 | * https://sourceforge.net/projects/blitz/ |
---|
28 | * |
---|
29 | ***************************************************************************/ |
---|
30 | |
---|
31 | #ifndef BZ_TINYMAT2_CC |
---|
32 | #define BZ_TINYMAT2_CC |
---|
33 | |
---|
34 | #include <blitz/tmevaluate.h> |
---|
35 | #include <blitz/tinymat2io.cc> |
---|
36 | #include <blitz/array/domain.h> |
---|
37 | |
---|
38 | BZ_NAMESPACE(blitz) |
---|
39 | |
---|
40 | template<typename P_numtype, int N_rows, int N_columns> |
---|
41 | inline TinyMatrix<P_numtype, N_rows, N_columns>::TinyMatrix(T_numtype initValue) |
---|
42 | { |
---|
43 | for (sizeType i=0; i < numElements(); ++i) |
---|
44 | data_[i] = initValue; |
---|
45 | } |
---|
46 | |
---|
47 | template<typename P_numtype, int N_rows, int N_columns> |
---|
48 | inline TinyMatrix<P_numtype, N_rows, N_columns>::TinyMatrix(const T_matrix& x) |
---|
49 | { |
---|
50 | for (sizeType i=0; i < numElements(); ++i) |
---|
51 | data_[i] = x.data_[i]; |
---|
52 | } |
---|
53 | |
---|
54 | template<typename P_numtype, int N_rows, int N_columns> |
---|
55 | template<typename P_numtype2> |
---|
56 | inline |
---|
57 | TinyMatrix<P_numtype, N_rows, N_columns>::TinyMatrix(const TinyMatrix<P_numtype2, N_rows, N_columns>& x) |
---|
58 | { |
---|
59 | for (sizeType i=0; i < numElements(); ++i) |
---|
60 | data_[i] = static_cast<P_numtype>(x.data_[i]); |
---|
61 | } |
---|
62 | |
---|
63 | /* |
---|
64 | * Assignment-type operators |
---|
65 | */ |
---|
66 | |
---|
67 | template<typename P_numtype, int N_rows, int N_columns> |
---|
68 | TinyMatrix<P_numtype, N_rows, N_columns>& |
---|
69 | TinyMatrix<P_numtype, N_rows, N_columns>::initialize(T_numtype x) |
---|
70 | { |
---|
71 | (*this) = _bz_ArrayExpr<_bz_ArrayExprConstant<T_numtype> >(x); |
---|
72 | return *this; |
---|
73 | } |
---|
74 | |
---|
75 | template<typename P_numtype, int N_rows, int N_columns> |
---|
76 | template<typename T_expr> |
---|
77 | inline |
---|
78 | TinyMatrix<P_numtype, N_rows, N_columns>& |
---|
79 | TinyMatrix<P_numtype, N_rows, N_columns>::operator=(const ETBase<T_expr>& expr) |
---|
80 | { |
---|
81 | _tm_evaluate(_bz_typename asExpr<T_expr>::T_expr(expr.unwrap()), |
---|
82 | _bz_update<T_numtype, _bz_typename asExpr<T_expr>::T_expr::T_result>()); |
---|
83 | return *this; |
---|
84 | } |
---|
85 | |
---|
86 | #define BZ_TM2_UPDATE(op,name) \ |
---|
87 | template<typename P_numtype, int N_rows, int N_columns> \ |
---|
88 | template<typename T> \ |
---|
89 | inline TinyMatrix<P_numtype, N_rows, N_columns>& \ |
---|
90 | TinyMatrix<P_numtype, N_rows, N_columns>::operator op(const T& expr) \ |
---|
91 | { \ |
---|
92 | _tm_evaluate(_bz_typename asExpr<T>::T_expr(expr), \ |
---|
93 | name<T_numtype, _bz_typename asExpr<T>::T_expr::T_result>()); \ |
---|
94 | return *this; \ |
---|
95 | } |
---|
96 | |
---|
97 | BZ_TM2_UPDATE(+=, _bz_plus_update) |
---|
98 | BZ_TM2_UPDATE(-=, _bz_minus_update) |
---|
99 | BZ_TM2_UPDATE(*=, _bz_multiply_update) |
---|
100 | BZ_TM2_UPDATE(/=, _bz_divide_update) |
---|
101 | BZ_TM2_UPDATE(%=, _bz_mod_update) |
---|
102 | BZ_TM2_UPDATE(^=, _bz_xor_update) |
---|
103 | BZ_TM2_UPDATE(&=, _bz_bitand_update) |
---|
104 | BZ_TM2_UPDATE(|=, _bz_bitor_update) |
---|
105 | BZ_TM2_UPDATE(<<=, _bz_shiftl_update) |
---|
106 | BZ_TM2_UPDATE(>>=, _bz_shiftr_update) |
---|
107 | |
---|
108 | /* |
---|
109 | * Other member functions |
---|
110 | */ |
---|
111 | |
---|
112 | |
---|
113 | template<typename P_numtype, int N_rows, int N_columns> |
---|
114 | inline RectDomain<2> |
---|
115 | TinyMatrix<P_numtype, N_rows, N_columns>::domain() |
---|
116 | { |
---|
117 | return RectDomain<2>(lbound(), ubound()); |
---|
118 | } |
---|
119 | |
---|
120 | |
---|
121 | template<typename P_numtype, int N_rows, int N_columns> |
---|
122 | template<int N0, int N1> |
---|
123 | inline _bz_ArrayExpr<ArrayIndexMapping<typename asExpr<TinyMatrix<P_numtype, N_rows, N_columns> >::T_expr, N0, N1> > |
---|
124 | TinyMatrix<P_numtype, N_rows, N_columns>::operator()(IndexPlaceholder<N0>, IndexPlaceholder<N1>) const |
---|
125 | { |
---|
126 | return _bz_ArrayExpr<ArrayIndexMapping<typename asExpr<T_matrix>::T_expr, |
---|
127 | N0, N1> >(noConst()); |
---|
128 | } |
---|
129 | |
---|
130 | |
---|
131 | BZ_NAMESPACE_END |
---|
132 | |
---|
133 | #endif // BZ_TINYVEC_CC |
---|