source: XMLIO_V2/external/include/blitz/array/convolve.cc @ 80

Last change on this file since 80 was 80, checked in by ymipsl, 14 years ago

ajout lib externe

File size: 1.7 KB
Line 
1/***************************************************************************
2 * blitz/array/convolve.cc  One-dimensional convolution
3 *
4 * Copyright (C) 1997-2001 Todd Veldhuizen <tveldhui@oonumerics.org>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * Suggestions:          blitz-dev@oonumerics.org
17 * Bugs:                 blitz-bugs@oonumerics.org
18 *
19 * For more information, please see the Blitz++ Home Page:
20 *    http://oonumerics.org/blitz/
21 *
22 ****************************************************************************/
23
24#ifndef BZ_ARRAY_CONVOLVE_CC
25#define BZ_ARRAY_CONVOLVE_CC
26
27BZ_NAMESPACE(blitz)
28
29template<typename T>
30Array<T,1> convolve(const Array<T,1>& B, const Array<T,1>& C)
31{
32    int Bl = B.lbound(0), Bh = B.ubound(0);
33    int Cl = C.lbound(0), Ch = C.ubound(0);
34
35    int lbound = Bl + Cl;
36    int ubound = Bh + Ch;
37   
38    Array<T,1> A(Range(lbound,ubound));
39
40    for (int i=lbound; i <= ubound; ++i)
41    {
42        int jl = i - Ch;
43        if (jl < Bl)
44            jl = Bl;
45
46        int jh = i - Cl;
47        if (jh > Bh)
48            jh = Bh;
49
50        T result = 0;
51        for (int j=jl; j <= jh; ++j)
52            result += B(j) * C(i-j);
53
54        A(i) = result;
55    }
56
57    return A;
58}
59
60BZ_NAMESPACE_END
61
62#endif // BZ_ARRAY_CONVOLVE_CC
63
Note: See TracBrowser for help on using the repository browser.