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

Last change on this file since 1022 was 1022, checked in by mhnguyen, 7 years ago
File size: 1.9 KB
Line 
1/***************************************************************************
2 * blitz/array/convolve.cc  One-dimensional convolution
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_ARRAY_CONVOLVE_CC
32#define BZ_ARRAY_CONVOLVE_CC
33
34BZ_NAMESPACE(blitz)
35
36template<typename T>
37Array<T,1> convolve(const Array<T,1>& B, const Array<T,1>& C)
38{
39    int Bl = B.lbound(0), Bh = B.ubound(0);
40    int Cl = C.lbound(0), Ch = C.ubound(0);
41
42    int lbound = Bl + Cl;
43    int ubound = Bh + Ch;
44   
45    Array<T,1> A(Range(lbound,ubound));
46
47    T result;
48    for (int i=lbound; i <= ubound; ++i)
49    {
50        int jl = i - Ch;
51        if (jl < Bl)
52            jl = Bl;
53
54        int jh = i - Cl;
55        if (jh > Bh)
56            jh = Bh;
57
58        result = 0;
59        for (int j=jl; j <= jh; ++j)
60            result += B(j) * C(i-j);
61
62        A(i) = result;
63    }
64
65    return A;
66}
67
68BZ_NAMESPACE_END
69
70#endif // BZ_ARRAY_CONVOLVE_CC
71
Note: See TracBrowser for help on using the repository browser.