annotate liboctave/operators/mx-inlines.cc @ 23219:3ac9f9ecfae5 stable

maint: Update copyright dates.
author John W. Eaton <jwe@octave.org>
date Wed, 22 Feb 2017 12:39:29 -0500
parents e9a0469dedd9
children 092078913d54
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
1 /*
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
2
23219
3ac9f9ecfae5 maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents: 23083
diff changeset
3 Copyright (C) 1993-2017 John W. Eaton
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
4 Copyright (C) 2009 Jaroslav Hajek
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
5 Copyright (C) 2009 VZLU Prague
3
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
6
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
7 This file is part of Octave.
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
8
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
9 Octave is free software; you can redistribute it and/or modify it
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
10 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5972
diff changeset
11 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5972
diff changeset
12 option) any later version.
3
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
13
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
14 Octave is distributed in the hope that it will be useful, but WITHOUT
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
17 for more details.
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
18
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
19 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5972
diff changeset
20 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5972
diff changeset
21 <http://www.gnu.org/licenses/>.
3
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
22
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
23 */
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
24
20791
f7084eae3318 maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents: 20232
diff changeset
25 #if ! defined (octave_mx_inlines_h)
2828
92826d6e8bd9 [project @ 1997-03-25 23:41:41 by jwe]
jwe
parents: 2811
diff changeset
26 #define octave_mx_inlines_h 1
2804
eedc2f3f61f7 [project @ 1997-03-11 04:34:50 by jwe]
jwe
parents: 2386
diff changeset
27
21690
b6a686543080 Only include config.h in files that are compiled separately.
John W. Eaton <jwe@octave.org>
parents: 21660
diff changeset
28 // This file should not include config.h. It is only included in other
b6a686543080 Only include config.h in files that are compiled separately.
John W. Eaton <jwe@octave.org>
parents: 21660
diff changeset
29 // C++ source files that should have included config.h before including
b6a686543080 Only include config.h in files that are compiled separately.
John W. Eaton <jwe@octave.org>
parents: 21660
diff changeset
30 // this file.
b6a686543080 Only include config.h in files that are compiled separately.
John W. Eaton <jwe@octave.org>
parents: 21660
diff changeset
31
2804
eedc2f3f61f7 [project @ 1997-03-11 04:34:50 by jwe]
jwe
parents: 2386
diff changeset
32 #include <cstddef>
8650
a1ae2aae903e abs,real,imag,conj: use code from mx-inlines rather than the generic map
Jaroslav Hajek <highegg@gmail.com>
parents: 8380
diff changeset
33 #include <cmath>
19381
af41e41ad28e replace oct-mem.h inline indirections by standard function calls.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 18725
diff changeset
34 #include <cstring>
10146
9597eea7fa36 inline xmin/xmax & optimize special cases
Jaroslav Hajek <highegg@gmail.com>
parents: 9827
diff changeset
35 #include <memory>
2804
eedc2f3f61f7 [project @ 1997-03-11 04:34:50 by jwe]
jwe
parents: 2386
diff changeset
36
5525
558c69736dc0 [project @ 2005-11-01 00:49:50 by jwe]
jwe
parents: 5524
diff changeset
37 #include "quit.h"
558c69736dc0 [project @ 2005-11-01 00:49:50 by jwe]
jwe
parents: 5524
diff changeset
38
1650
23aa282707e8 [project @ 1995-12-20 06:53:12 by jwe]
jwe
parents: 1574
diff changeset
39 #include "oct-cmplx.h"
8758
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
40 #include "oct-locbuf.h"
8897
fd83cc87f55e add missing include
Jaroslav Hajek <highegg@gmail.com>
parents: 8780
diff changeset
41 #include "oct-inttypes.h"
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
42 #include "Array.h"
10146
9597eea7fa36 inline xmin/xmax & optimize special cases
Jaroslav Hajek <highegg@gmail.com>
parents: 9827
diff changeset
43 #include "Array-util.h"
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
44
13004
d9d65c3017c3 Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
45 #include "bsxfun.h"
d9d65c3017c3 Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
46
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
47 // Provides some commonly repeated, basic loop templates.
461
00f8b2242a18 [project @ 1994-06-06 00:45:57 by jwe]
jwe
parents: 238
diff changeset
48
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
49 template <typename R, typename S>
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
50 inline void mx_inline_fill (size_t n, R *r, S s) throw ()
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
51 {
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
52 for (size_t i = 0; i < n; i++)
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
53 r[i] = s;
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
54 }
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
55
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
56 #define DEFMXUNOP(F, OP) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
57 template <typename R, typename X> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
58 inline void F (size_t n, R *r, const X *x) throw () \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
59 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
60 for (size_t i = 0; i < n; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
61 r[i] = OP x[i]; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
62 }
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
63
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
64 DEFMXUNOP (mx_inline_uminus, -)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
65
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
66 #define DEFMXUNOPEQ(F, OP) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
67 template <typename R> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
68 inline void F (size_t n, R *r) throw () \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
69 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
70 for (size_t i = 0; i < n; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
71 r[i] = OP r[i]; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
72 }
9607
1be3c73ed7b5 reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents: 9578
diff changeset
73
1be3c73ed7b5 reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents: 9578
diff changeset
74 DEFMXUNOPEQ (mx_inline_uminus2, -)
1be3c73ed7b5 reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents: 9578
diff changeset
75
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
76 #define DEFMXUNBOOLOP(F, OP) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
77 template <typename X> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
78 inline void F (size_t n, bool *r, const X *x) throw () \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
79 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
80 const X zero = X (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
81 for (size_t i = 0; i < n; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
82 r[i] = x[i] OP zero; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
83 }
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
84
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
85 DEFMXUNBOOLOP (mx_inline_iszero, ==)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
86 DEFMXUNBOOLOP (mx_inline_notzero, !=)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
87
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
88 #define DEFMXBINOP(F, OP) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
89 template <typename R, typename X, typename Y> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
90 inline void F (size_t n, R *r, const X *x, const Y *y) throw () \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
91 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
92 for (size_t i = 0; i < n; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
93 r[i] = x[i] OP y[i]; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
94 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
95 template <typename R, typename X, typename Y> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
96 inline void F (size_t n, R *r, const X *x, Y y) throw () \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
97 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
98 for (size_t i = 0; i < n; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
99 r[i] = x[i] OP y; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
100 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
101 template <typename R, typename X, typename Y> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
102 inline void F (size_t n, R *r, X x, const Y *y) throw () \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
103 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
104 for (size_t i = 0; i < n; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
105 r[i] = x OP y[i]; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
106 }
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
107
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
108 DEFMXBINOP (mx_inline_add, +)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
109 DEFMXBINOP (mx_inline_sub, -)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
110 DEFMXBINOP (mx_inline_mul, *)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
111 DEFMXBINOP (mx_inline_div, /)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
112
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
113 #define DEFMXBINOPEQ(F, OP) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
114 template <typename R, typename X> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
115 inline void F (size_t n, R *r, const X *x) throw () \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
116 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
117 for (size_t i = 0; i < n; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
118 r[i] OP x[i]; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
119 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
120 template <typename R, typename X> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
121 inline void F (size_t n, R *r, X x) throw () \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
122 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
123 for (size_t i = 0; i < n; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
124 r[i] OP x; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
125 }
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
126
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
127 DEFMXBINOPEQ (mx_inline_add2, +=)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
128 DEFMXBINOPEQ (mx_inline_sub2, -=)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
129 DEFMXBINOPEQ (mx_inline_mul2, *=)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
130 DEFMXBINOPEQ (mx_inline_div2, /=)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
131
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
132 #define DEFMXCMPOP(F, OP) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
133 template <typename X, typename Y> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
134 inline void F (size_t n, bool *r, const X *x, const Y *y) throw () \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
135 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
136 for (size_t i = 0; i < n; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
137 r[i] = x[i] OP y[i]; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
138 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
139 template <typename X, typename Y> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
140 inline void F (size_t n, bool *r, const X *x, Y y) throw () \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
141 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
142 for (size_t i = 0; i < n; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
143 r[i] = x[i] OP y; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
144 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
145 template <typename X, typename Y> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
146 inline void F (size_t n, bool *r, X x, const Y *y) throw () \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
147 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
148 for (size_t i = 0; i < n; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
149 r[i] = x OP y[i]; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
150 }
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
151
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
152 DEFMXCMPOP (mx_inline_lt, <)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
153 DEFMXCMPOP (mx_inline_le, <=)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
154 DEFMXCMPOP (mx_inline_gt, >)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
155 DEFMXCMPOP (mx_inline_ge, >=)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
156 DEFMXCMPOP (mx_inline_eq, ==)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
157 DEFMXCMPOP (mx_inline_ne, !=)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
158
9553
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
159 // Convert to logical value, for logical op purposes.
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
160 template <typename T>
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
161 inline bool
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
162 logical_value (T x)
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
163 {
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
164 return x;
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
165 }
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
166
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
167 template <typename T>
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
168 inline bool
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
169 logical_value (const std::complex<T>& x)
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
170 {
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
171 return x.real () != 0 || x.imag () != 0;
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
172 }
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
173
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
174 template <typename T>
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
175 inline bool
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
176 logical_value (const octave_int<T>& x)
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
177 {
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
178 return x.value ();
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
179 }
9553
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
180
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
181 template <typename X>
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
182 void mx_inline_not (size_t n, bool *r, const X* x) throw ()
9553
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
183 {
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
184 for (size_t i = 0; i < n; i++)
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
185 r[i] = ! logical_value (x[i]);
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
186 }
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
187
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
188 inline void mx_inline_not2 (size_t n, bool *r) throw ()
9607
1be3c73ed7b5 reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents: 9578
diff changeset
189 {
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
190 for (size_t i = 0; i < n; i++)
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
191 r[i] = ! r[i];
9607
1be3c73ed7b5 reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents: 9578
diff changeset
192 }
1be3c73ed7b5 reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents: 9578
diff changeset
193
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
194 #define DEFMXBOOLOP(F, NOT1, OP, NOT2) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
195 template <typename X, typename Y> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
196 inline void F (size_t n, bool *r, const X *x, const Y *y) throw () \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
197 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
198 for (size_t i = 0; i < n; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
199 r[i] = ((NOT1 logical_value (x[i])) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
200 OP (NOT2 logical_value (y[i]))); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
201 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
202 template <typename X, typename Y> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
203 inline void F (size_t n, bool *r, const X *x, Y y) throw () \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
204 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
205 const bool yy = (NOT2 logical_value (y)); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
206 for (size_t i = 0; i < n; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
207 r[i] = (NOT1 logical_value (x[i])) OP yy; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
208 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
209 template <typename X, typename Y> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
210 inline void F (size_t n, bool *r, X x, const Y *y) throw () \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
211 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
212 const bool xx = (NOT1 logical_value (x)); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
213 for (size_t i = 0; i < n; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
214 r[i] = xx OP (NOT2 logical_value (y[i])); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
215 }
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
216
9553
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
217 DEFMXBOOLOP (mx_inline_and, , &, )
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
218 DEFMXBOOLOP (mx_inline_or, , |, )
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
219 DEFMXBOOLOP (mx_inline_not_and, !, &, )
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
220 DEFMXBOOLOP (mx_inline_not_or, !, |, )
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
221 DEFMXBOOLOP (mx_inline_and_not, , &, !)
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
222 DEFMXBOOLOP (mx_inline_or_not, , |, !)
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
223
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
224 #define DEFMXBOOLOPEQ(F, OP) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
225 template <typename X> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
226 inline void F (size_t n, bool *r, const X *x) throw () \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
227 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
228 for (size_t i = 0; i < n; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
229 r[i] OP logical_value (x[i]); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
230 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
231 template <typename X> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
232 inline void F (size_t n, bool *r, X x) throw () \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
233 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
234 for (size_t i = 0; i < n; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
235 r[i] OP x; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
236 }
9612
66970dd627f6 further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9607
diff changeset
237
66970dd627f6 further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9607
diff changeset
238 DEFMXBOOLOPEQ (mx_inline_and2, &=)
66970dd627f6 further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9607
diff changeset
239 DEFMXBOOLOPEQ (mx_inline_or2, |=)
66970dd627f6 further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9607
diff changeset
240
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
241 template <typename T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
242 inline bool
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
243 mx_inline_any_nan (size_t n, const T* x) throw ()
9814
2b29f3472e20 add a couple of useful loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
244 {
2b29f3472e20 add a couple of useful loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
245 for (size_t i = 0; i < n; i++)
2b29f3472e20 add a couple of useful loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
246 {
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
247 if (octave::math::isnan (x[i]))
9814
2b29f3472e20 add a couple of useful loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
248 return true;
2b29f3472e20 add a couple of useful loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
249 }
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
250
9814
2b29f3472e20 add a couple of useful loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
251 return false;
8380
dbe67764e628 fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents: 7789
diff changeset
252 }
dbe67764e628 fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents: 7789
diff changeset
253
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
254 template <typename T>
10900
b64803a8be4e optimize element-wise sparse-dense multiplication and division
Jaroslav Hajek <highegg@gmail.com>
parents: 10643
diff changeset
255 inline bool
b64803a8be4e optimize element-wise sparse-dense multiplication and division
Jaroslav Hajek <highegg@gmail.com>
parents: 10643
diff changeset
256 mx_inline_all_finite (size_t n, const T* x) throw ()
b64803a8be4e optimize element-wise sparse-dense multiplication and division
Jaroslav Hajek <highegg@gmail.com>
parents: 10643
diff changeset
257 {
b64803a8be4e optimize element-wise sparse-dense multiplication and division
Jaroslav Hajek <highegg@gmail.com>
parents: 10643
diff changeset
258 for (size_t i = 0; i < n; i++)
b64803a8be4e optimize element-wise sparse-dense multiplication and division
Jaroslav Hajek <highegg@gmail.com>
parents: 10643
diff changeset
259 {
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
260 if (! octave::math::finite (x[i]))
10900
b64803a8be4e optimize element-wise sparse-dense multiplication and division
Jaroslav Hajek <highegg@gmail.com>
parents: 10643
diff changeset
261 return false;
b64803a8be4e optimize element-wise sparse-dense multiplication and division
Jaroslav Hajek <highegg@gmail.com>
parents: 10643
diff changeset
262 }
b64803a8be4e optimize element-wise sparse-dense multiplication and division
Jaroslav Hajek <highegg@gmail.com>
parents: 10643
diff changeset
263
b64803a8be4e optimize element-wise sparse-dense multiplication and division
Jaroslav Hajek <highegg@gmail.com>
parents: 10643
diff changeset
264 return true;
b64803a8be4e optimize element-wise sparse-dense multiplication and division
Jaroslav Hajek <highegg@gmail.com>
parents: 10643
diff changeset
265 }
b64803a8be4e optimize element-wise sparse-dense multiplication and division
Jaroslav Hajek <highegg@gmail.com>
parents: 10643
diff changeset
266
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
267 template <typename T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
268 inline bool
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
269 mx_inline_any_negative (size_t n, const T* x) throw ()
9827
c15a5ed0da58 optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents: 9814
diff changeset
270 {
c15a5ed0da58 optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents: 9814
diff changeset
271 for (size_t i = 0; i < n; i++)
c15a5ed0da58 optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents: 9814
diff changeset
272 {
c15a5ed0da58 optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents: 9814
diff changeset
273 if (x[i] < 0)
c15a5ed0da58 optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents: 9814
diff changeset
274 return true;
c15a5ed0da58 optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents: 9814
diff changeset
275 }
c15a5ed0da58 optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents: 9814
diff changeset
276
c15a5ed0da58 optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents: 9814
diff changeset
277 return false;
c15a5ed0da58 optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents: 9814
diff changeset
278 }
c15a5ed0da58 optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents: 9814
diff changeset
279
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
280 template <typename T>
13756
6dfebfa334cb allow negative data log plots with OpenGL+FLTK graphics (bug #34232)
John W. Eaton <jwe@octave.org>
parents: 13139
diff changeset
281 inline bool
6dfebfa334cb allow negative data log plots with OpenGL+FLTK graphics (bug #34232)
John W. Eaton <jwe@octave.org>
parents: 13139
diff changeset
282 mx_inline_any_positive (size_t n, const T* x) throw ()
6dfebfa334cb allow negative data log plots with OpenGL+FLTK graphics (bug #34232)
John W. Eaton <jwe@octave.org>
parents: 13139
diff changeset
283 {
6dfebfa334cb allow negative data log plots with OpenGL+FLTK graphics (bug #34232)
John W. Eaton <jwe@octave.org>
parents: 13139
diff changeset
284 for (size_t i = 0; i < n; i++)
6dfebfa334cb allow negative data log plots with OpenGL+FLTK graphics (bug #34232)
John W. Eaton <jwe@octave.org>
parents: 13139
diff changeset
285 {
6dfebfa334cb allow negative data log plots with OpenGL+FLTK graphics (bug #34232)
John W. Eaton <jwe@octave.org>
parents: 13139
diff changeset
286 if (x[i] > 0)
6dfebfa334cb allow negative data log plots with OpenGL+FLTK graphics (bug #34232)
John W. Eaton <jwe@octave.org>
parents: 13139
diff changeset
287 return true;
6dfebfa334cb allow negative data log plots with OpenGL+FLTK graphics (bug #34232)
John W. Eaton <jwe@octave.org>
parents: 13139
diff changeset
288 }
6dfebfa334cb allow negative data log plots with OpenGL+FLTK graphics (bug #34232)
John W. Eaton <jwe@octave.org>
parents: 13139
diff changeset
289
6dfebfa334cb allow negative data log plots with OpenGL+FLTK graphics (bug #34232)
John W. Eaton <jwe@octave.org>
parents: 13139
diff changeset
290 return false;
6dfebfa334cb allow negative data log plots with OpenGL+FLTK graphics (bug #34232)
John W. Eaton <jwe@octave.org>
parents: 13139
diff changeset
291 }
6dfebfa334cb allow negative data log plots with OpenGL+FLTK graphics (bug #34232)
John W. Eaton <jwe@octave.org>
parents: 13139
diff changeset
292
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
293 template <typename T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
294 inline bool
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
295 mx_inline_all_real (size_t n, const std::complex<T>* x) throw ()
9814
2b29f3472e20 add a couple of useful loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
296 {
2b29f3472e20 add a couple of useful loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
297 for (size_t i = 0; i < n; i++)
2b29f3472e20 add a couple of useful loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
298 {
2b29f3472e20 add a couple of useful loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
299 if (x[i].imag () != 0)
2b29f3472e20 add a couple of useful loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
300 return false;
2b29f3472e20 add a couple of useful loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
301 }
2b29f3472e20 add a couple of useful loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
302
2b29f3472e20 add a couple of useful loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
303 return true;
2b29f3472e20 add a couple of useful loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
304 }
2811
1dd37f97364a [project @ 1997-03-12 23:06:13 by jwe]
jwe
parents: 2804
diff changeset
305
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
306 #define DEFMXMAPPER(F, FUN) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
307 template <typename T> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
308 inline void F (size_t n, T *r, const T *x) throw () \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
309 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
310 for (size_t i = 0; i < n; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
311 r[i] = FUN (x[i]); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
312 }
9800
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
313
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
314 template <typename T>
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
315 inline void mx_inline_real (size_t n, T *r, const std::complex<T>* x) throw ()
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
316 {
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
317 for (size_t i = 0; i < n; i++)
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
318 r[i] = x[i].real ();
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
319 }
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
320
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
321 template <typename T>
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
322 inline void mx_inline_imag (size_t n, T *r, const std::complex<T>* x) throw ()
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
323 {
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
324 for (size_t i = 0; i < n; i++)
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
325 r[i] = x[i].imag ();
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
326 }
9800
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
327
9743
26abff55f6fe optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents: 9721
diff changeset
328 // Pairwise minimums/maximums
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
329 #define DEFMXMAPPER2(F, FUN) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
330 template <typename T> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
331 inline void F (size_t n, T *r, const T *x, const T *y) throw () \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
332 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
333 for (size_t i = 0; i < n; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
334 r[i] = FUN (x[i], y[i]); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
335 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
336 template <typename T> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
337 inline void F (size_t n, T *r, const T *x, T y) throw () \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
338 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
339 for (size_t i = 0; i < n; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
340 r[i] = FUN (x[i], y); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
341 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
342 template <typename T> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
343 inline void F (size_t n, T *r, T x, const T *y) throw () \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
344 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
345 for (size_t i = 0; i < n; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
346 r[i] = FUN (x, y[i]); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
347 }
3
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
348
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
349 DEFMXMAPPER2 (mx_inline_xmin, octave::math::min)
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
350 DEFMXMAPPER2 (mx_inline_xmax, octave::math::max)
2811
1dd37f97364a [project @ 1997-03-12 23:06:13 by jwe]
jwe
parents: 2804
diff changeset
351
10146
9597eea7fa36 inline xmin/xmax & optimize special cases
Jaroslav Hajek <highegg@gmail.com>
parents: 9827
diff changeset
352 // Specialize array-scalar max/min
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
353 #define DEFMINMAXSPEC(T, F, OP) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
354 template <> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
355 inline void F<T> (size_t n, T *r, const T *x, T y) throw () \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
356 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
357 if (octave::math::isnan (y)) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
358 std::memcpy (r, x, n * sizeof (T)); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
359 else \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
360 for (size_t i = 0; i < n; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
361 r[i] = (x[i] OP y) ? x[i] : y; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
362 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
363 template <> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
364 inline void F<T> (size_t n, T *r, T x, const T *y) throw () \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
365 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
366 if (octave::math::isnan (x)) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
367 std::memcpy (r, y, n * sizeof (T)); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
368 else \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
369 for (size_t i = 0; i < n; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
370 r[i] = (y[i] OP x) ? y[i] : x; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
371 }
10146
9597eea7fa36 inline xmin/xmax & optimize special cases
Jaroslav Hajek <highegg@gmail.com>
parents: 9827
diff changeset
372
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
373 DEFMINMAXSPEC (double, mx_inline_xmin, <=)
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
374 DEFMINMAXSPEC (double, mx_inline_xmax, >=)
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
375 DEFMINMAXSPEC (float, mx_inline_xmin, <=)
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
376 DEFMINMAXSPEC (float, mx_inline_xmax, >=)
10146
9597eea7fa36 inline xmin/xmax & optimize special cases
Jaroslav Hajek <highegg@gmail.com>
parents: 9827
diff changeset
377
9827
c15a5ed0da58 optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents: 9814
diff changeset
378 // Pairwise power
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
379 #define DEFMXMAPPER2X(F, FUN) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
380 template <typename R, typename X, typename Y> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
381 inline void F (size_t n, R *r, const X *x, const Y *y) throw () \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
382 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
383 for (size_t i = 0; i < n; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
384 r[i] = FUN (x[i], y[i]); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
385 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
386 template <typename R, typename X, typename Y> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
387 inline void F (size_t n, R *r, const X *x, Y y) throw () \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
388 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
389 for (size_t i = 0; i < n; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
390 r[i] = FUN (x[i], y); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
391 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
392 template <typename R, typename X, typename Y> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
393 inline void F (size_t n, R *r, X x, const Y *y) throw () \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
394 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
395 for (size_t i = 0; i < n; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
396 r[i] = FUN (x, y[i]); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
397 }
9827
c15a5ed0da58 optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents: 9814
diff changeset
398
13005
4061106b1c4b Enable automatic bsxfun for power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 13004
diff changeset
399 // Let the compiler decide which pow to use, whichever best matches the
4061106b1c4b Enable automatic bsxfun for power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 13004
diff changeset
400 // arguments provided.
4061106b1c4b Enable automatic bsxfun for power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 13004
diff changeset
401 using std::pow;
4061106b1c4b Enable automatic bsxfun for power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 13004
diff changeset
402 DEFMXMAPPER2X (mx_inline_pow, pow)
9827
c15a5ed0da58 optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents: 9814
diff changeset
403
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21690
diff changeset
404 // Arbitrary function appliers.
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21690
diff changeset
405 // The function is a template parameter to enable inlining.
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
406 template <typename R, typename X, R fun (X x)>
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
407 inline void mx_inline_map (size_t n, R *r, const X *x) throw ()
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
408 {
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
409 for (size_t i = 0; i < n; i++)
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
410 r[i] = fun (x[i]);
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
411 }
9800
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
412
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
413 template <typename R, typename X, R fun (const X& x)>
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
414 inline void mx_inline_map (size_t n, R *r, const X *x) throw ()
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
415 {
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
416 for (size_t i = 0; i < n; i++)
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
417 r[i] = fun (x[i]);
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
418 }
3
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
419
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21690
diff changeset
420 // Appliers. Since these call the operation just once, we pass it as
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
421 // a pointer, to allow the compiler reduce number of instances.
3
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
422
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
423 template <typename R, typename X>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
424 inline Array<R>
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
425 do_mx_unary_op (const Array<X>& x,
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
426 void (*op) (size_t, R *, const X *) throw ())
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
427 {
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
428 Array<R> r (x.dims ());
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
429 op (r.numel (), r.fortran_vec (), x.data ());
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
430 return r;
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
431 }
2811
1dd37f97364a [project @ 1997-03-12 23:06:13 by jwe]
jwe
parents: 2804
diff changeset
432
9800
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
433 // Shortcuts for applying mx_inline_map.
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
434
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
435 template <typename R, typename X, R fun (X)>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
436 inline Array<R>
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
437 do_mx_unary_map (const Array<X>& x)
9800
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
438 {
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
439 return do_mx_unary_op<R, X> (x, mx_inline_map<R, X, fun>);
9800
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
440 }
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
441
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
442 template <typename R, typename X, R fun (const X&)>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
443 inline Array<R>
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
444 do_mx_unary_map (const Array<X>& x)
9800
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
445 {
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
446 return do_mx_unary_op<R, X> (x, mx_inline_map<R, X, fun>);
9800
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
447 }
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
448
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
449 template <typename R>
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
450 inline Array<R>&
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
451 do_mx_inplace_op (Array<R>& r,
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
452 void (*op) (size_t, R *) throw ())
9607
1be3c73ed7b5 reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents: 9578
diff changeset
453 {
1be3c73ed7b5 reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents: 9578
diff changeset
454 op (r.numel (), r.fortran_vec ());
1be3c73ed7b5 reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents: 9578
diff changeset
455 return r;
1be3c73ed7b5 reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents: 9578
diff changeset
456 }
1be3c73ed7b5 reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents: 9578
diff changeset
457
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
458 template <typename R, typename X, typename Y>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
459 inline Array<R>
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
460 do_mm_binary_op (const Array<X>& x, const Array<Y>& y,
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
461 void (*op) (size_t, R *, const X *, const Y *) throw (),
13004
d9d65c3017c3 Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
462 void (*op1) (size_t, R *, X, const Y *) throw (),
d9d65c3017c3 Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
463 void (*op2) (size_t, R *, const X *, Y) throw (),
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
464 const char *opname)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
465 {
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17769
diff changeset
466 dim_vector dx = x.dims ();
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17769
diff changeset
467 dim_vector dy = y.dims ();
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
468 if (dx == dy)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
469 {
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
470 Array<R> r (dx);
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20218
diff changeset
471 op (r.numel (), r.fortran_vec (), x.data (), y.data ());
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
472 return r;
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
473 }
14056
c3d401562410 allow warning (or error) for automatic bsxfun
John W. Eaton <jwe@octave.org>
parents: 13756
diff changeset
474 else if (is_valid_bsxfun (opname, dx, dy))
13004
d9d65c3017c3 Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
475 {
d9d65c3017c3 Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
476 return do_bsxfun_op (x, y, op, op1, op2);
d9d65c3017c3 Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
477 }
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
478 else
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
479 octave::err_nonconformant (opname, dx, dy);
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
480 }
3
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
481
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
482 template <typename R, typename X, typename Y>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
483 inline Array<R>
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
484 do_ms_binary_op (const Array<X>& x, const Y& y,
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
485 void (*op) (size_t, R *, const X *, Y) throw ())
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
486 {
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
487 Array<R> r (x.dims ());
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20218
diff changeset
488 op (r.numel (), r.fortran_vec (), x.data (), y);
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
489 return r;
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
490 }
3
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
491
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
492 template <typename R, typename X, typename Y>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
493 inline Array<R>
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
494 do_sm_binary_op (const X& x, const Array<Y>& y,
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
495 void (*op) (size_t, R *, X, const Y *) throw ())
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
496 {
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
497 Array<R> r (y.dims ());
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20218
diff changeset
498 op (r.numel (), r.fortran_vec (), x, y.data ());
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
499 return r;
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
500 }
3
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
501
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
502 template <typename R, typename X>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
503 inline Array<R>&
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
504 do_mm_inplace_op (Array<R>& r, const Array<X>& x,
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
505 void (*op) (size_t, R *, const X *) throw (),
13139
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13005
diff changeset
506 void (*op1) (size_t, R *, X) throw (),
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
507 const char *opname)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
508 {
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17769
diff changeset
509 dim_vector dr = r.dims ();
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17769
diff changeset
510 dim_vector dx = x.dims ();
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
511 if (dr == dx)
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
512 op (r.numel (), r.fortran_vec (), x.data ());
14056
c3d401562410 allow warning (or error) for automatic bsxfun
John W. Eaton <jwe@octave.org>
parents: 13756
diff changeset
513 else if (is_valid_inplace_bsxfun (opname, dr, dx))
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
514 do_inplace_bsxfun_op (r, x, op, op1);
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
515 else
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
516 octave::err_nonconformant (opname, dr, dx);
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
517
9612
66970dd627f6 further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9607
diff changeset
518 return r;
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
519 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
520
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
521 template <typename R, typename X>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
522 inline Array<R>&
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
523 do_ms_inplace_op (Array<R>& r, const X& x,
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
524 void (*op) (size_t, R *, X) throw ())
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
525 {
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20218
diff changeset
526 op (r.numel (), r.fortran_vec (), x);
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
527 return r;
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
528 }
3
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
529
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
530 template <typename T1, typename T2>
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
531 inline bool
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
532 mx_inline_equal (size_t n, const T1 *x, const T2 *y) throw ()
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
533 {
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
534 for (size_t i = 0; i < n; i++)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
535 if (x[i] != y[i])
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
536 return false;
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
537 return true;
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
538 }
3
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
539
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
540 template <typename T>
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
541 inline bool
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
542 do_mx_check (const Array<T>& a,
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
543 bool (*op) (size_t, const T *) throw ())
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
544 {
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
545 return op (a.numel (), a.data ());
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
546 }
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
547
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
548 // NOTE: we don't use std::norm because it typically does some heavyweight
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
549 // magic to avoid underflows, which we don't need here.
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
550 template <typename T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
551 inline T cabsq (const std::complex<T>& c)
22402
4caa7b28d183 maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents: 22327
diff changeset
552 {
4caa7b28d183 maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents: 22327
diff changeset
553 return c.real () * c.real () + c.imag () * c.imag ();
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
554 }
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
555
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21690
diff changeset
556 // default. works for integers and bool.
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
557 template <typename T>
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
558 inline bool
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
559 xis_true (T x)
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
560 {
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
561 return x;
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
562 }
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
563
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
564 template <typename T>
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
565 inline bool
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
566 xis_false (T x)
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
567 {
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
568 return ! x;
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
569 }
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
570
8743
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
571 // for octave_ints
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
572 template <typename T>
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
573 inline bool
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
574 xis_true (const octave_int<T>& x)
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
575 {
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
576 return x.value ();
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
577 }
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
578
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
579 template <typename T>
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
580 inline bool
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
581 xis_false (const octave_int<T>& x)
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
582 {
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
583 return ! x.value ();
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
584 }
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
585
8743
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
586 // for reals, we want to ignore NaNs.
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
587 inline bool
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
588 xis_true (double x)
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
589 {
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
590 return ! octave::math::isnan (x) && x != 0.0;
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
591 }
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
592
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
593 inline bool
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
594 xis_false (double x)
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
595 {
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
596 return x == 0.0;
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
597 }
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
598
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
599 inline bool
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
600 xis_true (float x)
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
601 {
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
602 return ! octave::math::isnan (x) && x != 0.0f;
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
603 }
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
604
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
605 inline bool
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
606 xis_false (float x)
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
607 {
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
608 return x == 0.0f;
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
609 }
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
610
8743
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
611 // Ditto for complex.
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
612 inline bool
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
613 xis_true (const Complex& x)
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
614 {
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
615 return ! octave::math::isnan (x) && x != 0.0;
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
616 }
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
617
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
618 inline bool
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
619 xis_false (const Complex& x)
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
620 {
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
621 return x == 0.0;
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
622 }
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
623
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
624 inline bool
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
625 xis_true (const FloatComplex& x)
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
626 {
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
627 return ! octave::math::isnan (x) && x != 0.0f;
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
628 }
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
629
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
630 inline bool
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
631 xis_false (const FloatComplex& x)
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
632 {
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
633 return x == 0.0f;
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
634 }
8743
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
635
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
636 #define OP_RED_SUM(ac, el) ac += el
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
637 #define OP_RED_PROD(ac, el) ac *= el
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
638 #define OP_RED_SUMSQ(ac, el) ac += el*el
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
639 #define OP_RED_SUMSQC(ac, el) ac += cabsq (el)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
640
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
641 inline void
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
642 op_dble_prod (double& ac, float el)
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
643 {
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
644 ac *= el;
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
645 }
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
646
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
647 // FIXME: guaranteed?
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
648 inline void
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
649 op_dble_prod (Complex& ac, const FloatComplex& el)
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
650 {
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
651 ac *= el;
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
652 }
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
653
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
654 template <typename T>
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
655 inline void
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
656 op_dble_prod (double& ac, const octave_int<T>& el)
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
657 {
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
658 ac *= el.double_value ();
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
659 }
18725
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18099
diff changeset
660
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
661 inline void
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
662 op_dble_sum (double& ac, float el)
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
663 {
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
664 ac += el;
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
665 }
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
666
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
667 // FIXME: guaranteed?
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
668 inline void
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
669 op_dble_sum (Complex& ac, const FloatComplex& el)
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
670 {
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
671 ac += el;
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
672 }
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
673
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
674 template <typename T>
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
675 inline void
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
676 op_dble_sum (double& ac, const octave_int<T>& el)
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
677 {
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
678 ac += el.double_value ();
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
679 }
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
680
8743
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
681 // The following two implement a simple short-circuiting.
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
682 #define OP_RED_ANYC(ac, el) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
683 if (xis_true (el)) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
684 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
685 ac = true; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
686 break; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
687 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
688 else \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
689 continue
8743
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
690
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
691 #define OP_RED_ALLC(ac, el) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
692 if (xis_false (el)) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
693 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
694 ac = false; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
695 break; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
696 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
697 else \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
698 continue
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
699
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
700 #define OP_RED_FCN(F, TSRC, TRES, OP, ZERO) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
701 template <typename T> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
702 inline TRES \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
703 F (const TSRC* v, octave_idx_type n) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
704 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
705 TRES ac = ZERO; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
706 for (octave_idx_type i = 0; i < n; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
707 OP(ac, v[i]); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
708 return ac; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
709 }
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
710
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
711 #define PROMOTE_DOUBLE(T) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
712 typename subst_template_param<std::complex, T, double>::type
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
713
8743
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
714 OP_RED_FCN (mx_inline_sum, T, T, OP_RED_SUM, 0)
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
715 OP_RED_FCN (mx_inline_dsum, T, PROMOTE_DOUBLE(T), op_dble_sum, 0.0)
8756
d0755c9db5ed implement fast logical sum (counting)
Jaroslav Hajek <highegg@gmail.com>
parents: 8751
diff changeset
716 OP_RED_FCN (mx_inline_count, bool, T, OP_RED_SUM, 0)
8743
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
717 OP_RED_FCN (mx_inline_prod, T, T, OP_RED_PROD, 1)
18725
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18099
diff changeset
718 OP_RED_FCN (mx_inline_dprod, T, PROMOTE_DOUBLE(T), op_dble_prod, 1)
8743
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
719 OP_RED_FCN (mx_inline_sumsq, T, T, OP_RED_SUMSQ, 0)
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
720 OP_RED_FCN (mx_inline_sumsq, std::complex<T>, T, OP_RED_SUMSQC, 0)
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
721 OP_RED_FCN (mx_inline_any, T, bool, OP_RED_ANYC, false)
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
722 OP_RED_FCN (mx_inline_all, T, bool, OP_RED_ALLC, true)
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
723
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
724 #define OP_RED_FCN2(F, TSRC, TRES, OP, ZERO) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
725 template <typename T> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
726 inline void \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
727 F (const TSRC* v, TRES *r, octave_idx_type m, octave_idx_type n) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
728 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
729 for (octave_idx_type i = 0; i < m; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
730 r[i] = ZERO; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
731 for (octave_idx_type j = 0; j < n; j++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
732 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
733 for (octave_idx_type i = 0; i < m; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
734 OP(r[i], v[i]); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
735 v += m; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
736 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
737 }
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
738
8743
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
739 OP_RED_FCN2 (mx_inline_sum, T, T, OP_RED_SUM, 0)
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
740 OP_RED_FCN2 (mx_inline_dsum, T, PROMOTE_DOUBLE(T), op_dble_sum, 0.0)
8756
d0755c9db5ed implement fast logical sum (counting)
Jaroslav Hajek <highegg@gmail.com>
parents: 8751
diff changeset
741 OP_RED_FCN2 (mx_inline_count, bool, T, OP_RED_SUM, 0)
8743
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
742 OP_RED_FCN2 (mx_inline_prod, T, T, OP_RED_PROD, 1)
18725
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18099
diff changeset
743 OP_RED_FCN2 (mx_inline_dprod, T, PROMOTE_DOUBLE(T), op_dble_prod, 0.0)
8743
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
744 OP_RED_FCN2 (mx_inline_sumsq, T, T, OP_RED_SUMSQ, 0)
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
745 OP_RED_FCN2 (mx_inline_sumsq, std::complex<T>, T, OP_RED_SUMSQC, 0)
8758
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
746
10147
adc0143e9419 optimize any/all (x, 2) with small number of rows
Jaroslav Hajek <highegg@gmail.com>
parents: 10146
diff changeset
747 #define OP_RED_ANYR(ac, el) ac |= xis_true (el)
adc0143e9419 optimize any/all (x, 2) with small number of rows
Jaroslav Hajek <highegg@gmail.com>
parents: 10146
diff changeset
748 #define OP_RED_ALLR(ac, el) ac &= xis_true (el)
adc0143e9419 optimize any/all (x, 2) with small number of rows
Jaroslav Hajek <highegg@gmail.com>
parents: 10146
diff changeset
749
adc0143e9419 optimize any/all (x, 2) with small number of rows
Jaroslav Hajek <highegg@gmail.com>
parents: 10146
diff changeset
750 OP_RED_FCN2 (mx_inline_any_r, T, bool, OP_RED_ANYR, false)
adc0143e9419 optimize any/all (x, 2) with small number of rows
Jaroslav Hajek <highegg@gmail.com>
parents: 10146
diff changeset
751 OP_RED_FCN2 (mx_inline_all_r, T, bool, OP_RED_ALLR, true)
adc0143e9419 optimize any/all (x, 2) with small number of rows
Jaroslav Hajek <highegg@gmail.com>
parents: 10146
diff changeset
752
8758
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
753 // Using the general code for any/all would sacrifice short-circuiting.
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21690
diff changeset
754 // OTOH, going by rows would sacrifice cache-coherence. The following
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21690
diff changeset
755 // algorithm will achieve both, at the cost of a temporary octave_idx_type
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21690
diff changeset
756 // array.
8758
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
757
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
758 #define OP_ROW_SHORT_CIRCUIT(F, PRED, ZERO) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
759 template <typename T> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
760 inline void \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
761 F (const T* v, bool *r, octave_idx_type m, octave_idx_type n) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
762 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
763 if (n <= 8) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
764 return F ## _r (v, r, m, n); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
765 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
766 /* FIXME: it may be sub-optimal to allocate the buffer here. */ \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
767 OCTAVE_LOCAL_BUFFER (octave_idx_type, iact, m); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
768 for (octave_idx_type i = 0; i < m; i++) iact[i] = i; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
769 octave_idx_type nact = m; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
770 for (octave_idx_type j = 0; j < n; j++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
771 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
772 octave_idx_type k = 0; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
773 for (octave_idx_type i = 0; i < nact; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
774 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
775 octave_idx_type ia = iact[i]; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
776 if (! PRED (v[ia])) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
777 iact[k++] = ia; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
778 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
779 nact = k; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
780 v += m; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
781 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
782 for (octave_idx_type i = 0; i < m; i++) r[i] = ! ZERO; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
783 for (octave_idx_type i = 0; i < nact; i++) r[iact[i]] = ZERO; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
784 }
8758
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
785
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
786 OP_ROW_SHORT_CIRCUIT (mx_inline_any, xis_true, false)
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
787 OP_ROW_SHORT_CIRCUIT (mx_inline_all, xis_false, true)
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
788
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
789 #define OP_RED_FCNN(F, TSRC, TRES) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
790 template <typename T> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
791 inline void \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
792 F (const TSRC *v, TRES *r, octave_idx_type l, \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
793 octave_idx_type n, octave_idx_type u) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
794 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
795 if (l == 1) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
796 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
797 for (octave_idx_type i = 0; i < u; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
798 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
799 r[i] = F<T> (v, n); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
800 v += n; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
801 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
802 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
803 else \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
804 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
805 for (octave_idx_type i = 0; i < u; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
806 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
807 F (v, r, l, n); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
808 v += l*n; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
809 r += l; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
810 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
811 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
812 }
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
813
8743
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
814 OP_RED_FCNN (mx_inline_sum, T, T)
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
815 OP_RED_FCNN (mx_inline_dsum, T, PROMOTE_DOUBLE(T))
8756
d0755c9db5ed implement fast logical sum (counting)
Jaroslav Hajek <highegg@gmail.com>
parents: 8751
diff changeset
816 OP_RED_FCNN (mx_inline_count, bool, T)
8743
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
817 OP_RED_FCNN (mx_inline_prod, T, T)
18725
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18099
diff changeset
818 OP_RED_FCNN (mx_inline_dprod, T, PROMOTE_DOUBLE(T))
8743
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
819 OP_RED_FCNN (mx_inline_sumsq, T, T)
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
820 OP_RED_FCNN (mx_inline_sumsq, std::complex<T>, T)
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
821 OP_RED_FCNN (mx_inline_any, T, bool)
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
822 OP_RED_FCNN (mx_inline_all, T, bool)
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
823
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
824 #define OP_CUM_FCN(F, TSRC, TRES, OP) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
825 template <typename T> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
826 inline void \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
827 F (const TSRC *v, TRES *r, octave_idx_type n) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
828 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
829 if (n) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
830 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
831 TRES t = r[0] = v[0]; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
832 for (octave_idx_type i = 1; i < n; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
833 r[i] = t = t OP v[i]; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
834 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
835 }
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
836
8780
ea76466605ba support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents: 8777
diff changeset
837 OP_CUM_FCN (mx_inline_cumsum, T, T, +)
ea76466605ba support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents: 8777
diff changeset
838 OP_CUM_FCN (mx_inline_cumprod, T, T, *)
ea76466605ba support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents: 8777
diff changeset
839 OP_CUM_FCN (mx_inline_cumcount, bool, T, +)
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
840
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
841 #define OP_CUM_FCN2(F, TSRC, TRES, OP) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
842 template <typename T> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
843 inline void \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
844 F (const TSRC *v, TRES *r, octave_idx_type m, octave_idx_type n) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
845 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
846 if (n) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
847 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
848 for (octave_idx_type i = 0; i < m; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
849 r[i] = v[i]; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
850 const T *r0 = r; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
851 for (octave_idx_type j = 1; j < n; j++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
852 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
853 r += m; v += m; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
854 for (octave_idx_type i = 0; i < m; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
855 r[i] = r0[i] OP v[i]; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
856 r0 += m; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
857 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
858 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
859 }
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
860
8780
ea76466605ba support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents: 8777
diff changeset
861 OP_CUM_FCN2 (mx_inline_cumsum, T, T, +)
ea76466605ba support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents: 8777
diff changeset
862 OP_CUM_FCN2 (mx_inline_cumprod, T, T, *)
10643
9852264314d1 fix cumulative logical sum
Jaroslav Hajek <highegg@gmail.com>
parents: 10482
diff changeset
863 OP_CUM_FCN2 (mx_inline_cumcount, bool, T, +)
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
864
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
865 #define OP_CUM_FCNN(F, TSRC, TRES) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
866 template <typename T> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
867 inline void \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
868 F (const TSRC *v, TRES *r, octave_idx_type l, \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
869 octave_idx_type n, octave_idx_type u) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
870 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
871 if (l == 1) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
872 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
873 for (octave_idx_type i = 0; i < u; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
874 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
875 F (v, r, n); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
876 v += n; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
877 r += n; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
878 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
879 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
880 else \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
881 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
882 for (octave_idx_type i = 0; i < u; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
883 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
884 F (v, r, l, n); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
885 v += l*n; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
886 r += l*n; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
887 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
888 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
889 }
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
890
8780
ea76466605ba support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents: 8777
diff changeset
891 OP_CUM_FCNN (mx_inline_cumsum, T, T)
ea76466605ba support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents: 8777
diff changeset
892 OP_CUM_FCNN (mx_inline_cumprod, T, T)
ea76466605ba support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents: 8777
diff changeset
893 OP_CUM_FCNN (mx_inline_cumcount, bool, T)
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
894
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
895 #define OP_MINMAX_FCN(F, OP) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
896 template <typename T> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
897 void F (const T *v, T *r, octave_idx_type n) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
898 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
899 if (! n) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
900 return; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
901 T tmp = v[0]; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
902 octave_idx_type i = 1; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
903 if (octave::math::isnan (tmp)) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
904 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
905 for (; i < n && octave::math::isnan (v[i]); i++) ; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
906 if (i < n) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
907 tmp = v[i]; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
908 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
909 for (; i < n; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
910 if (v[i] OP tmp) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
911 tmp = v[i]; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
912 *r = tmp; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
913 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
914 template <typename T> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
915 void F (const T *v, T *r, octave_idx_type *ri, octave_idx_type n) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
916 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
917 if (! n) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
918 return; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
919 T tmp = v[0]; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
920 octave_idx_type tmpi = 0; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
921 octave_idx_type i = 1; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
922 if (octave::math::isnan (tmp)) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
923 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
924 for (; i < n && octave::math::isnan (v[i]); i++) ; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
925 if (i < n) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
926 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
927 tmp = v[i]; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
928 tmpi = i; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
929 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
930 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
931 for (; i < n; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
932 if (v[i] OP tmp) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
933 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
934 tmp = v[i]; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
935 tmpi = i; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
936 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
937 *r = tmp; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
938 *ri = tmpi; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
939 }
8751
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
940
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
941 OP_MINMAX_FCN (mx_inline_min, <)
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
942 OP_MINMAX_FCN (mx_inline_max, >)
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
943
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
944 // Row reductions will be slightly complicated. We will proceed with checks
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
945 // for NaNs until we detect that no row will yield a NaN, in which case we
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
946 // proceed to a faster code.
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
947
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
948 #define OP_MINMAX_FCN2(F, OP) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
949 template <typename T> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
950 inline void \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
951 F (const T *v, T *r, octave_idx_type m, octave_idx_type n) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
952 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
953 if (! n) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
954 return; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
955 bool nan = false; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
956 octave_idx_type j = 0; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
957 for (octave_idx_type i = 0; i < m; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
958 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
959 r[i] = v[i]; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
960 if (octave::math::isnan (v[i])) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
961 nan = true; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
962 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
963 j++; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
964 v += m; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
965 while (nan && j < n) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
966 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
967 nan = false; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
968 for (octave_idx_type i = 0; i < m; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
969 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
970 if (octave::math::isnan (v[i])) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
971 nan = true; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
972 else if (octave::math::isnan (r[i]) || v[i] OP r[i]) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
973 r[i] = v[i]; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
974 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
975 j++; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
976 v += m; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
977 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
978 while (j < n) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
979 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
980 for (octave_idx_type i = 0; i < m; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
981 if (v[i] OP r[i]) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
982 r[i] = v[i]; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
983 j++; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
984 v += m; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
985 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
986 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
987 template <typename T> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
988 inline void \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
989 F (const T *v, T *r, octave_idx_type *ri, \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
990 octave_idx_type m, octave_idx_type n) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
991 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
992 if (! n) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
993 return; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
994 bool nan = false; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
995 octave_idx_type j = 0; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
996 for (octave_idx_type i = 0; i < m; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
997 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
998 r[i] = v[i]; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
999 ri[i] = j; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1000 if (octave::math::isnan (v[i])) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1001 nan = true; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1002 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1003 j++; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1004 v += m; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1005 while (nan && j < n) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1006 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1007 nan = false; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1008 for (octave_idx_type i = 0; i < m; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1009 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1010 if (octave::math::isnan (v[i])) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1011 nan = true; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1012 else if (octave::math::isnan (r[i]) || v[i] OP r[i]) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1013 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1014 r[i] = v[i]; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1015 ri[i] = j; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1016 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1017 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1018 j++; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1019 v += m; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1020 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1021 while (j < n) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1022 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1023 for (octave_idx_type i = 0; i < m; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1024 if (v[i] OP r[i]) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1025 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1026 r[i] = v[i]; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1027 ri[i] = j; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1028 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1029 j++; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1030 v += m; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1031 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1032 }
8751
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1033
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1034 OP_MINMAX_FCN2 (mx_inline_min, <)
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1035 OP_MINMAX_FCN2 (mx_inline_max, >)
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1036
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1037 #define OP_MINMAX_FCNN(F) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1038 template <typename T> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1039 inline void \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1040 F (const T *v, T *r, octave_idx_type l, \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1041 octave_idx_type n, octave_idx_type u) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1042 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1043 if (! n) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1044 return; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1045 if (l == 1) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1046 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1047 for (octave_idx_type i = 0; i < u; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1048 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1049 F (v, r, n); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1050 v += n; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1051 r++; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1052 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1053 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1054 else \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1055 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1056 for (octave_idx_type i = 0; i < u; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1057 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1058 F (v, r, l, n); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1059 v += l*n; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1060 r += l; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1061 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1062 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1063 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1064 template <typename T> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1065 inline void \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1066 F (const T *v, T *r, octave_idx_type *ri, \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1067 octave_idx_type l, octave_idx_type n, octave_idx_type u) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1068 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1069 if (! n) return; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1070 if (l == 1) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1071 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1072 for (octave_idx_type i = 0; i < u; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1073 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1074 F (v, r, ri, n); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1075 v += n; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1076 r++; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1077 ri++; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1078 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1079 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1080 else \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1081 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1082 for (octave_idx_type i = 0; i < u; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1083 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1084 F (v, r, ri, l, n); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1085 v += l*n; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1086 r += l; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1087 ri += l; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1088 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1089 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1090 }
8751
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1091
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1092 OP_MINMAX_FCNN (mx_inline_min)
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1093 OP_MINMAX_FCNN (mx_inline_max)
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1094
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1095 #define OP_CUMMINMAX_FCN(F, OP) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1096 template <typename T> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1097 void F (const T *v, T *r, octave_idx_type n) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1098 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1099 if (! n) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1100 return; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1101 T tmp = v[0]; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1102 octave_idx_type i = 1; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1103 octave_idx_type j = 0; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1104 if (octave::math::isnan (tmp)) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1105 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1106 for (; i < n && octave::math::isnan (v[i]); i++) ; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1107 for (; j < i; j++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1108 r[j] = tmp; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1109 if (i < n) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1110 tmp = v[i]; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1111 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1112 for (; i < n; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1113 if (v[i] OP tmp) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1114 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1115 for (; j < i; j++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1116 r[j] = tmp; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1117 tmp = v[i]; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1118 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1119 for (; j < i; j++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1120 r[j] = tmp; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1121 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1122 template <typename T> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1123 void F (const T *v, T *r, octave_idx_type *ri, octave_idx_type n) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1124 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1125 if (! n) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1126 return; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1127 T tmp = v[0]; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1128 octave_idx_type tmpi = 0; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1129 octave_idx_type i = 1; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1130 octave_idx_type j = 0; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1131 if (octave::math::isnan (tmp)) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1132 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1133 for (; i < n && octave::math::isnan (v[i]); i++) ; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1134 for (; j < i; j++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1135 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1136 r[j] = tmp; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1137 ri[j] = tmpi; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1138 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1139 if (i < n) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1140 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1141 tmp = v[i]; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1142 tmpi = i; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1143 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1144 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1145 for (; i < n; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1146 if (v[i] OP tmp) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1147 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1148 for (; j < i; j++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1149 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1150 r[j] = tmp; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1151 ri[j] = tmpi; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1152 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1153 tmp = v[i]; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1154 tmpi = i; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1155 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1156 for (; j < i; j++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1157 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1158 r[j] = tmp; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1159 ri[j] = tmpi; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1160 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1161 }
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1162
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1163 OP_CUMMINMAX_FCN (mx_inline_cummin, <)
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1164 OP_CUMMINMAX_FCN (mx_inline_cummax, >)
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1165
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1166 // Row reductions will be slightly complicated. We will proceed with checks
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1167 // for NaNs until we detect that no row will yield a NaN, in which case we
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1168 // proceed to a faster code.
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1169
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1170 #define OP_CUMMINMAX_FCN2(F, OP) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1171 template <typename T> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1172 inline void \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1173 F (const T *v, T *r, octave_idx_type m, octave_idx_type n) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1174 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1175 if (! n) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1176 return; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1177 bool nan = false; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1178 const T *r0; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1179 octave_idx_type j = 0; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1180 for (octave_idx_type i = 0; i < m; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1181 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1182 r[i] = v[i]; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1183 if (octave::math::isnan (v[i])) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1184 nan = true; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1185 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1186 j++; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1187 v += m; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1188 r0 = r; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1189 r += m; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1190 while (nan && j < n) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1191 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1192 nan = false; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1193 for (octave_idx_type i = 0; i < m; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1194 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1195 if (octave::math::isnan (v[i])) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1196 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1197 r[i] = r0[i]; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1198 nan = true; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1199 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1200 else if (octave::math::isnan (r0[i]) || v[i] OP r0[i]) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1201 r[i] = v[i]; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1202 else \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1203 r[i] = r0[i]; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1204 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1205 j++; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1206 v += m; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1207 r0 = r; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1208 r += m; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1209 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1210 while (j < n) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1211 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1212 for (octave_idx_type i = 0; i < m; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1213 if (v[i] OP r0[i]) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1214 r[i] = v[i]; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1215 else \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1216 r[i] = r0[i]; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1217 j++; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1218 v += m; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1219 r0 = r; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1220 r += m; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1221 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1222 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1223 template <typename T> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1224 inline void \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1225 F (const T *v, T *r, octave_idx_type *ri, \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1226 octave_idx_type m, octave_idx_type n) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1227 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1228 if (! n) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1229 return; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1230 bool nan = false; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1231 const T *r0; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1232 const octave_idx_type *r0i; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1233 octave_idx_type j = 0; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1234 for (octave_idx_type i = 0; i < m; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1235 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1236 r[i] = v[i]; ri[i] = 0; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1237 if (octave::math::isnan (v[i])) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1238 nan = true; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1239 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1240 j++; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1241 v += m; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1242 r0 = r; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1243 r += m; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1244 r0i = ri; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1245 ri += m; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1246 while (nan && j < n) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1247 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1248 nan = false; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1249 for (octave_idx_type i = 0; i < m; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1250 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1251 if (octave::math::isnan (v[i])) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1252 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1253 r[i] = r0[i]; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1254 ri[i] = r0i[i]; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1255 nan = true; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1256 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1257 else if (octave::math::isnan (r0[i]) || v[i] OP r0[i]) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1258 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1259 r[i] = v[i]; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1260 ri[i] = j; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1261 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1262 else \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1263 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1264 r[i] = r0[i]; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1265 ri[i] = r0i[i]; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1266 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1267 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1268 j++; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1269 v += m; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1270 r0 = r; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1271 r += m; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1272 r0i = ri; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1273 ri += m; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1274 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1275 while (j < n) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1276 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1277 for (octave_idx_type i = 0; i < m; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1278 if (v[i] OP r0[i]) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1279 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1280 r[i] = v[i]; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1281 ri[i] = j; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1282 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1283 else \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1284 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1285 r[i] = r0[i]; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1286 ri[i] = r0i[i]; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1287 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1288 j++; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1289 v += m; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1290 r0 = r; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1291 r += m; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1292 r0i = ri; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1293 ri += m; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1294 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1295 }
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1296
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1297 OP_CUMMINMAX_FCN2 (mx_inline_cummin, <)
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1298 OP_CUMMINMAX_FCN2 (mx_inline_cummax, >)
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1299
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1300 #define OP_CUMMINMAX_FCNN(F) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1301 template <typename T> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1302 inline void \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1303 F (const T *v, T *r, octave_idx_type l, \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1304 octave_idx_type n, octave_idx_type u) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1305 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1306 if (! n) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1307 return; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1308 if (l == 1) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1309 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1310 for (octave_idx_type i = 0; i < u; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1311 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1312 F (v, r, n); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1313 v += n; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1314 r += n; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1315 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1316 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1317 else \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1318 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1319 for (octave_idx_type i = 0; i < u; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1320 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1321 F (v, r, l, n); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1322 v += l*n; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1323 r += l*n; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1324 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1325 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1326 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1327 template <typename T> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1328 inline void \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1329 F (const T *v, T *r, octave_idx_type *ri, \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1330 octave_idx_type l, octave_idx_type n, octave_idx_type u) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1331 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1332 if (! n) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1333 return; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1334 if (l == 1) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1335 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1336 for (octave_idx_type i = 0; i < u; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1337 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1338 F (v, r, ri, n); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1339 v += n; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1340 r += n; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1341 ri += n; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1342 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1343 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1344 else \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1345 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1346 for (octave_idx_type i = 0; i < u; i++) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1347 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1348 F (v, r, ri, l, n); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1349 v += l*n; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1350 r += l*n; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1351 ri += l*n; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1352 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1353 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1354 }
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1355
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1356 OP_CUMMINMAX_FCNN (mx_inline_cummin)
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1357 OP_CUMMINMAX_FCNN (mx_inline_cummax)
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1358
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
1359 template <typename T>
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1360 void mx_inline_diff (const T *v, T *r, octave_idx_type n,
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1361 octave_idx_type order)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1362 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1363 switch (order)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1364 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1365 case 1:
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1366 for (octave_idx_type i = 0; i < n-1; i++)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1367 r[i] = v[i+1] - v[i];
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1368 break;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1369 case 2:
9702
9ecd35a606e3 avoid some warnings from g++
John W. Eaton <jwe@octave.org>
parents: 9612
diff changeset
1370 if (n > 1)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1371 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1372 T lst = v[1] - v[0];
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1373 for (octave_idx_type i = 0; i < n-2; i++)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1374 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1375 T dif = v[i+2] - v[i+1];
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1376 r[i] = dif - lst;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1377 lst = dif;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1378 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1379 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1380 break;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1381 default:
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1382 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1383 OCTAVE_LOCAL_BUFFER (T, buf, n-1);
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1384
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1385 for (octave_idx_type i = 0; i < n-1; i++)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1386 buf[i] = v[i+1] - v[i];
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1387
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1388 for (octave_idx_type o = 2; o <= order; o++)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1389 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1390 for (octave_idx_type i = 0; i < n-o; i++)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1391 buf[i] = buf[i+1] - buf[i];
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1392 }
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1393
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1394 for (octave_idx_type i = 0; i < n-order; i++)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1395 r[i] = buf[i];
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1396 }
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1397 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1398 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1399
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
1400 template <typename T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1401 void mx_inline_diff (const T *v, T *r,
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1402 octave_idx_type m, octave_idx_type n,
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1403 octave_idx_type order)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1404 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1405 switch (order)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1406 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1407 case 1:
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1408 for (octave_idx_type i = 0; i < m*(n-1); i++)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1409 r[i] = v[i+m] - v[i];
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1410 break;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1411 case 2:
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1412 for (octave_idx_type i = 0; i < n-2; i++)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1413 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1414 for (octave_idx_type j = i*m; j < i*m+m; j++)
15118
a4e94933fed3 Fix bug #37033 in diff ()
Carlo de Falco <cdf@users.sourceforge.net>
parents: 14138
diff changeset
1415 r[j] = (v[j+m+m] - v[j+m]) - (v[j+m] - v[j]);
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1416 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1417 break;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1418 default:
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1419 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1420 OCTAVE_LOCAL_BUFFER (T, buf, n-1);
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1421
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1422 for (octave_idx_type j = 0; j < m; j++)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1423 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1424 for (octave_idx_type i = 0; i < n-1; i++)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1425 buf[i] = v[i*m+j+m] - v[i*m+j];
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1426
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1427 for (octave_idx_type o = 2; o <= order; o++)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1428 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1429 for (octave_idx_type i = 0; i < n-o; i++)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1430 buf[i] = buf[i+1] - buf[i];
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1431 }
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1432
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1433 for (octave_idx_type i = 0; i < n-order; i++)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1434 r[i*m+j] = buf[i];
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1435 }
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1436 }
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1437 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1438 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1439
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
1440 template <typename T>
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1441 inline void
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1442 mx_inline_diff (const T *v, T *r,
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1443 octave_idx_type l, octave_idx_type n, octave_idx_type u,
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1444 octave_idx_type order)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1445 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1446 if (! n) return;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1447 if (l == 1)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1448 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1449 for (octave_idx_type i = 0; i < u; i++)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1450 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1451 mx_inline_diff (v, r, n, order);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1452 v += n; r += n-order;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1453 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1454 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1455 else
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1456 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1457 for (octave_idx_type i = 0; i < u; i++)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1458 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1459 mx_inline_diff (v, r, l, n, order);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1460 v += l*n;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1461 r += l*(n-order);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1462 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1463 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1464 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1465
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1466 // Assistant function
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1467
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1468 inline void
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1469 get_extent_triplet (const dim_vector& dims, int& dim,
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1470 octave_idx_type& l, octave_idx_type& n,
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1471 octave_idx_type& u)
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1472 {
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21139
diff changeset
1473 octave_idx_type ndims = dims.ndims ();
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1474 if (dim >= ndims)
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1475 {
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1476 l = dims.numel ();
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1477 n = 1;
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1478 u = 1;
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1479 }
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1480 else
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1481 {
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1482 if (dim < 0)
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1483 dim = dims.first_non_singleton ();
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1484
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1485 // calculate extent triplet.
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1486 l = 1, n = dims(dim), u = 1;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1487 for (octave_idx_type i = 0; i < dim; i++)
20218
b2100e1659ac maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents: 19697
diff changeset
1488 l *= dims(i);
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1489 for (octave_idx_type i = dim + 1; i < ndims; i++)
20218
b2100e1659ac maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents: 19697
diff changeset
1490 u *= dims(i);
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1491 }
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1492 }
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1493
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1494 // Appliers.
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1495 // FIXME: is this the best design? C++ gives a lot of options here...
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1496 // maybe it can be done without an explicit parameter?
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1497
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
1498 template <typename R, typename T>
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1499 inline Array<R>
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1500 do_mx_red_op (const Array<T>& src, int dim,
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1501 void (*mx_red_op) (const T *, R *, octave_idx_type,
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1502 octave_idx_type, octave_idx_type))
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1503 {
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1504 octave_idx_type l, n, u;
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1505 dim_vector dims = src.dims ();
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
1506 // M*b inconsistency: sum ([]) = 0 etc.
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21139
diff changeset
1507 if (dims.ndims () == 2 && dims(0) == 0 && dims(1) == 0)
20218
b2100e1659ac maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents: 19697
diff changeset
1508 dims(1) = 1;
8743
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
1509
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1510 get_extent_triplet (dims, dim, l, n, u);
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1511
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1512 // Reduction operation reduces the array size.
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21139
diff changeset
1513 if (dim < dims.ndims ()) dims(dim) = 1;
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1514 dims.chop_trailing_singletons ();
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1515
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1516 Array<R> ret (dims);
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1517 mx_red_op (src.data (), ret.fortran_vec (), l, n, u);
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1518
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1519 return ret;
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1520 }
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1521
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
1522 template <typename R, typename T>
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1523 inline Array<R>
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1524 do_mx_cum_op (const Array<T>& src, int dim,
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1525 void (*mx_cum_op) (const T *, R *, octave_idx_type,
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1526 octave_idx_type, octave_idx_type))
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1527 {
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1528 octave_idx_type l, n, u;
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1529 dim_vector dims = src.dims ();
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1530 get_extent_triplet (dims, dim, l, n, u);
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1531
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1532 // Cumulative operation doesn't reduce the array size.
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1533 Array<R> ret (dims);
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1534 mx_cum_op (src.data (), ret.fortran_vec (), l, n, u);
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1535
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1536 return ret;
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1537 }
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1538
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
1539 template <typename R>
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1540 inline Array<R>
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1541 do_mx_minmax_op (const Array<R>& src, int dim,
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1542 void (*mx_minmax_op) (const R *, R *, octave_idx_type,
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1543 octave_idx_type, octave_idx_type))
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1544 {
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1545 octave_idx_type l, n, u;
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1546 dim_vector dims = src.dims ();
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1547 get_extent_triplet (dims, dim, l, n, u);
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1548
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1549 // If the dimension is zero, we don't do anything.
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21139
diff changeset
1550 if (dim < dims.ndims () && dims(dim) != 0) dims(dim) = 1;
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1551 dims.chop_trailing_singletons ();
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1552
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1553 Array<R> ret (dims);
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1554 mx_minmax_op (src.data (), ret.fortran_vec (), l, n, u);
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1555
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1556 return ret;
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1557 }
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1558
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
1559 template <typename R>
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1560 inline Array<R>
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1561 do_mx_minmax_op (const Array<R>& src, Array<octave_idx_type>& idx, int dim,
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1562 void (*mx_minmax_op) (const R *, R *, octave_idx_type *,
8751
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1563 octave_idx_type, octave_idx_type, octave_idx_type))
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1564 {
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1565 octave_idx_type l, n, u;
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1566 dim_vector dims = src.dims ();
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1567 get_extent_triplet (dims, dim, l, n, u);
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1568
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1569 // If the dimension is zero, we don't do anything.
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21139
diff changeset
1570 if (dim < dims.ndims () && dims(dim) != 0) dims(dim) = 1;
8751
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1571 dims.chop_trailing_singletons ();
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1572
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1573 Array<R> ret (dims);
8751
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1574 if (idx.dims () != dims) idx = Array<octave_idx_type> (dims);
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1575
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1576 mx_minmax_op (src.data (), ret.fortran_vec (), idx.fortran_vec (),
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1577 l, n, u);
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1578
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1579 return ret;
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1580 }
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1581
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
1582 template <typename R>
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1583 inline Array<R>
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1584 do_mx_cumminmax_op (const Array<R>& src, int dim,
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1585 void (*mx_cumminmax_op) (const R *, R *, octave_idx_type,
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1586 octave_idx_type, octave_idx_type))
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1587 {
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1588 octave_idx_type l, n, u;
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1589 dim_vector dims = src.dims ();
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1590 get_extent_triplet (dims, dim, l, n, u);
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1591
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1592 Array<R> ret (dims);
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1593 mx_cumminmax_op (src.data (), ret.fortran_vec (), l, n, u);
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1594
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1595 return ret;
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1596 }
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1597
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
1598 template <typename R>
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1599 inline Array<R>
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1600 do_mx_cumminmax_op (const Array<R>& src, Array<octave_idx_type>& idx, int dim,
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1601 void (*mx_cumminmax_op) (const R *, R *, octave_idx_type *,
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1602 octave_idx_type, octave_idx_type, octave_idx_type))
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1603 {
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1604 octave_idx_type l, n, u;
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1605 dim_vector dims = src.dims ();
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1606 get_extent_triplet (dims, dim, l, n, u);
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1607
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1608 Array<R> ret (dims);
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1609 if (idx.dims () != dims) idx = Array<octave_idx_type> (dims);
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1610
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1611 mx_cumminmax_op (src.data (), ret.fortran_vec (), idx.fortran_vec (),
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1612 l, n, u);
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1613
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1614 return ret;
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1615 }
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1616
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
1617 template <typename R>
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1618 inline Array<R>
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1619 do_mx_diff_op (const Array<R>& src, int dim, octave_idx_type order,
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1620 void (*mx_diff_op) (const R *, R *,
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1621 octave_idx_type, octave_idx_type,
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1622 octave_idx_type, octave_idx_type))
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1623 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1624 octave_idx_type l, n, u;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1625 if (order <= 0)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1626 return src;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1627
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1628 dim_vector dims = src.dims ();
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1629
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1630 get_extent_triplet (dims, dim, l, n, u);
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21139
diff changeset
1631 if (dim >= dims.ndims ())
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1632 dims.resize (dim+1, 1);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1633
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1634 if (dims(dim) <= order)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1635 {
20218
b2100e1659ac maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents: 19697
diff changeset
1636 dims(dim) = 0;
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1637 return Array<R> (dims);
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1638 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1639 else
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1640 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1641 dims(dim) -= order;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1642 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1643
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1644 Array<R> ret (dims);
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1645 mx_diff_op (src.data (), ret.fortran_vec (), l, n, u, order);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1646
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1647 return ret;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1648 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1649
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21690
diff changeset
1650 // Fast extra-precise summation. According to
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1651 // T. Ogita, S. M. Rump, S. Oishi:
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1652 // Accurate Sum And Dot Product,
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1653 // SIAM J. Sci. Computing, Vol. 26, 2005
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1654
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
1655 template <typename T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1656 inline void twosum_accum (T& s, T& e,
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1657 const T& x)
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1658 {
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17769
diff changeset
1659 T s1 = s + x;
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17769
diff changeset
1660 T t = s1 - s;
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17769
diff changeset
1661 T e1 = (s - (s1 - t)) + (x - t);
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1662 s = s1;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1663 e += e1;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1664 }
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1665
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
1666 template <typename T>
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1667 inline T
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1668 mx_inline_xsum (const T *v, octave_idx_type n)
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1669 {
18099
6c706a83070f Tweak cset 8e056300994b defining 1 var per line in liboctave.
Rik <rik@octave.org>
parents: 18084
diff changeset
1670 T s, e;
6c706a83070f Tweak cset 8e056300994b defining 1 var per line in liboctave.
Rik <rik@octave.org>
parents: 18084
diff changeset
1671 s = e = 0;
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1672 for (octave_idx_type i = 0; i < n; i++)
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1673 twosum_accum (s, e, v[i]);
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1674
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1675 return s + e;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1676 }
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1677
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
1678 template <typename T>
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1679 inline void
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1680 mx_inline_xsum (const T *v, T *r,
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1681 octave_idx_type m, octave_idx_type n)
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1682 {
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1683 OCTAVE_LOCAL_BUFFER (T, e, m);
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1684 for (octave_idx_type i = 0; i < m; i++)
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1685 e[i] = r[i] = T ();
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1686
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1687 for (octave_idx_type j = 0; j < n; j++)
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1688 {
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1689 for (octave_idx_type i = 0; i < m; i++)
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1690 twosum_accum (r[i], e[i], v[i]);
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1691
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1692 v += m;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1693 }
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1694
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1695 for (octave_idx_type i = 0; i < m; i++)
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1696 r[i] += e[i];
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1697 }
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1698
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1699 OP_RED_FCNN (mx_inline_xsum, T, T)
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1700
2804
eedc2f3f61f7 [project @ 1997-03-11 04:34:50 by jwe]
jwe
parents: 2386
diff changeset
1701 #endif