source: XIOS/dev/dev_olga/src/extern/blitz/include/blitz/tinyvec2.cc @ 1022

Last change on this file since 1022 was 1022, checked in by mhnguyen, 7 years ago
File size: 4.0 KB
Line 
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
39BZ_NAMESPACE(blitz)
40
41/*
42 * Constructors
43 */
44
45template<typename P_numtype, int N_length>
46_bz_forceinline
47TinyVector<P_numtype, N_length>::TinyVector(const T_numtype initValue) {
48    for (int i=0; i < N_length; ++i)
49        data_[i] = initValue;
50}
51
52template<typename P_numtype, int N_length>
53_bz_forceinline
54TinyVector<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
59template<typename P_numtype, int N_length>
60template<typename P_numtype2>
61_bz_forceinline
62TinyVector<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
72template<typename P_numtype, int N_length>
73_bz_forceinline
74TinyVector<P_numtype, N_length>& 
75TinyVector<P_numtype,N_length>::initialize(T_numtype x)
76{
77    (*this) = _bz_ArrayExpr<_bz_ArrayExprConstant<T_numtype> >(x);
78    return *this;
79}
80
81template<typename P_numtype, int N_length> template<typename T_expr>
82_bz_forceinline
83TinyVector<P_numtype,N_length>&
84TinyVector<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
107BZ_TV2_UPDATE(+=, _bz_plus_update)
108BZ_TV2_UPDATE(-=, _bz_minus_update)
109BZ_TV2_UPDATE(*=, _bz_multiply_update)
110BZ_TV2_UPDATE(/=, _bz_divide_update)
111BZ_TV2_UPDATE(%=, _bz_mod_update)
112BZ_TV2_UPDATE(^=, _bz_xor_update)
113BZ_TV2_UPDATE(&=, _bz_bitand_update)
114BZ_TV2_UPDATE(|=, _bz_bitor_update)
115BZ_TV2_UPDATE(<<=, _bz_shiftl_update)
116BZ_TV2_UPDATE(>>=, _bz_shiftr_update)
117
118/*
119 * Other member functions
120 */
121
122template<typename P_numtype, int N_length>
123template<int N0>
124_bz_forceinline
125_bz_ArrayExpr<ArrayIndexMapping<typename asExpr<TinyVector<P_numtype, N_length> >::T_expr, N0> >
126TinyVector<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
133BZ_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
Note: See TracBrowser for help on using the repository browser.