Mercurial > octave
annotate liboctave/util/oct-binmap.h @ 27919:1891570abac8
update Octave Project Developers copyright for the new year
In files that have the "Octave Project Developers" copyright notice,
update for 2020.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 06 Jan 2020 22:29:51 -0500 |
parents | b442ec6dda5c |
children | bd51beb6205e |
rev | line source |
---|---|
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
1 /* |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
2 |
27919
1891570abac8
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27918
diff
changeset
|
3 Copyright (C) 2010-2020 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27177
diff
changeset
|
4 |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27177
diff
changeset
|
5 See the file COPYRIGHT.md in the top-level directory of this distribution |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27177
diff
changeset
|
6 or <https://octave.org/COPYRIGHT.html/>. |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27177
diff
changeset
|
7 |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
8 |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
9 This file is part of Octave. |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
10 |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23449
diff
changeset
|
11 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
|
12 under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23449
diff
changeset
|
13 the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
14 (at your option) any later version. |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
15 |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
16 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
|
17 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
19 GNU General Public License for more details. |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
20 |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
21 You should have received a copy of the GNU General Public License |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
22 along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23449
diff
changeset
|
23 <https://www.gnu.org/licenses/>. |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
24 |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
25 */ |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
26 |
20791
f7084eae3318
maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
27 #if ! defined (octave_oct_binmap_h) |
17822
ebb3ef964372
maint: Use common #define syntax "octave_filename_h" in h_files.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
28 #define octave_oct_binmap_h 1 |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
29 |
21244
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21139
diff
changeset
|
30 #include "octave-config.h" |
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21139
diff
changeset
|
31 |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
32 #include "Array.h" |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
33 #include "Sparse.h" |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
34 #include "Array-util.h" |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
35 |
13006
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
36 #include "bsxfun.h" |
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
37 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21244
diff
changeset
|
38 // This source file implements a general binary maping function for arrays. |
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21244
diff
changeset
|
39 // The syntax is binmap<type> (a, b, f,[name]). |
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21244
diff
changeset
|
40 // type denotes the expected return type of the operation. |
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21244
diff
changeset
|
41 // a, b, should be one of the 6 combinations: |
13006
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
42 // |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
43 // Array-Array |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
44 // Array-scalar |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
45 // scalar-Array |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
46 // Sparse-Sparse |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
47 // Sparse-scalar |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
48 // scalar-Sparse |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
49 // |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21244
diff
changeset
|
50 // If both operands are nonscalar, name must be supplied. It is used |
13006
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
51 // as the base for error message when operands are nonconforming. |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
52 // |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21244
diff
changeset
|
53 // The operation needs not be homogeneous, i.e., a, b and the result |
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21244
diff
changeset
|
54 // may be of distinct types. f can have any of the four signatures: |
13006
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
55 // |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
56 // U f (T, R) |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
57 // U f (const T&, R) |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
58 // U f (T, const R&) |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
59 // U f (const T&, const R&) |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
60 // |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
61 // Additionally, f can be an arbitrary functor object. |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
62 // |
13006
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
63 // octave_quit() is called at appropriate places, hence the operation |
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
64 // is breakable. |
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
65 |
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
66 // The following template wrappers are provided for automatic bsxfun |
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
67 // calls (see the function signature for do_bsxfun_op). |
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
68 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21118
diff
changeset
|
69 template <typename R, typename X, typename Y, typename F> |
13006
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
70 class bsxfun_wrapper |
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
71 { |
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
72 private: |
27177 | 73 |
74 static F s_fcn; | |
13006
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
75 |
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
76 public: |
27177 | 77 |
13006
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
78 static void |
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
79 set_f (const F& f_in) |
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
80 { |
27177 | 81 s_fcn = f_in; |
13006
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
82 } |
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
83 |
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
84 static void |
23449
c763214a8260
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
85 op_mm (size_t n, R *r, const X *x , const Y *y) |
13006
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
86 { |
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
87 for (size_t i = 0; i < n; i++) |
27177 | 88 r[i] = s_fcn (x[i], y[i]); |
13006
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
89 } |
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
90 |
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
91 static void |
23449
c763214a8260
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
92 op_sm (size_t n, R *r, X x, const Y *y) |
13006
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
93 { |
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
94 for (size_t i = 0; i < n; i++) |
27177 | 95 r[i] = s_fcn (x, y[i]); |
13006
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
96 } |
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
97 |
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
98 static void |
23449
c763214a8260
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
99 op_ms (size_t n , R *r, const X *x, Y y) |
13006
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
100 { |
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
101 for (size_t i = 0; i < n; i++) |
27177 | 102 r[i] = s_fcn (x[i], y); |
13006
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
103 } |
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
104 }; |
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
105 |
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
106 // Static init |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21118
diff
changeset
|
107 template <typename R, typename X, typename Y, typename F> |
27177 | 108 F bsxfun_wrapper<R, X, Y, F>::s_fcn; |
13006
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
109 |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
110 // scalar-Array |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21118
diff
changeset
|
111 template <typename U, typename T, typename R, typename F> |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
112 Array<U> |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
113 binmap (const T& x, const Array<R>& ya, F fcn) |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
114 { |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
115 octave_idx_type len = ya.numel (); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
116 |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
117 const R *y = ya.data (); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
118 |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
119 Array<U> result (ya.dims ()); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
120 U *p = result.fortran_vec (); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
121 |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
122 octave_idx_type i; |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
123 for (i = 0; i < len - 3; i += 4) |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
124 { |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
125 octave_quit (); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
126 |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
127 p[i] = fcn (x, y[i]); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
128 p[i+1] = fcn (x, y[i+1]); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
129 p[i+2] = fcn (x, y[i+2]); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
130 p[i+3] = fcn (x, y[i+3]); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
131 } |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
132 |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
133 octave_quit (); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
134 |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
135 for (; i < len; i++) |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
136 p[i] = fcn (x, y[i]); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
137 |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
138 return result; |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
139 } |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
140 |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
141 // Array-scalar |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21118
diff
changeset
|
142 template <typename U, typename T, typename R, typename F> |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
143 Array<U> |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
144 binmap (const Array<T>& xa, const R& y, F fcn) |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
145 { |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
146 octave_idx_type len = xa.numel (); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
147 |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
148 const R *x = xa.data (); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
149 |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
150 Array<U> result (xa.dims ()); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
151 U *p = result.fortran_vec (); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
152 |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
153 octave_idx_type i; |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
154 for (i = 0; i < len - 3; i += 4) |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
155 { |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
156 octave_quit (); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
157 |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
158 p[i] = fcn (x[i], y); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
159 p[i+1] = fcn (x[i+1], y); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
160 p[i+2] = fcn (x[i+2], y); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
161 p[i+3] = fcn (x[i+3], y); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
162 } |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
163 |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
164 octave_quit (); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
165 |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
166 for (; i < len; i++) |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
167 p[i] = fcn (x[i], y); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
168 |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
169 return result; |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
170 } |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
171 |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
172 // Array-Array (treats singletons as scalars) |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21118
diff
changeset
|
173 template <typename U, typename T, typename R, typename F> |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
174 Array<U> |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
175 binmap (const Array<T>& xa, const Array<R>& ya, F fcn, const char *name) |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
176 { |
18084
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17822
diff
changeset
|
177 dim_vector xad = xa.dims (); |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17822
diff
changeset
|
178 dim_vector yad = ya.dims (); |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
179 if (xa.numel () == 1) |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
180 return binmap<U, T, R, F> (xa(0), ya, fcn); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
181 else if (ya.numel () == 1) |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
182 return binmap<U, T, R, F> (xa, ya(0), fcn); |
13006
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
183 else if (xad != yad) |
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
184 { |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
185 if (! is_valid_bsxfun (name, xad, yad)) |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
186 octave::err_nonconformant (name, xad, yad); |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
187 |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
188 bsxfun_wrapper<U, T, R, F>::set_f(fcn); |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
189 return do_bsxfun_op (xa, ya, |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
190 bsxfun_wrapper<U, T, R, F>::op_mm, |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
191 bsxfun_wrapper<U, T, R, F>::op_sm, |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
192 bsxfun_wrapper<U, T, R, F>::op_ms); |
13006
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
193 } |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
194 |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
195 octave_idx_type len = xa.numel (); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
196 |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
197 const T *x = xa.data (); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
198 const T *y = ya.data (); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
199 |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
200 Array<U> result (xa.dims ()); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
201 U *p = result.fortran_vec (); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
202 |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
203 octave_idx_type i; |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
204 for (i = 0; i < len - 3; i += 4) |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
205 { |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
206 octave_quit (); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
207 |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
208 p[i] = fcn (x[i], y[i]); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
209 p[i+1] = fcn (x[i+1], y[i+1]); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
210 p[i+2] = fcn (x[i+2], y[i+2]); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
211 p[i+3] = fcn (x[i+3], y[i+3]); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
212 } |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
213 |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
214 octave_quit (); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
215 |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
216 for (; i < len; i++) |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
217 p[i] = fcn (x[i], y[i]); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
218 |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
219 return result; |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
220 } |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
221 |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
222 // scalar-Sparse |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21118
diff
changeset
|
223 template <typename U, typename T, typename R, typename F> |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
224 Sparse<U> |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
225 binmap (const T& x, const Sparse<R>& ys, F fcn) |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
226 { |
18789
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18788
diff
changeset
|
227 R yzero = R (); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18788
diff
changeset
|
228 U fz = fcn (x, yzero); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18788
diff
changeset
|
229 |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18788
diff
changeset
|
230 if (fz == U ()) // Sparsity preserving fcn |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
231 { |
18789
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18788
diff
changeset
|
232 octave_idx_type nz = ys.nnz (); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18788
diff
changeset
|
233 Sparse<U> retval (ys.rows (), ys.cols (), nz); |
19381
af41e41ad28e
replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
18791
diff
changeset
|
234 std::copy (ys.ridx (), ys.ridx () + nz, retval.ridx ()); |
af41e41ad28e
replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
18791
diff
changeset
|
235 std::copy (ys.cidx (), ys.cidx () + ys.cols () + 1, retval.cidx ()); |
18789
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18788
diff
changeset
|
236 |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18788
diff
changeset
|
237 for (octave_idx_type i = 0; i < nz; i++) |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18788
diff
changeset
|
238 { |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18788
diff
changeset
|
239 octave_quit (); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18788
diff
changeset
|
240 // FIXME: Could keep track of whether fcn call results in a 0. |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18788
diff
changeset
|
241 // If no zeroes are created could skip maybe_compress() |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18788
diff
changeset
|
242 retval.xdata (i) = fcn (x, ys.data (i)); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18788
diff
changeset
|
243 } |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18788
diff
changeset
|
244 |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
245 octave_quit (); |
18789
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18788
diff
changeset
|
246 retval.maybe_compress (true); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18788
diff
changeset
|
247 return retval; |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
248 } |
18789
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18788
diff
changeset
|
249 else |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18788
diff
changeset
|
250 return Sparse<U> (binmap<U, T, R, F> (x, ys.array_value (), fcn)); |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
251 } |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
252 |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
253 // Sparse-scalar |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21118
diff
changeset
|
254 template <typename U, typename T, typename R, typename F> |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
255 Sparse<U> |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
256 binmap (const Sparse<T>& xs, const R& y, F fcn) |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
257 { |
18789
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18788
diff
changeset
|
258 T xzero = T (); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18788
diff
changeset
|
259 U fz = fcn (xzero, y); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18788
diff
changeset
|
260 |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18788
diff
changeset
|
261 if (fz == U ()) // Sparsity preserving fcn |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
262 { |
18789
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18788
diff
changeset
|
263 octave_idx_type nz = xs.nnz (); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18788
diff
changeset
|
264 Sparse<U> retval (xs.rows (), xs.cols (), nz); |
19381
af41e41ad28e
replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
18791
diff
changeset
|
265 std::copy (xs.ridx (), xs.ridx () + nz, retval.ridx ()); |
af41e41ad28e
replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
18791
diff
changeset
|
266 std::copy (xs.cidx (), xs.cidx () + xs.cols () + 1, retval.cidx ()); |
18789
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18788
diff
changeset
|
267 |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18788
diff
changeset
|
268 for (octave_idx_type i = 0; i < nz; i++) |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18788
diff
changeset
|
269 { |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18788
diff
changeset
|
270 octave_quit (); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18788
diff
changeset
|
271 // FIXME: Could keep track of whether fcn call results in a 0. |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18788
diff
changeset
|
272 // If no zeroes are created could skip maybe_compress() |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18788
diff
changeset
|
273 retval.xdata (i) = fcn (xs.data (i), y); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18788
diff
changeset
|
274 } |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18788
diff
changeset
|
275 |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
276 octave_quit (); |
18789
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18788
diff
changeset
|
277 retval.maybe_compress (true); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18788
diff
changeset
|
278 return retval; |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
279 } |
18789
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18788
diff
changeset
|
280 else |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18788
diff
changeset
|
281 return Sparse<U> (binmap<U, T, R, F> (xs.array_value (), y, fcn)); |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
282 } |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
283 |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
284 // Sparse-Sparse (treats singletons as scalars) |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21118
diff
changeset
|
285 template <typename U, typename T, typename R, typename F> |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
286 Sparse<U> |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
287 binmap (const Sparse<T>& xs, const Sparse<R>& ys, F fcn, const char *name) |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
288 { |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
289 if (xs.rows () == 1 && xs.cols () == 1) |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
290 return binmap<U, T, R, F> (xs(0,0), ys, fcn); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
291 else if (ys.rows () == 1 && ys.cols () == 1) |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
292 return binmap<U, T, R, F> (xs, ys(0,0), fcn); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
293 else if (xs.dims () != ys.dims ()) |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
294 octave::err_nonconformant (name, xs.dims (), ys.dims ()); |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
295 |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
296 T xzero = T (); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
297 R yzero = R (); |
18788
658d23da2c46
Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents:
17822
diff
changeset
|
298 U fz = fcn (xzero, yzero); |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
299 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
300 if (fz == U ()) |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
301 { |
18788
658d23da2c46
Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents:
17822
diff
changeset
|
302 // Sparsity-preserving function. Do it efficiently. |
658d23da2c46
Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents:
17822
diff
changeset
|
303 octave_idx_type nr = xs.rows (); |
658d23da2c46
Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents:
17822
diff
changeset
|
304 octave_idx_type nc = xs.cols (); |
658d23da2c46
Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents:
17822
diff
changeset
|
305 Sparse<T> retval (nr, nc, xs.nnz () + ys.nnz ()); |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
306 |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
307 octave_idx_type nz = 0; |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
308 for (octave_idx_type j = 0; j < nc; j++) |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
309 { |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
310 octave_quit (); |
18788
658d23da2c46
Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents:
17822
diff
changeset
|
311 |
658d23da2c46
Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents:
17822
diff
changeset
|
312 octave_idx_type jx = xs.cidx (j); |
658d23da2c46
Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents:
17822
diff
changeset
|
313 octave_idx_type jx_max = xs.cidx (j+1); |
658d23da2c46
Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents:
17822
diff
changeset
|
314 bool jx_lt_max = jx < jx_max; |
658d23da2c46
Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents:
17822
diff
changeset
|
315 |
658d23da2c46
Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents:
17822
diff
changeset
|
316 octave_idx_type jy = ys.cidx (j); |
658d23da2c46
Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents:
17822
diff
changeset
|
317 octave_idx_type jy_max = ys.cidx (j+1); |
658d23da2c46
Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents:
17822
diff
changeset
|
318 bool jy_lt_max = jy < jy_max; |
658d23da2c46
Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents:
17822
diff
changeset
|
319 |
658d23da2c46
Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents:
17822
diff
changeset
|
320 while (jx_lt_max || jy_lt_max) |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
321 { |
18788
658d23da2c46
Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents:
17822
diff
changeset
|
322 if (! jy_lt_max |
658d23da2c46
Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents:
17822
diff
changeset
|
323 || (jx_lt_max && (xs.ridx (jx) < ys.ridx (jy)))) |
658d23da2c46
Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents:
17822
diff
changeset
|
324 { |
658d23da2c46
Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents:
17822
diff
changeset
|
325 retval.xridx (nz) = xs.ridx (jx); |
658d23da2c46
Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents:
17822
diff
changeset
|
326 retval.xdata (nz) = fcn (xs.data (jx), yzero); |
658d23da2c46
Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents:
17822
diff
changeset
|
327 jx++; |
658d23da2c46
Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents:
17822
diff
changeset
|
328 jx_lt_max = jx < jx_max; |
658d23da2c46
Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents:
17822
diff
changeset
|
329 } |
18789
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18788
diff
changeset
|
330 else if (! jx_lt_max |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18788
diff
changeset
|
331 || (jy_lt_max && (ys.ridx (jy) < xs.ridx (jx)))) |
18788
658d23da2c46
Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents:
17822
diff
changeset
|
332 { |
658d23da2c46
Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents:
17822
diff
changeset
|
333 retval.xridx (nz) = ys.ridx (jy); |
658d23da2c46
Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents:
17822
diff
changeset
|
334 retval.xdata (nz) = fcn (xzero, ys.data (jy)); |
658d23da2c46
Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents:
17822
diff
changeset
|
335 jy++; |
658d23da2c46
Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents:
17822
diff
changeset
|
336 jy_lt_max = jy < jy_max; |
658d23da2c46
Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents:
17822
diff
changeset
|
337 } |
658d23da2c46
Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents:
17822
diff
changeset
|
338 else |
658d23da2c46
Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents:
17822
diff
changeset
|
339 { |
658d23da2c46
Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents:
17822
diff
changeset
|
340 retval.xridx (nz) = xs.ridx (jx); |
658d23da2c46
Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents:
17822
diff
changeset
|
341 retval.xdata (nz) = fcn (xs.data (jx), ys.data (jy)); |
658d23da2c46
Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents:
17822
diff
changeset
|
342 jx++; |
658d23da2c46
Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents:
17822
diff
changeset
|
343 jx_lt_max = jx < jx_max; |
658d23da2c46
Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents:
17822
diff
changeset
|
344 jy++; |
658d23da2c46
Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents:
17822
diff
changeset
|
345 jy_lt_max = jy < jy_max; |
658d23da2c46
Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents:
17822
diff
changeset
|
346 } |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
347 nz++; |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
348 } |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
349 retval.xcidx (j+1) = nz; |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
350 } |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
351 |
18788
658d23da2c46
Fix infinite loop and segfault for atan2, fmod, hypot (bug #40813).
Stefan Mahr <dac922@gmx.de>
parents:
17822
diff
changeset
|
352 retval.maybe_compress (true); |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
353 return retval; |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
354 } |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
355 else |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
356 return Sparse<U> (binmap<U, T, R, F> (xs.array_value (), ys.array_value (), |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
357 fcn, name)); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
358 } |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
359 |
13006
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
360 // Overloads for function pointers. |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
361 |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
362 // Signature (T, R) |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
363 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21118
diff
changeset
|
364 template <typename U, typename T, typename R> |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
365 inline Array<U> |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
366 binmap (const Array<T>& xa, const Array<R>& ya, U (*fcn) (T, R), |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
367 const char *name) |
13006
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
368 { return binmap<U, T, R, U (*) (T, R)> (xa, ya, fcn, name); } |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
369 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21118
diff
changeset
|
370 template <typename U, typename T, typename R> |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
371 inline Array<U> |
13006
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
372 binmap (const T& x, const Array<R>& ya, U (*fcn) (T, R)) |
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
373 { return binmap<U, T, R, U (*) (T, R)> (x, ya, fcn); } |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
374 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21118
diff
changeset
|
375 template <typename U, typename T, typename R> |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
376 inline Array<U> |
13006
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
377 binmap (const Array<T>& xa, const R& y, U (*fcn) (T, R)) |
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
378 { return binmap<U, T, R, U (*) (T, R)> (xa, y, fcn); } |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
379 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21118
diff
changeset
|
380 template <typename U, typename T, typename R> |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
381 inline Sparse<U> |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
382 binmap (const Sparse<T>& xa, const Sparse<R>& ya, U (*fcn) (T, R), |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
383 const char *name) |
13006
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
384 { return binmap<U, T, R, U (*) (T, R)> (xa, ya, fcn, name); } |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
385 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21118
diff
changeset
|
386 template <typename U, typename T, typename R> |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
387 inline Sparse<U> |
13006
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
388 binmap (const T& x, const Sparse<R>& ya, U (*fcn) (T, R)) |
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
389 { return binmap<U, T, R, U (*) (T, R)> (x, ya, fcn); } |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
390 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21118
diff
changeset
|
391 template <typename U, typename T, typename R> |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
392 inline Sparse<U> |
13006
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
393 binmap (const Sparse<T>& xa, const R& y, U (*fcn) (T, R)) |
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
394 { return binmap<U, T, R, U (*) (T, R)> (xa, y, fcn); } |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
395 |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
396 // Signature (const T&, const R&) |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
397 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21118
diff
changeset
|
398 template <typename U, typename T, typename R> |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
399 inline Array<U> |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
400 binmap (const Array<T>& xa, const Array<R>& ya, U (*fcn) (const T&, const R&), |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
401 const char *name) |
13006
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
402 { return binmap<U, T, R, U (*) (const T&, const R&)> (xa, ya, fcn, name); } |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
403 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21118
diff
changeset
|
404 template <typename U, typename T, typename R> |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
405 inline Array<U> |
13006
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
406 binmap (const T& x, const Array<R>& ya, U (*fcn) (const T&, const R&)) |
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
407 { return binmap<U, T, R, U (*) (const T&, const R&)> (x, ya, fcn); } |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
408 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21118
diff
changeset
|
409 template <typename U, typename T, typename R> |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
410 inline Array<U> |
13006
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
411 binmap (const Array<T>& xa, const R& y, U (*fcn) (const T&, const R&)) |
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
412 { return binmap<U, T, R, U (*) (const T&, const R&)> (xa, y, fcn); } |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
413 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21118
diff
changeset
|
414 template <typename U, typename T, typename R> |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
415 inline Sparse<U> |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
416 binmap (const Sparse<T>& xa, const Sparse<R>& ya, U (*fcn) (const T&, const R&), |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
417 const char *name) |
13006
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
418 { return binmap<U, T, R, U (*) (const T&, const R&)> (xa, ya, fcn, name); } |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
419 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21118
diff
changeset
|
420 template <typename U, typename T, typename R> |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
421 inline Sparse<U> |
13006
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
422 binmap (const T& x, const Sparse<R>& ya, U (*fcn) (const T&, const R&)) |
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
423 { return binmap<U, T, R, U (*) (const T&, const R&)> (x, ya, fcn); } |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
424 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21118
diff
changeset
|
425 template <typename U, typename T, typename R> |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
426 inline Sparse<U> |
13006
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
427 binmap (const Sparse<T>& xa, const R& y, U (*fcn) (const T&, const R&)) |
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
428 { return binmap<U, T, R, U (*) (const T&, const R&)> (xa, y, fcn); } |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
429 |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
430 // Signature (const T&, R) |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
431 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21118
diff
changeset
|
432 template <typename U, typename T, typename R> |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
433 inline Array<U> |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
434 binmap (const Array<T>& xa, const Array<R>& ya, U (*fcn) (const T&, R), |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
435 const char *name) |
13006
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
436 { return binmap<U, T, R, U (*) (const T&, R)> (xa, ya, fcn, name); } |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
437 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21118
diff
changeset
|
438 template <typename U, typename T, typename R> |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
439 inline Array<U> |
13006
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
440 binmap (const T& x, const Array<R>& ya, U (*fcn) (const T&, R)) |
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
441 { return binmap<U, T, R, U (*) (const T&, R)> (x, ya, fcn); } |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
442 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21118
diff
changeset
|
443 template <typename U, typename T, typename R> |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
444 inline Array<U> |
13006
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
445 binmap (const Array<T>& xa, const R& y, U (*fcn) (const T&, R)) |
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
446 { return binmap<U, T, R, U (*) (const T&, R)> (xa, y, fcn); } |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
447 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21118
diff
changeset
|
448 template <typename U, typename T, typename R> |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
449 inline Sparse<U> |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
450 binmap (const Sparse<T>& xa, const Sparse<R>& ya, U (*fcn) (const T&, R), |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
451 const char *name) |
13006
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
452 { return binmap<U, T, R, U (*) (const T&, R)> (xa, ya, fcn, name); } |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
453 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21118
diff
changeset
|
454 template <typename U, typename T, typename R> |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
455 inline Sparse<U> |
13006
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
456 binmap (const T& x, const Sparse<R>& ya, U (*fcn) (const T&, R)) |
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
457 { return binmap<U, T, R, U (*) (const T&, R)> (x, ya, fcn); } |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
458 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21118
diff
changeset
|
459 template <typename U, typename T, typename R> |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
460 inline Sparse<U> |
13006
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
461 binmap (const Sparse<T>& xa, const R& y, U (*fcn) (const T&, R)) |
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
462 { return binmap<U, T, R, U (*) (const T&, R)> (xa, y, fcn); } |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
463 |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
464 // Signature (T, const R&) |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
465 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21118
diff
changeset
|
466 template <typename U, typename T, typename R> |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
467 inline Array<U> |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
468 binmap (const Array<T>& xa, const Array<R>& ya, U (*fcn) (T, const R&), |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
469 const char *name) |
13006
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
470 { return binmap<U, T, R, U (*) (T, const R&)> (xa, ya, fcn, name); } |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
471 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21118
diff
changeset
|
472 template <typename U, typename T, typename R> |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
473 inline Array<U> |
13006
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
474 binmap (const T& x, const Array<R>& ya, U (*fcn) (T, const R&)) |
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
475 { return binmap<U, T, R, U (*) (T, const R&)> (x, ya, fcn); } |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
476 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21118
diff
changeset
|
477 template <typename U, typename T, typename R> |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
478 inline Array<U> |
13006
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
479 binmap (const Array<T>& xa, const R& y, U (*fcn) (T, const R&)) |
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
480 { return binmap<U, T, R, U (*) (T, const R&)> (xa, y, fcn); } |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
481 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21118
diff
changeset
|
482 template <typename U, typename T, typename R> |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
483 inline Sparse<U> |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
484 binmap (const Sparse<T>& xa, const Sparse<R>& ya, U (*fcn) (T, const R&), |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
485 const char *name) |
13006
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
486 { return binmap<U, T, R, U (*) (T, const R&)> (xa, ya, fcn, name); } |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
487 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21118
diff
changeset
|
488 template <typename U, typename T, typename R> |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
489 inline Sparse<U> |
13006
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
490 binmap (const T& x, const Sparse<R>& ya, U (*fcn) (T, const R&)) |
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
491 { return binmap<U, T, R, U (*) (T, const R&)> (x, ya, fcn); } |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
492 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21118
diff
changeset
|
493 template <typename U, typename T, typename R> |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
494 inline Sparse<U> |
13006
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
495 binmap (const Sparse<T>& xa, const R& y, U (*fcn) (T, const R&)) |
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
496 { return binmap<U, T, R, U (*) (T, const R&)> (xa, y, fcn); } |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
497 |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
498 #endif |