source: XIOS/dev/dev_olga/src/extern/blitz/include/blitz/meta/sum.h @ 1022

Last change on this file since 1022 was 1022, checked in by mhnguyen, 7 years ago
File size: 2.4 KB
Line 
1// -*- C++ -*-
2/***************************************************************************
3 * blitz/meta/sum.h      TinyVector sum metaprogram
4 *
5 * $Id$
6 *
7 * Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org>
8 *
9 * This file is a part of Blitz.
10 *
11 * Blitz is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation, either version 3
14 * of the License, or (at your option) any later version.
15 *
16 * Blitz is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 * GNU Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with Blitz.  If not, see <http://www.gnu.org/licenses/>.
23 *
24 * Suggestions:          blitz-devel@lists.sourceforge.net
25 * Bugs:                 blitz-support@lists.sourceforge.net   
26 *
27 * For more information, please see the Blitz++ Home Page:
28 *    https://sourceforge.net/projects/blitz/
29 *
30 ***************************************************************************/
31
32#ifndef BZ_META_SUM_H
33#define BZ_META_SUM_H
34
35#ifndef BZ_METAPROG_H
36 #include <blitz/meta/metaprog.h>
37#endif
38
39BZ_NAMESPACE(blitz)
40
41template<int N, int I>
42class _bz_meta_vectorSum {
43public:
44    static const int loopFlag = (I < N-1) ? 1 : 0;
45
46    template<typename T_expr1>
47    static inline BZ_SUMTYPE(_bz_typename T_expr1::T_numtype)
48    f(const T_expr1& a)
49    {
50        return a[I] +
51            _bz_meta_vectorSum<loopFlag * N, loopFlag * (I+1)>::f(a);
52    }
53};
54
55template<>
56class _bz_meta_vectorSum<0,0> {
57public:
58    template<typename T_expr1>
59    static inline _bz_meta_nullOperand f(const T_expr1&)
60    { return _bz_meta_nullOperand(); }
61
62};
63
64template<int N, int I, typename T_ret>
65class _bz_meta_vectorSumRet {
66public:
67    static const int loopFlag = (I < N-1) ? 1 : 0;
68
69    template<typename T_expr1>
70    static inline T_ret
71    f(const T_expr1& a)
72    {
73      return static_cast<T_ret>(a[I]) +
74        _bz_meta_vectorSumRet<loopFlag * N, loopFlag * (I+1), T_ret>::f(a);
75    }
76};
77
78template<typename T_ret>
79class _bz_meta_vectorSumRet<0,0, T_ret> {
80public:
81    template<typename T_expr1>
82    static inline _bz_meta_nullOperand f(const T_expr1&)
83    { return _bz_meta_nullOperand(); }
84
85};
86
87BZ_NAMESPACE_END
88
89#endif // BZ_META_SUM_H
Note: See TracBrowser for help on using the repository browser.