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

Last change on this file since 1022 was 1022, checked in by mhnguyen, 7 years ago
File size: 2.5 KB
Line 
1// -*- C++ -*-
2/***************************************************************************
3 * blitz/meta/product.h  TinyVector product 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_PRODUCT_H
33#define BZ_META_PRODUCT_H
34
35#ifndef BZ_PROMOTE_H
36 #include <blitz/promote.h>
37#endif
38
39#ifndef BZ_METAPROG_H
40 #include <blitz/meta/metaprog.h>
41#endif
42
43BZ_NAMESPACE(blitz)
44
45template<int N, int I>
46class _bz_meta_vectorProduct {
47public:
48    static const int loopFlag = (I < N-1) ? 1 : 0;
49
50    template<typename T_expr1>
51    static inline BZ_SUMTYPE(_bz_typename T_expr1::T_numtype)
52    f(const T_expr1& a)
53    {
54        return a[I] * _bz_meta_vectorProduct<loopFlag * N, 
55            loopFlag * (I+1)>::f(a);
56    }
57};
58
59template<>
60class _bz_meta_vectorProduct<0,0> {
61public:
62    template<typename T_expr1>
63    static inline _bz_meta_nullOperand f(const T_expr1&)
64    { return _bz_meta_nullOperand(); }
65};
66
67template<int N, int I, typename T_ret>
68class _bz_meta_vectorProductRet {
69public:
70    static const int loopFlag = (I < N-1) ? 1 : 0;
71
72    template<typename T_expr1>
73    static inline T_ret
74    f(const T_expr1& a)
75    {
76      return static_cast<T_ret>(a[I]) * _bz_meta_vectorProductRet<loopFlag * N, 
77        loopFlag * (I+1), T_ret>::f(a);
78    }
79};
80
81template<typename T_ret>
82class _bz_meta_vectorProductRet<0,0, T_ret> {
83public:
84    template<typename T_expr1>
85    static inline _bz_meta_nullOperand f(const T_expr1&)
86    { return _bz_meta_nullOperand(); }
87};
88
89BZ_NAMESPACE_END
90
91#endif // BZ_META_PRODUCT_H
Note: See TracBrowser for help on using the repository browser.