Mercurial > octave
annotate liboctave/numeric/oct-convn.cc @ 22948:7e447335b839
use F77_INT instead of octave_idx_type for liboctave convolution functions
* oct-convn.cc: Use F77_INT instead of octave_idx_type for integer
data passed to Fortran subroutines.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 26 Dec 2016 21:11:20 -0500 |
parents | 3a2b891d0b33 |
children | cd33c785e80e |
rev | line source |
---|---|
10385
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
1 /* |
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
2 |
22323
bac0d6f07a3e
maint: Update copyright notices for 2016.
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
3 Copyright (C) 2010-2016 VZLU Prague |
10385
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
4 |
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
5 This file is part of Octave. |
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
6 |
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
7 Octave is free software; you can redistribute it and/or modify it |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
8 under the terms of the GNU General Public License as published by |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
9 the Free Software Foundation; either version 3 of the License, or |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
10 (at your option) any later version. |
10385
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
11 |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
12 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
13 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
15 GNU General Public License for more details. |
10385
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
16 |
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
17 You should have received a copy of the GNU General Public License |
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
18 along with Octave; see the file COPYING. If not, see |
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
19 <http://www.gnu.org/licenses/>. |
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
20 |
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
21 */ |
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
22 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
23 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21202
diff
changeset
|
24 # include "config.h" |
10385
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
25 #endif |
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
26 |
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
27 #include <iostream> |
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
28 #include <algorithm> |
10388
5af0b4bb384d
rewrite convn optimizations based on xAXPY
Jaroslav Hajek <highegg@gmail.com>
parents:
10385
diff
changeset
|
29 |
5af0b4bb384d
rewrite convn optimizations based on xAXPY
Jaroslav Hajek <highegg@gmail.com>
parents:
10385
diff
changeset
|
30 #include "f77-fcn.h" |
5af0b4bb384d
rewrite convn optimizations based on xAXPY
Jaroslav Hajek <highegg@gmail.com>
parents:
10385
diff
changeset
|
31 |
10385
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
32 #include "oct-convn.h" |
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
33 #include "oct-locbuf.h" |
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
34 |
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
35 // 2d convolution with a matrix kernel. |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
36 template <typename T, typename R> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
37 static void |
22948
7e447335b839
use F77_INT instead of octave_idx_type for liboctave convolution functions
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
38 convolve_2d (const T *a, F77_INT ma, F77_INT na, |
7e447335b839
use F77_INT instead of octave_idx_type for liboctave convolution functions
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
39 const R *b, F77_INT mb, F77_INT nb, |
10388
5af0b4bb384d
rewrite convn optimizations based on xAXPY
Jaroslav Hajek <highegg@gmail.com>
parents:
10385
diff
changeset
|
40 T *c, bool inner); |
10385
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
41 |
10388
5af0b4bb384d
rewrite convn optimizations based on xAXPY
Jaroslav Hajek <highegg@gmail.com>
parents:
10385
diff
changeset
|
42 // Forward instances to our Fortran implementations. |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22135
diff
changeset
|
43 #define FORWARD_IMPL(T_CXX, R_CXX, T, R, T_CAST, T_CONST_CAST, \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22135
diff
changeset
|
44 R_CONST_CAST, f, F) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22135
diff
changeset
|
45 extern "C" \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22135
diff
changeset
|
46 F77_RET_T \ |
22948
7e447335b839
use F77_INT instead of octave_idx_type for liboctave convolution functions
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
47 F77_FUNC (f##conv2o, F##CONV2O) (const F77_INT&, const F77_INT&, \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22135
diff
changeset
|
48 const T*, const F77_INT&, \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22135
diff
changeset
|
49 const F77_INT&, const R*, T *); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22135
diff
changeset
|
50 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22135
diff
changeset
|
51 extern "C" \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22135
diff
changeset
|
52 F77_RET_T \ |
22948
7e447335b839
use F77_INT instead of octave_idx_type for liboctave convolution functions
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
53 F77_FUNC (f##conv2i, F##CONV2I) (const F77_INT&, const F77_INT&, \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22135
diff
changeset
|
54 const T*, const F77_INT&, \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22135
diff
changeset
|
55 const F77_INT&, const R*, T *); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22135
diff
changeset
|
56 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22135
diff
changeset
|
57 template <> void \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22135
diff
changeset
|
58 convolve_2d<T_CXX, R_CXX> (const T_CXX *a, F77_INT ma, F77_INT na, \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22135
diff
changeset
|
59 const R_CXX *b, F77_INT mb, F77_INT nb, \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22135
diff
changeset
|
60 T_CXX *c, bool inner) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22135
diff
changeset
|
61 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22135
diff
changeset
|
62 if (inner) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22135
diff
changeset
|
63 F77_XFCN (f##conv2i, F##CONV2I, (ma, na, T_CONST_CAST (a), \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22135
diff
changeset
|
64 mb, nb, R_CONST_CAST (b), \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22135
diff
changeset
|
65 T_CAST (c))); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22135
diff
changeset
|
66 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22135
diff
changeset
|
67 F77_XFCN (f##conv2o, F##CONV2O, (ma, na, T_CONST_CAST (a), \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22135
diff
changeset
|
68 mb, nb, R_CONST_CAST (b), \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22135
diff
changeset
|
69 T_CAST (c))); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22135
diff
changeset
|
70 } |
10385
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
71 |
22135
407c66ae1e20
reduce warnings from GCC's link-time optimization feature (bug #48531)
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
72 FORWARD_IMPL (double, double, F77_DBLE, F77_DBLE, , , , d, D) |
407c66ae1e20
reduce warnings from GCC's link-time optimization feature (bug #48531)
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
73 FORWARD_IMPL (float, float, F77_REAL, F77_REAL, , , , s, S) |
407c66ae1e20
reduce warnings from GCC's link-time optimization feature (bug #48531)
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
74 |
407c66ae1e20
reduce warnings from GCC's link-time optimization feature (bug #48531)
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
75 FORWARD_IMPL (std::complex<double>, std::complex<double>, |
407c66ae1e20
reduce warnings from GCC's link-time optimization feature (bug #48531)
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
76 F77_DBLE_CMPLX, F77_DBLE_CMPLX, F77_DBLE_CMPLX_ARG, |
407c66ae1e20
reduce warnings from GCC's link-time optimization feature (bug #48531)
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
77 F77_CONST_DBLE_CMPLX_ARG, F77_CONST_DBLE_CMPLX_ARG, z, Z) |
407c66ae1e20
reduce warnings from GCC's link-time optimization feature (bug #48531)
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
78 FORWARD_IMPL (std::complex<float>, std::complex<float>, |
407c66ae1e20
reduce warnings from GCC's link-time optimization feature (bug #48531)
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
79 F77_CMPLX, F77_CMPLX, F77_CMPLX_ARG, |
407c66ae1e20
reduce warnings from GCC's link-time optimization feature (bug #48531)
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
80 F77_CONST_CMPLX_ARG, F77_CONST_CMPLX_ARG, c, C) |
407c66ae1e20
reduce warnings from GCC's link-time optimization feature (bug #48531)
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
81 |
407c66ae1e20
reduce warnings from GCC's link-time optimization feature (bug #48531)
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
82 FORWARD_IMPL (std::complex<double>, double, |
407c66ae1e20
reduce warnings from GCC's link-time optimization feature (bug #48531)
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
83 F77_DBLE_CMPLX, F77_DBLE, F77_DBLE_CMPLX_ARG, |
407c66ae1e20
reduce warnings from GCC's link-time optimization feature (bug #48531)
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
84 F77_CONST_DBLE_CMPLX_ARG, , zd, ZD) |
407c66ae1e20
reduce warnings from GCC's link-time optimization feature (bug #48531)
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
85 FORWARD_IMPL (std::complex<float>, float, F77_CMPLX, F77_REAL, F77_CMPLX_ARG, |
407c66ae1e20
reduce warnings from GCC's link-time optimization feature (bug #48531)
John W. Eaton <jwe@octave.org>
parents:
22133
diff
changeset
|
86 F77_CONST_CMPLX_ARG, , cs, CS) |
10385
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
87 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
88 template <typename T, typename R> |
10385
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
89 void convolve_nd (const T *a, const dim_vector& ad, const dim_vector& acd, |
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
90 const R *b, const dim_vector& bd, const dim_vector& bcd, |
10388
5af0b4bb384d
rewrite convn optimizations based on xAXPY
Jaroslav Hajek <highegg@gmail.com>
parents:
10385
diff
changeset
|
91 T *c, const dim_vector& ccd, int nd, bool inner) |
10385
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
92 { |
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
93 if (nd == 2) |
22948
7e447335b839
use F77_INT instead of octave_idx_type for liboctave convolution functions
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
94 { |
7e447335b839
use F77_INT instead of octave_idx_type for liboctave convolution functions
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
95 F77_INT ad0 = to_f77_int (ad(0)); |
7e447335b839
use F77_INT instead of octave_idx_type for liboctave convolution functions
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
96 F77_INT ad1 = to_f77_int (ad(1)); |
7e447335b839
use F77_INT instead of octave_idx_type for liboctave convolution functions
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
97 |
7e447335b839
use F77_INT instead of octave_idx_type for liboctave convolution functions
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
98 F77_INT bd0 = to_f77_int (bd(0)); |
7e447335b839
use F77_INT instead of octave_idx_type for liboctave convolution functions
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
99 F77_INT bd1 = to_f77_int (bd(1)); |
7e447335b839
use F77_INT instead of octave_idx_type for liboctave convolution functions
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
100 |
7e447335b839
use F77_INT instead of octave_idx_type for liboctave convolution functions
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
101 convolve_2d<T, R> (a, ad0, ad1, b, bd0, bd1, c, inner); |
7e447335b839
use F77_INT instead of octave_idx_type for liboctave convolution functions
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
102 } |
10385
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
103 else |
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
104 { |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
105 octave_idx_type ma = acd(nd-2); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
106 octave_idx_type na = ad(nd-1); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
107 octave_idx_type mb = bcd(nd-2); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
108 octave_idx_type nb = bd(nd-1); |
10385
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
109 octave_idx_type ldc = ccd(nd-2); |
22948
7e447335b839
use F77_INT instead of octave_idx_type for liboctave convolution functions
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
110 |
10388
5af0b4bb384d
rewrite convn optimizations based on xAXPY
Jaroslav Hajek <highegg@gmail.com>
parents:
10385
diff
changeset
|
111 if (inner) |
5af0b4bb384d
rewrite convn optimizations based on xAXPY
Jaroslav Hajek <highegg@gmail.com>
parents:
10385
diff
changeset
|
112 { |
5af0b4bb384d
rewrite convn optimizations based on xAXPY
Jaroslav Hajek <highegg@gmail.com>
parents:
10385
diff
changeset
|
113 for (octave_idx_type ja = 0; ja < na - nb + 1; ja++) |
5af0b4bb384d
rewrite convn optimizations based on xAXPY
Jaroslav Hajek <highegg@gmail.com>
parents:
10385
diff
changeset
|
114 for (octave_idx_type jb = 0; jb < nb; jb++) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
115 convolve_nd<T, R> (a + ma*(ja+jb), ad, acd, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
116 b + mb*(nb-jb-1), bd, bcd, |
10388
5af0b4bb384d
rewrite convn optimizations based on xAXPY
Jaroslav Hajek <highegg@gmail.com>
parents:
10385
diff
changeset
|
117 c + ldc*ja, ccd, nd-1, inner); |
5af0b4bb384d
rewrite convn optimizations based on xAXPY
Jaroslav Hajek <highegg@gmail.com>
parents:
10385
diff
changeset
|
118 } |
5af0b4bb384d
rewrite convn optimizations based on xAXPY
Jaroslav Hajek <highegg@gmail.com>
parents:
10385
diff
changeset
|
119 else |
10385
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
120 { |
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
121 for (octave_idx_type ja = 0; ja < na; ja++) |
10388
5af0b4bb384d
rewrite convn optimizations based on xAXPY
Jaroslav Hajek <highegg@gmail.com>
parents:
10385
diff
changeset
|
122 for (octave_idx_type jb = 0; jb < nb; jb++) |
5af0b4bb384d
rewrite convn optimizations based on xAXPY
Jaroslav Hajek <highegg@gmail.com>
parents:
10385
diff
changeset
|
123 convolve_nd<T, R> (a + ma*ja, ad, acd, b + mb*jb, bd, bcd, |
5af0b4bb384d
rewrite convn optimizations based on xAXPY
Jaroslav Hajek <highegg@gmail.com>
parents:
10385
diff
changeset
|
124 c + ldc*(ja+jb), ccd, nd-1, inner); |
10385
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
125 } |
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
126 } |
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
127 } |
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
128 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
129 // Arbitrary convolutor. |
10385
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
130 // The 2nd array is assumed to be the smaller one. |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
131 template <typename T, typename R> |
10385
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
132 static MArray<T> |
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
133 convolve (const MArray<T>& a, const MArray<R>& b, |
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
134 convn_type ct) |
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
135 { |
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
136 if (a.is_empty () || b.is_empty ()) |
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
137 return MArray<T> (); |
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
138 |
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
139 int nd = std::max (a.ndims (), b.ndims ()); |
18084
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
140 const dim_vector adims = a.dims ().redim (nd); |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
141 const dim_vector bdims = b.dims ().redim (nd); |
10385
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
142 dim_vector cdims = dim_vector::alloc (nd); |
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
143 |
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
144 for (int i = 0; i < nd; i++) |
10388
5af0b4bb384d
rewrite convn optimizations based on xAXPY
Jaroslav Hajek <highegg@gmail.com>
parents:
10385
diff
changeset
|
145 { |
5af0b4bb384d
rewrite convn optimizations based on xAXPY
Jaroslav Hajek <highegg@gmail.com>
parents:
10385
diff
changeset
|
146 if (ct == convn_valid) |
10389
8a551f02f10d
oct-convn.cc (convolve): cast int constant to octave_idx_type in call to std::max
John W. Eaton <jwe@octave.org>
parents:
10388
diff
changeset
|
147 cdims(i) = std::max (adims(i) - bdims(i) + 1, |
8a551f02f10d
oct-convn.cc (convolve): cast int constant to octave_idx_type in call to std::max
John W. Eaton <jwe@octave.org>
parents:
10388
diff
changeset
|
148 static_cast<octave_idx_type> (0)); |
10388
5af0b4bb384d
rewrite convn optimizations based on xAXPY
Jaroslav Hajek <highegg@gmail.com>
parents:
10385
diff
changeset
|
149 else |
10389
8a551f02f10d
oct-convn.cc (convolve): cast int constant to octave_idx_type in call to std::max
John W. Eaton <jwe@octave.org>
parents:
10388
diff
changeset
|
150 cdims(i) = std::max (adims(i) + bdims(i) - 1, |
8a551f02f10d
oct-convn.cc (convolve): cast int constant to octave_idx_type in call to std::max
John W. Eaton <jwe@octave.org>
parents:
10388
diff
changeset
|
151 static_cast<octave_idx_type> (0)); |
10388
5af0b4bb384d
rewrite convn optimizations based on xAXPY
Jaroslav Hajek <highegg@gmail.com>
parents:
10385
diff
changeset
|
152 } |
10385
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
153 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14209
diff
changeset
|
154 MArray<T> c (cdims, T ()); |
10385
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
155 |
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
156 convolve_nd<T, R> (a.fortran_vec (), adims, adims.cumulative (), |
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
157 b.fortran_vec (), bdims, bdims.cumulative (), |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
158 c.fortran_vec (), cdims.cumulative (), |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
159 nd, ct == convn_valid); |
10385
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
160 |
10388
5af0b4bb384d
rewrite convn optimizations based on xAXPY
Jaroslav Hajek <highegg@gmail.com>
parents:
10385
diff
changeset
|
161 if (ct == convn_same) |
10385
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
162 { |
10388
5af0b4bb384d
rewrite convn optimizations based on xAXPY
Jaroslav Hajek <highegg@gmail.com>
parents:
10385
diff
changeset
|
163 // Pick the relevant part. |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
164 Array<idx_vector> sidx (dim_vector (nd, 1)); |
10388
5af0b4bb384d
rewrite convn optimizations based on xAXPY
Jaroslav Hajek <highegg@gmail.com>
parents:
10385
diff
changeset
|
165 |
5af0b4bb384d
rewrite convn optimizations based on xAXPY
Jaroslav Hajek <highegg@gmail.com>
parents:
10385
diff
changeset
|
166 for (int i = 0; i < nd; i++) |
14209
846273dae16b
Return correct part of convolution for 'same' parameter in conv2, convn (Bug #34893).
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
167 sidx(i) = idx_vector::make_range (bdims(i)/2, 1, adims(i)); |
10388
5af0b4bb384d
rewrite convn optimizations based on xAXPY
Jaroslav Hajek <highegg@gmail.com>
parents:
10385
diff
changeset
|
168 c = c.index (sidx); |
10385
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
169 } |
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
170 |
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
171 return c; |
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
172 } |
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
173 |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22135
diff
changeset
|
174 #define CONV_DEFS(TPREF, RPREF) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22135
diff
changeset
|
175 TPREF ## NDArray \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22135
diff
changeset
|
176 convn (const TPREF ## NDArray& a, const RPREF ## NDArray& b, \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22135
diff
changeset
|
177 convn_type ct) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22135
diff
changeset
|
178 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22135
diff
changeset
|
179 return convolve (a, b, ct); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22135
diff
changeset
|
180 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22135
diff
changeset
|
181 TPREF ## Matrix \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22135
diff
changeset
|
182 convn (const TPREF ## Matrix& a, const RPREF ## Matrix& b, \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22135
diff
changeset
|
183 convn_type ct) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22135
diff
changeset
|
184 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22135
diff
changeset
|
185 return convolve (a, b, ct); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22135
diff
changeset
|
186 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22135
diff
changeset
|
187 TPREF ## Matrix \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22135
diff
changeset
|
188 convn (const TPREF ## Matrix& a, const RPREF ## ColumnVector& c, \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22135
diff
changeset
|
189 const RPREF ## RowVector& r, convn_type ct) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22135
diff
changeset
|
190 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22135
diff
changeset
|
191 return convolve (a, c * r, ct); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22135
diff
changeset
|
192 } |
10385
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
193 |
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
194 CONV_DEFS ( , ) |
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
195 CONV_DEFS (Complex, ) |
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
196 CONV_DEFS (Complex, Complex) |
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
197 CONV_DEFS (Float, Float) |
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
198 CONV_DEFS (FloatComplex, Float) |
56116dceb1e0
add omitted source from the last change
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
199 CONV_DEFS (FloatComplex, FloatComplex) |
22402
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
200 |