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_TINYVEC2_CC |
---|
32 | #define BZ_TINYVEC2_CC |
---|
33 | |
---|
34 | #include <blitz/tinyvec2.h> |
---|
35 | #include <blitz/update.h> |
---|
36 | #include <blitz/tvevaluate.h> |
---|
37 | #include <blitz/array/asexpr.h> |
---|
38 | |
---|
39 | BZ_NAMESPACE(blitz) |
---|
40 | |
---|
41 | /* |
---|
42 | * Constructors |
---|
43 | */ |
---|
44 | |
---|
45 | template<typename P_numtype, int N_length> |
---|
46 | _bz_forceinline |
---|
47 | TinyVector<P_numtype, N_length>::TinyVector(const T_numtype initValue) { |
---|
48 | for (int i=0; i < N_length; ++i) |
---|
49 | data_[i] = initValue; |
---|
50 | } |
---|
51 | |
---|
52 | template<typename P_numtype, int N_length> |
---|
53 | _bz_forceinline |
---|
54 | TinyVector<P_numtype, N_length>::TinyVector(const TinyVector<T_numtype, N_length>& x) { |
---|
55 | for (int i=0; i < N_length; ++i) |
---|
56 | data_[i] = x.data_[i]; |
---|
57 | } |
---|
58 | |
---|
59 | template<typename P_numtype, int N_length> |
---|
60 | template<typename P_numtype2> |
---|
61 | _bz_forceinline |
---|
62 | TinyVector<P_numtype, N_length>::TinyVector(const TinyVector<P_numtype2, N_length>& x) { |
---|
63 | for (int i=0; i < N_length; ++i) |
---|
64 | data_[i] = static_cast<P_numtype>(x[i]); |
---|
65 | } |
---|
66 | |
---|
67 | |
---|
68 | /* |
---|
69 | * Assignment-type operators |
---|
70 | */ |
---|
71 | |
---|
72 | template<typename P_numtype, int N_length> |
---|
73 | _bz_forceinline |
---|
74 | TinyVector<P_numtype, N_length>& |
---|
75 | TinyVector<P_numtype,N_length>::initialize(T_numtype x) |
---|
76 | { |
---|
77 | (*this) = _bz_ArrayExpr<_bz_ArrayExprConstant<T_numtype> >(x); |
---|
78 | return *this; |
---|
79 | } |
---|
80 | |
---|
81 | template<typename P_numtype, int N_length> template<typename T_expr> |
---|
82 | _bz_forceinline |
---|
83 | TinyVector<P_numtype,N_length>& |
---|
84 | TinyVector<P_numtype,N_length>::operator=(const ETBase<T_expr>& expr) |
---|
85 | { |
---|
86 | _tv_evaluate(_bz_typename asExpr<T_expr>::T_expr(expr.unwrap()), |
---|
87 | _bz_update< |
---|
88 | T_numtype, |
---|
89 | _bz_typename asExpr<T_expr>::T_expr::T_result>()); |
---|
90 | return *this; |
---|
91 | } |
---|
92 | |
---|
93 | #define BZ_TV2_UPDATE(op,name) \ |
---|
94 | template<typename P_numtype, int N_length> \ |
---|
95 | template<typename T> \ |
---|
96 | _bz_forceinline \ |
---|
97 | TinyVector<P_numtype,N_length>& \ |
---|
98 | TinyVector<P_numtype,N_length>::operator op(const T& expr) \ |
---|
99 | { \ |
---|
100 | _tv_evaluate(_bz_typename asExpr<T>::T_expr(expr), \ |
---|
101 | name<T_numtype, \ |
---|
102 | _bz_typename asExpr<T>::T_expr::T_result>()); \ |
---|
103 | return *this; \ |
---|
104 | } |
---|
105 | |
---|
106 | |
---|
107 | BZ_TV2_UPDATE(+=, _bz_plus_update) |
---|
108 | BZ_TV2_UPDATE(-=, _bz_minus_update) |
---|
109 | BZ_TV2_UPDATE(*=, _bz_multiply_update) |
---|
110 | BZ_TV2_UPDATE(/=, _bz_divide_update) |
---|
111 | BZ_TV2_UPDATE(%=, _bz_mod_update) |
---|
112 | BZ_TV2_UPDATE(^=, _bz_xor_update) |
---|
113 | BZ_TV2_UPDATE(&=, _bz_bitand_update) |
---|
114 | BZ_TV2_UPDATE(|=, _bz_bitor_update) |
---|
115 | BZ_TV2_UPDATE(<<=, _bz_shiftl_update) |
---|
116 | BZ_TV2_UPDATE(>>=, _bz_shiftr_update) |
---|
117 | |
---|
118 | /* |
---|
119 | * Other member functions |
---|
120 | */ |
---|
121 | |
---|
122 | template<typename P_numtype, int N_length> |
---|
123 | template<int N0> |
---|
124 | _bz_forceinline |
---|
125 | _bz_ArrayExpr<ArrayIndexMapping<typename asExpr<TinyVector<P_numtype, N_length> >::T_expr, N0> > |
---|
126 | TinyVector<P_numtype, N_length>::operator()(IndexPlaceholder<N0>) const |
---|
127 | { |
---|
128 | return _bz_ArrayExpr<ArrayIndexMapping<typename asExpr<T_vector>::T_expr, N0> > |
---|
129 | (noConst()); |
---|
130 | } |
---|
131 | |
---|
132 | |
---|
133 | BZ_NAMESPACE_END |
---|
134 | |
---|
135 | #include <blitz/tv2fastiter.h> // Iterators |
---|
136 | //#include <blitz/tv2assign.h> unused now? |
---|
137 | #include <blitz/tinyvec2io.cc> |
---|
138 | |
---|
139 | #endif // BZ_TINYVEC_CC |
---|