annotate liboctave/mx-inlines.cc @ 9814:2b29f3472e20

add a couple of useful loops
author Jaroslav Hajek <highegg@gmail.com>
date Fri, 13 Nov 2009 12:00:53 +0100
parents ef4c4186cb47
children c15a5ed0da58
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
7017
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
3 Copyright (C) 1993, 1994, 1995, 1996, 1997, 1999, 2000, 2001, 2002,
8920
eb63fbe60fab update copyright notices
John W. Eaton <jwe@octave.org>
parents: 8899
diff changeset
4 2003, 2004, 2005, 2006, 2007, 2008 John W. Eaton
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
5 Copyright (C) 2009 Jaroslav Hajek
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
6 Copyright (C) 2009 VZLU Prague
3
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
7
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
8 This file is part of Octave.
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
9
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
10 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
11 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
12 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
13 option) any later version.
3
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
14
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
15 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
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
17 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
18 for more details.
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
19
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
20 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
21 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
22 <http://www.gnu.org/licenses/>.
3
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 */
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
25
2828
92826d6e8bd9 [project @ 1997-03-25 23:41:41 by jwe]
jwe
parents: 2811
diff changeset
26 #if !defined (octave_mx_inlines_h)
92826d6e8bd9 [project @ 1997-03-25 23:41:41 by jwe]
jwe
parents: 2811
diff changeset
27 #define octave_mx_inlines_h 1
2804
eedc2f3f61f7 [project @ 1997-03-11 04:34:50 by jwe]
jwe
parents: 2386
diff changeset
28
eedc2f3f61f7 [project @ 1997-03-11 04:34:50 by jwe]
jwe
parents: 2386
diff changeset
29 #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
30 #include <cmath>
2804
eedc2f3f61f7 [project @ 1997-03-11 04:34:50 by jwe]
jwe
parents: 2386
diff changeset
31
5525
558c69736dc0 [project @ 2005-11-01 00:49:50 by jwe]
jwe
parents: 5524
diff changeset
32 #include "quit.h"
558c69736dc0 [project @ 2005-11-01 00:49:50 by jwe]
jwe
parents: 5524
diff changeset
33
1650
23aa282707e8 [project @ 1995-12-20 06:53:12 by jwe]
jwe
parents: 1574
diff changeset
34 #include "oct-cmplx.h"
8758
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
35 #include "oct-locbuf.h"
8897
fd83cc87f55e add missing include
Jaroslav Hajek <highegg@gmail.com>
parents: 8780
diff changeset
36 #include "oct-inttypes.h"
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
37 #include "Array-util.h"
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
38
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
39 // Provides some commonly repeated, basic loop templates.
461
00f8b2242a18 [project @ 1994-06-06 00:45:57 by jwe]
jwe
parents: 238
diff changeset
40
8380
dbe67764e628 fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents: 7789
diff changeset
41 template <class R, class S>
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
42 inline void mx_inline_fill (size_t n, R *r, S s)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
43 { for (size_t i = 0; i < n; i++) r[i] = s; }
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
44
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
45 #define DEFMXUNOP(F, OP) \
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
46 template <class R, class X> \
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
47 inline void F (size_t n, R *r, const X *x) \
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
48 { for (size_t i = 0; i < n; i++) r[i] = OP x[i]; }
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
49
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
50 DEFMXUNOP (mx_inline_uminus, -)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
51
9607
1be3c73ed7b5 reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents: 9578
diff changeset
52 #define DEFMXUNOPEQ(F, OP) \
1be3c73ed7b5 reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents: 9578
diff changeset
53 template <class R> \
1be3c73ed7b5 reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents: 9578
diff changeset
54 inline void F (size_t n, R *r) \
1be3c73ed7b5 reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents: 9578
diff changeset
55 { for (size_t i = 0; i < n; i++) r[i] = OP r[i]; }
1be3c73ed7b5 reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents: 9578
diff changeset
56
1be3c73ed7b5 reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents: 9578
diff changeset
57 DEFMXUNOPEQ (mx_inline_uminus2, -)
1be3c73ed7b5 reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents: 9578
diff changeset
58
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
59 #define DEFMXUNBOOLOP(F, OP) \
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
60 template <class X> \
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
61 inline void F (size_t n, bool *r, const X *x) \
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
62 { const X zero = X(); for (size_t i = 0; i < n; i++) r[i] = x[i] OP zero; }
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 DEFMXUNBOOLOP (mx_inline_iszero, ==)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
65 DEFMXUNBOOLOP (mx_inline_notzero, !=)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
66
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
67 #define DEFMXBINOP(F, OP) \
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
68 template <class R, class X, class Y> \
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
69 inline void F (size_t n, R *r, const X *x, const Y *y) \
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
70 { for (size_t i = 0; i < n; i++) r[i] = x[i] OP y[i]; } \
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
71 template <class R, class X, class Y> \
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
72 inline void F (size_t n, R *r, const X *x, Y y) \
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
73 { for (size_t i = 0; i < n; i++) r[i] = x[i] OP y; } \
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
74 template <class R, class X, class Y> \
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
75 inline void F (size_t n, R *r, X x, const Y *y) \
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
76 { for (size_t i = 0; i < n; i++) r[i] = x OP y[i]; }
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
77
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
78 DEFMXBINOP (mx_inline_add, +)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
79 DEFMXBINOP (mx_inline_sub, -)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
80 DEFMXBINOP (mx_inline_mul, *)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
81 DEFMXBINOP (mx_inline_div, /)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
82
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
83 #define DEFMXBINOPEQ(F, OP) \
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
84 template <class R, class X> \
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
85 inline void F (size_t n, R *r, const X *x) \
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
86 { for (size_t i = 0; i < n; i++) r[i] OP x[i]; } \
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
87 template <class R, class X> \
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
88 inline void F (size_t n, R *r, X x) \
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
89 { for (size_t i = 0; i < n; i++) r[i] OP x; }
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
90
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
91 DEFMXBINOPEQ (mx_inline_add2, +=)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
92 DEFMXBINOPEQ (mx_inline_sub2, -=)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
93 DEFMXBINOPEQ (mx_inline_mul2, *=)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
94 DEFMXBINOPEQ (mx_inline_div2, /=)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
95
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
96 #define DEFMXCMPOP(F, OP) \
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
97 template <class X, class Y> \
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
98 inline void F (size_t n, bool *r, const X *x, const Y *y) \
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
99 { for (size_t i = 0; i < n; i++) r[i] = x[i] OP y[i]; } \
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
100 template <class X, class Y> \
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
101 inline void F (size_t n, bool *r, const X *x, Y y) \
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
102 { for (size_t i = 0; i < n; i++) r[i] = x[i] OP y; } \
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
103 template <class X, class Y> \
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
104 inline void F (size_t n, bool *r, X x, const Y *y) \
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
105 { for (size_t i = 0; i < n; i++) r[i] = x OP y[i]; }
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
106
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
107 DEFMXCMPOP (mx_inline_lt, <)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
108 DEFMXCMPOP (mx_inline_le, <=)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
109 DEFMXCMPOP (mx_inline_gt, >)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
110 DEFMXCMPOP (mx_inline_ge, >=)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
111 DEFMXCMPOP (mx_inline_eq, ==)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
112 DEFMXCMPOP (mx_inline_ne, !=)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
113
9553
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
114 // Convert to logical value, for logical op purposes.
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
115 template <class T> inline bool logical_value (T x) { return x; }
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
116 template <class T> inline bool logical_value (const octave_int<T>& x)
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
117 { return x.value (); }
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
118
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
119 // NaNs in real data should generate an error. Doing it on-the-fly is faster.
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
120
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
121 #define DEFLOGCHKNAN(ARG, ZERO) \
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
122 inline bool logical_value (ARG x) \
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
123 { if (xisnan (x)) gripe_nan_to_logical_conversion (); return x != ZERO; }
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
124
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
125 DEFLOGCHKNAN (double, 0.0)
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
126 DEFLOGCHKNAN (const Complex&, 0.0)
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
127 DEFLOGCHKNAN (float, 0.0f)
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
128 DEFLOGCHKNAN (const FloatComplex&, 0.0f)
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
129
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
130 template <class X>
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
131 void mx_inline_not (size_t n, bool *r, const X* x)
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
132 {
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
133 for (size_t i = 0; i < n; i++)
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
134 r[i] = ! logical_value (x[i]);
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
135 }
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
136
9607
1be3c73ed7b5 reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents: 9578
diff changeset
137 inline void mx_inline_not2 (size_t n, bool *r)
1be3c73ed7b5 reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents: 9578
diff changeset
138 {
1be3c73ed7b5 reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents: 9578
diff changeset
139 for (size_t i = 0; i < n; i++) r[i] = ! r[i];
1be3c73ed7b5 reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents: 9578
diff changeset
140 }
1be3c73ed7b5 reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents: 9578
diff changeset
141
9553
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
142 #define DEFMXBOOLOP(F, NOT1, OP, NOT2) \
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
143 template <class X, class Y> \
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
144 inline void F (size_t n, bool *r, const X *x, const Y *y) \
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
145 { \
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
146 for (size_t i = 0; i < n; i++) \
9553
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
147 r[i] = (NOT1 logical_value (x[i])) OP (NOT2 logical_value (y[i])); \
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
148 } \
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
149 template <class X, class Y> \
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
150 inline void F (size_t n, bool *r, const X *x, Y y) \
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
151 { \
9553
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
152 const bool yy = (NOT2 logical_value (y)); \
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
153 for (size_t i = 0; i < n; i++) \
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
154 r[i] = (NOT1 logical_value (x[i])) OP yy; \
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
155 } \
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
156 template <class X, class Y> \
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
157 inline void F (size_t n, bool *r, X x, const Y *y) \
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 const bool xx = (NOT1 logical_value (x)); \
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
160 for (size_t i = 0; i < n; i++) \
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
161 r[i] = xx OP (NOT2 logical_value (y[i])); \
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
162 }
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
163
9553
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
164 DEFMXBOOLOP (mx_inline_and, , &, )
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
165 DEFMXBOOLOP (mx_inline_or, , |, )
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
166 DEFMXBOOLOP (mx_inline_not_and, !, &, )
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
167 DEFMXBOOLOP (mx_inline_not_or, !, |, )
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
168 DEFMXBOOLOP (mx_inline_and_not, , &, !)
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
169 DEFMXBOOLOP (mx_inline_or_not, , |, !)
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
170
9612
66970dd627f6 further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9607
diff changeset
171 #define DEFMXBOOLOPEQ(F, OP) \
66970dd627f6 further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9607
diff changeset
172 template <class X> \
66970dd627f6 further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9607
diff changeset
173 inline void F (size_t n, bool *r, const X *x) \
66970dd627f6 further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9607
diff changeset
174 { \
66970dd627f6 further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9607
diff changeset
175 for (size_t i = 0; i < n; i++) \
66970dd627f6 further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9607
diff changeset
176 r[i] OP logical_value (x[i]); \
66970dd627f6 further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9607
diff changeset
177 } \
66970dd627f6 further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9607
diff changeset
178
66970dd627f6 further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9607
diff changeset
179 DEFMXBOOLOPEQ (mx_inline_and2, &=)
66970dd627f6 further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9607
diff changeset
180 DEFMXBOOLOPEQ (mx_inline_or2, |=)
66970dd627f6 further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9607
diff changeset
181
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
182 template <class T>
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
183 inline bool
9814
2b29f3472e20 add a couple of useful loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
184 mx_inline_any_nan (size_t n, const T* x)
2b29f3472e20 add a couple of useful loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
185 {
2b29f3472e20 add a couple of useful loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
186 for (size_t i = 0; i < n; i++)
2b29f3472e20 add a couple of useful loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
187 {
2b29f3472e20 add a couple of useful loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
188 if (xisnan (x[i]))
2b29f3472e20 add a couple of useful loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
189 return true;
2b29f3472e20 add a couple of useful loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
190 }
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
191
9814
2b29f3472e20 add a couple of useful loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
192 return false;
8380
dbe67764e628 fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents: 7789
diff changeset
193 }
dbe67764e628 fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents: 7789
diff changeset
194
9814
2b29f3472e20 add a couple of useful loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
195 template<class T>
2b29f3472e20 add a couple of useful loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
196 inline bool
2b29f3472e20 add a couple of useful loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
197 mx_inline_all_real (size_t n, const std::complex<T>* x)
2b29f3472e20 add a couple of useful loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
198 {
2b29f3472e20 add a couple of useful loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
199 for (size_t i = 0; i < n; i++)
2b29f3472e20 add a couple of useful loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
200 {
2b29f3472e20 add a couple of useful loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
201 if (x[i].imag () != 0)
2b29f3472e20 add a couple of useful loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
202 return false;
2b29f3472e20 add a couple of useful loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
203 }
2b29f3472e20 add a couple of useful loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
204
2b29f3472e20 add a couple of useful loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
205 return true;
2b29f3472e20 add a couple of useful loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
206 }
2811
1dd37f97364a [project @ 1997-03-12 23:06:13 by jwe]
jwe
parents: 2804
diff changeset
207
9800
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
208 #define DEFMXMAPPER(F, FUN) \
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
209 template <class T> \
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
210 inline void F (size_t n, T *r, const T *x) \
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
211 { for (size_t i = 0; i < n; i++) r[i] = FUN (x[i]); }
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
212
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
213 template<class T>
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
214 inline void mx_inline_real (size_t n, T *r, const std::complex<T>* x)
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
215 { for (size_t i = 0; i < n; i++) r[i] = x[i].real (); }
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
216 template<class T>
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
217 inline void mx_inline_imag (size_t n, T *r, const std::complex<T>* x)
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
218 { for (size_t i = 0; i < n; i++) r[i] = x[i].imag (); }
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
219
9743
26abff55f6fe optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents: 9721
diff changeset
220 // Pairwise minimums/maximums
9800
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
221 #define DEFMXMAPPER2(F, FUN) \
9743
26abff55f6fe optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents: 9721
diff changeset
222 template <class T> \
26abff55f6fe optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents: 9721
diff changeset
223 inline void F (size_t n, T *r, const T *x, const T *y) \
26abff55f6fe optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents: 9721
diff changeset
224 { for (size_t i = 0; i < n; i++) r[i] = FUN (x[i], y[i]); } \
26abff55f6fe optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents: 9721
diff changeset
225 template <class T> \
26abff55f6fe optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents: 9721
diff changeset
226 inline void F (size_t n, T *r, const T *x, T y) \
26abff55f6fe optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents: 9721
diff changeset
227 { for (size_t i = 0; i < n; i++) r[i] = FUN (x[i], y); } \
26abff55f6fe optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents: 9721
diff changeset
228 template <class T> \
26abff55f6fe optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents: 9721
diff changeset
229 inline void F (size_t n, T *r, T x, const T *y) \
26abff55f6fe optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents: 9721
diff changeset
230 { for (size_t i = 0; i < n; i++) r[i] = FUN (x, y[i]); }
3
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
231
9800
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
232 DEFMXMAPPER2 (mx_inline_xmin, xmin)
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
233 DEFMXMAPPER2 (mx_inline_xmax, xmax)
2811
1dd37f97364a [project @ 1997-03-12 23:06:13 by jwe]
jwe
parents: 2804
diff changeset
234
9800
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
235 // Arbitrary function appliers. The function is a template parameter to enable
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
236 // inlining.
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
237 template <class R, class X, R fun (X x)>
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
238 inline void mx_inline_map (size_t n, R *r, const X *x)
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
239 { for (size_t i = 0; i < n; i++) r[i] = fun (x[i]); }
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
240
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
241 template <class R, class X, R fun (const X& x)>
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
242 inline void mx_inline_map (size_t n, R *r, const X *x)
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
243 { for (size_t i = 0; i < n; i++) r[i] = fun (x[i]); }
3
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
244
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
245 // Appliers. Since these call the operation just once, we pass it as
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
246 // 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
247
9800
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
248 #define AELEMT(ARRAY) typename ARRAY::element_type
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
249 template <class RNDA, class XNDA>
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
250 inline RNDA
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
251 do_mx_unary_op (const XNDA& x,
9800
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
252 void (*op) (size_t, AELEMT(RNDA) *,
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
253 const AELEMT(XNDA) *))
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
254 {
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
255 RNDA r (x.dims ());
9612
66970dd627f6 further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9607
diff changeset
256 op (r.length (), r.fortran_vec (), x.data ());
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
257 return r;
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
258 }
2811
1dd37f97364a [project @ 1997-03-12 23:06:13 by jwe]
jwe
parents: 2804
diff changeset
259
9800
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
260 // Shortcuts for applying mx_inline_map.
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
261
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
262 template <class RNDA, class XNDA, AELEMT(RNDA) fun (AELEMT(XNDA))>
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
263 inline RNDA
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
264 do_mx_unary_map (const XNDA& x)
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
265 {
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
266 return do_mx_unary_op<RNDA, XNDA> (x, mx_inline_map<AELEMT(RNDA), AELEMT(XNDA), fun>);
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
267 }
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
268
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
269 template <class RNDA, class XNDA, AELEMT(RNDA) fun (const AELEMT(XNDA)&)>
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
270 inline RNDA
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
271 do_mx_unary_map (const XNDA& x)
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
272 {
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
273 return do_mx_unary_op<RNDA, XNDA> (x, mx_inline_map<AELEMT(RNDA), AELEMT(XNDA), fun>);
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
274 }
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
275
9607
1be3c73ed7b5 reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents: 9578
diff changeset
276 template <class RNDA>
1be3c73ed7b5 reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents: 9578
diff changeset
277 inline RNDA&
1be3c73ed7b5 reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents: 9578
diff changeset
278 do_mx_inplace_op (RNDA& r,
9800
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
279 void (*op) (size_t, AELEMT(RNDA) *))
9607
1be3c73ed7b5 reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents: 9578
diff changeset
280 {
1be3c73ed7b5 reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents: 9578
diff changeset
281 op (r.numel (), r.fortran_vec ());
1be3c73ed7b5 reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents: 9578
diff changeset
282 return r;
1be3c73ed7b5 reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents: 9578
diff changeset
283 }
1be3c73ed7b5 reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents: 9578
diff changeset
284
1be3c73ed7b5 reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents: 9578
diff changeset
285
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
286 template <class RNDA, class XNDA, class YNDA>
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
287 inline RNDA
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
288 do_mm_binary_op (const XNDA& x, const YNDA& y,
9800
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
289 void (*op) (size_t, AELEMT(RNDA) *,
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
290 const AELEMT(XNDA) *,
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
291 const AELEMT(YNDA) *),
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
292 const char *opname)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
293 {
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
294 dim_vector dx = x.dims (), dy = y.dims ();
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
295 if (dx == dy)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
296 {
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
297 RNDA r (dx);
9612
66970dd627f6 further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9607
diff changeset
298 op (r.length (), r.fortran_vec (), x.data (), y.data ());
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
299 return r;
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
300 }
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
301 else
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
302 {
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
303 gripe_nonconformant (opname, dx, dy);
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
304 return RNDA ();
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
305 }
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
306 }
3
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
307
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
308 template <class RNDA, class XNDA, class YS>
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
309 inline RNDA
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
310 do_ms_binary_op (const XNDA& x, const YS& y,
9800
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
311 void (*op) (size_t, AELEMT(RNDA) *,
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
312 const AELEMT(XNDA) *, YS))
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
313 {
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
314 RNDA r (x.dims ());
9612
66970dd627f6 further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9607
diff changeset
315 op (r.length (), r.fortran_vec (), x.data (), y);
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
316 return r;
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
317 }
3
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
318
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
319 template <class RNDA, class XS, class YNDA>
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
320 inline RNDA
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
321 do_sm_binary_op (const XS& x, const YNDA& y,
9800
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
322 void (*op) (size_t, AELEMT(RNDA) *, XS,
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
323 const AELEMT(YNDA) *))
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
324 {
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
325 RNDA r (y.dims ());
9612
66970dd627f6 further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9607
diff changeset
326 op (r.length (), r.fortran_vec (), x, y.data ());
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
327 return r;
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
328 }
3
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
329
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
330 template <class RNDA, class XNDA>
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
331 inline RNDA&
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
332 do_mm_inplace_op (RNDA& r, const XNDA& x,
9800
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
333 void (*op) (size_t, AELEMT(RNDA) *,
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
334 const AELEMT(XNDA) *),
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
335 const char *opname)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
336 {
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
337 dim_vector dr = r.dims (), dx = x.dims ();
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
338 if (dr == dx)
9612
66970dd627f6 further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9607
diff changeset
339 op (r.length (), r.fortran_vec (), x.data ());
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
340 else
9612
66970dd627f6 further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9607
diff changeset
341 gripe_nonconformant (opname, dr, dx);
66970dd627f6 further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9607
diff changeset
342 return r;
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
343 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
344
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
345 template <class RNDA, class XS>
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
346 inline RNDA&
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
347 do_ms_inplace_op (RNDA& r, const XS& x,
9800
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
348 void (*op) (size_t, AELEMT(RNDA) *, XS))
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
349 {
9612
66970dd627f6 further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9607
diff changeset
350 op (r.length (), r.fortran_vec (), x);
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
351 return r;
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
352 }
3
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
353
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
354 template <class T1, class T2>
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
355 inline bool
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
356 mx_inline_equal (size_t n, const T1 *x, const T2 *y)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
357 {
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
358 for (size_t i = 0; i < n; i++)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
359 if (x[i] != y[i])
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
360 return false;
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
361 return true;
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
362 }
3
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
363
2804
eedc2f3f61f7 [project @ 1997-03-11 04:34:50 by jwe]
jwe
parents: 2386
diff changeset
364 #define OP_DUP_FCN(OP, F, R, T) \
eedc2f3f61f7 [project @ 1997-03-11 04:34:50 by jwe]
jwe
parents: 2386
diff changeset
365 static inline R * \
eedc2f3f61f7 [project @ 1997-03-11 04:34:50 by jwe]
jwe
parents: 2386
diff changeset
366 F (const T *x, size_t n) \
eedc2f3f61f7 [project @ 1997-03-11 04:34:50 by jwe]
jwe
parents: 2386
diff changeset
367 { \
eedc2f3f61f7 [project @ 1997-03-11 04:34:50 by jwe]
jwe
parents: 2386
diff changeset
368 R *r = 0; \
eedc2f3f61f7 [project @ 1997-03-11 04:34:50 by jwe]
jwe
parents: 2386
diff changeset
369 if (n > 0) \
eedc2f3f61f7 [project @ 1997-03-11 04:34:50 by jwe]
jwe
parents: 2386
diff changeset
370 { \
eedc2f3f61f7 [project @ 1997-03-11 04:34:50 by jwe]
jwe
parents: 2386
diff changeset
371 r = new R [n]; \
eedc2f3f61f7 [project @ 1997-03-11 04:34:50 by jwe]
jwe
parents: 2386
diff changeset
372 for (size_t i = 0; i < n; i++) \
eedc2f3f61f7 [project @ 1997-03-11 04:34:50 by jwe]
jwe
parents: 2386
diff changeset
373 r[i] = OP (x[i]); \
eedc2f3f61f7 [project @ 1997-03-11 04:34:50 by jwe]
jwe
parents: 2386
diff changeset
374 } \
eedc2f3f61f7 [project @ 1997-03-11 04:34:50 by jwe]
jwe
parents: 2386
diff changeset
375 return r; \
eedc2f3f61f7 [project @ 1997-03-11 04:34:50 by jwe]
jwe
parents: 2386
diff changeset
376 }
3
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
377
3769
7c8e3c42ed04 [project @ 2001-01-31 22:15:51 by jwe]
jwe
parents: 3504
diff changeset
378 OP_DUP_FCN (, mx_inline_dup, double, double)
7c8e3c42ed04 [project @ 2001-01-31 22:15:51 by jwe]
jwe
parents: 3504
diff changeset
379 OP_DUP_FCN (, mx_inline_dup, Complex, Complex)
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
380 OP_DUP_FCN (, mx_inline_dup, float, float)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
381 OP_DUP_FCN (, mx_inline_dup, FloatComplex, FloatComplex)
3
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
382
2804
eedc2f3f61f7 [project @ 1997-03-11 04:34:50 by jwe]
jwe
parents: 2386
diff changeset
383 // These should really return a bool *. Also, they should probably be
eedc2f3f61f7 [project @ 1997-03-11 04:34:50 by jwe]
jwe
parents: 2386
diff changeset
384 // in with a collection of other element-by-element boolean ops.
3769
7c8e3c42ed04 [project @ 2001-01-31 22:15:51 by jwe]
jwe
parents: 3504
diff changeset
385 OP_DUP_FCN (0.0 ==, mx_inline_not, double, double)
7c8e3c42ed04 [project @ 2001-01-31 22:15:51 by jwe]
jwe
parents: 3504
diff changeset
386 OP_DUP_FCN (0.0 ==, mx_inline_not, double, Complex)
3
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
387
3769
7c8e3c42ed04 [project @ 2001-01-31 22:15:51 by jwe]
jwe
parents: 3504
diff changeset
388 OP_DUP_FCN (, mx_inline_make_complex, Complex, double)
2804
eedc2f3f61f7 [project @ 1997-03-11 04:34:50 by jwe]
jwe
parents: 2386
diff changeset
389
3769
7c8e3c42ed04 [project @ 2001-01-31 22:15:51 by jwe]
jwe
parents: 3504
diff changeset
390 OP_DUP_FCN (-, mx_inline_change_sign, double, double)
7c8e3c42ed04 [project @ 2001-01-31 22:15:51 by jwe]
jwe
parents: 3504
diff changeset
391 OP_DUP_FCN (-, mx_inline_change_sign, Complex, Complex)
3
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
392
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
393 OP_DUP_FCN (std::abs, mx_inline_fabs_dup, double, double)
a1ae2aae903e abs,real,imag,conj: use code from mx-inlines rather than the generic map
Jaroslav Hajek <highegg@gmail.com>
parents: 8380
diff changeset
394 OP_DUP_FCN (std::abs, mx_inline_cabs_dup, double, Complex)
3769
7c8e3c42ed04 [project @ 2001-01-31 22:15:51 by jwe]
jwe
parents: 3504
diff changeset
395 OP_DUP_FCN (real, mx_inline_real_dup, double, Complex)
7c8e3c42ed04 [project @ 2001-01-31 22:15:51 by jwe]
jwe
parents: 3504
diff changeset
396 OP_DUP_FCN (imag, mx_inline_imag_dup, double, Complex)
7c8e3c42ed04 [project @ 2001-01-31 22:15:51 by jwe]
jwe
parents: 3504
diff changeset
397 OP_DUP_FCN (conj, mx_inline_conj_dup, Complex, Complex)
3
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
398
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
399 OP_DUP_FCN (0.0 ==, mx_inline_not, float, float)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
400 OP_DUP_FCN (static_cast<float>(0.0) ==, mx_inline_not, float, FloatComplex)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
401
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
402 OP_DUP_FCN (, mx_inline_make_complex, FloatComplex, float)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
403
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
404 OP_DUP_FCN (-, mx_inline_change_sign, float, float)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
405 OP_DUP_FCN (-, mx_inline_change_sign, FloatComplex, FloatComplex)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
406
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
407 OP_DUP_FCN (std::abs, mx_inline_fabs_dup, float, float)
a1ae2aae903e abs,real,imag,conj: use code from mx-inlines rather than the generic map
Jaroslav Hajek <highegg@gmail.com>
parents: 8380
diff changeset
408 OP_DUP_FCN (std::abs, mx_inline_cabs_dup, float, FloatComplex)
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
409 OP_DUP_FCN (real, mx_inline_real_dup, float, FloatComplex)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
410 OP_DUP_FCN (imag, mx_inline_imag_dup, float, FloatComplex)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
411 OP_DUP_FCN (conj, mx_inline_conj_dup, FloatComplex, FloatComplex)
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
412
8899
4ab9654eceac update comment
Jaroslav Hajek <highegg@gmail.com>
parents: 8897
diff changeset
413 // FIXME: Due to a performance defect in g++ (<= 4.3), std::norm is slow unless
4ab9654eceac update comment
Jaroslav Hajek <highegg@gmail.com>
parents: 8897
diff changeset
414 // ffast-math is on (not by default even with -O3). The following helper function
4ab9654eceac update comment
Jaroslav Hajek <highegg@gmail.com>
parents: 8897
diff changeset
415 // gives the expected straightforward implementation of std::norm.
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
416 template <class T>
8743
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
417 inline T cabsq (const std::complex<T>& c)
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
418 { return c.real () * c.real () + c.imag () * c.imag (); }
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
419
8743
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
420 // default. works for integers and bool.
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
421 template <class T>
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
422 inline bool xis_true (T x) { return x; }
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
423 template <class T>
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
424 inline bool xis_false (T x) { return ! x; }
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
425 // for octave_ints
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
426 template <class T>
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
427 inline bool xis_true (const octave_int<T>& x) { return x.value (); }
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
428 template <class T>
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
429 inline bool xis_false (const octave_int<T>& x) { return ! x.value (); }
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
430 // for reals, we want to ignore NaNs.
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
431 inline bool xis_true (double x) { return ! xisnan (x) && x != 0.0; }
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
432 inline bool xis_false (double x) { return x == 0.0; }
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
433 inline bool xis_true (float x) { return ! xisnan (x) && x != 0.0f; }
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
434 inline bool xis_false (float x) { return x == 0.0f; }
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
435 // Ditto for complex.
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
436 inline bool xis_true (const Complex& x) { return ! xisnan (x) && x != 0.0; }
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
437 inline bool xis_false (const Complex& x) { return x == 0.0; }
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
438 inline bool xis_true (const FloatComplex& x) { return ! xisnan (x) && x != 0.0f; }
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
439 inline bool xis_false (const FloatComplex& x) { return x == 0.0f; }
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
440
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
441 #define OP_RED_SUM(ac, el) ac += el
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
442 #define OP_RED_PROD(ac, el) ac *= el
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
443 #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
444 #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
445
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
446 inline void op_dble_sum(double& ac, float el)
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
447 { ac += el; }
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
448 inline void op_dble_sum(Complex& ac, const FloatComplex& el)
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
449 { ac += el; } // FIXME: guaranteed?
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
450 template <class T>
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
451 inline void op_dble_sum(double& ac, const octave_int<T>& el)
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
452 { ac += el.double_value (); }
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
453
8743
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
454 // The following two implement a simple short-circuiting.
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
455 #define OP_RED_ANYC(ac, el) if (xis_true (el)) { ac = true; break; } else continue
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
456 #define OP_RED_ALLC(ac, el) if (xis_false (el)) { ac = false; break; } else continue
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
457
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
458 #define OP_RED_FCN(F, TSRC, TRES, OP, ZERO) \
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
459 template <class T> \
8743
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
460 inline TRES \
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
461 F (const TSRC* v, octave_idx_type n) \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
462 { \
8743
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
463 TRES ac = ZERO; \
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
464 for (octave_idx_type i = 0; i < n; i++) \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
465 OP(ac, v[i]); \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
466 return ac; \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
467 }
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
468
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
469 #define PROMOTE_DOUBLE(T) typename subst_template_param<std::complex, T, double>::type
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
470
8743
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
471 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
472 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
473 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
474 OP_RED_FCN (mx_inline_prod, T, T, OP_RED_PROD, 1)
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
475 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
476 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
477 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
478 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
479
8743
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
480
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
481 #define OP_RED_FCN2(F, TSRC, TRES, OP, ZERO) \
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
482 template <class T> \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
483 inline void \
8743
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
484 F (const TSRC* v, TRES *r, octave_idx_type m, octave_idx_type n) \
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
485 { \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
486 for (octave_idx_type i = 0; i < m; i++) \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
487 r[i] = ZERO; \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
488 for (octave_idx_type j = 0; j < n; j++) \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
489 { \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
490 for (octave_idx_type i = 0; i < m; i++) \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
491 OP(r[i], v[i]); \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
492 v += m; \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
493 } \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
494 }
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
495
8743
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
496 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
497 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
498 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
499 OP_RED_FCN2 (mx_inline_prod, T, T, OP_RED_PROD, 1)
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
500 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
501 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
502
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
503 // Using the general code for any/all would sacrifice short-circuiting.
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
504 // OTOH, going by rows would sacrifice cache-coherence. The following algorithm
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
505 // will achieve both, at the cost of a temporary octave_idx_type array.
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
506
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
507 #define OP_ROW_SHORT_CIRCUIT(F, PRED, ZERO) \
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
508 template <class T> \
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
509 inline void \
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
510 F (const T* v, bool *r, octave_idx_type m, octave_idx_type n) \
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
511 { \
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
512 /* FIXME: it may be sub-optimal to allocate the buffer here. */ \
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
513 OCTAVE_LOCAL_BUFFER (octave_idx_type, iact, m); \
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
514 for (octave_idx_type i = 0; i < m; i++) iact[i] = i; \
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
515 octave_idx_type nact = m; \
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
516 for (octave_idx_type j = 0; j < n; j++) \
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
517 { \
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
518 octave_idx_type k = 0; \
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
519 for (octave_idx_type i = 0; i < nact; i++) \
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
520 { \
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
521 octave_idx_type ia = iact[i]; \
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
522 if (! PRED (v[ia])) \
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
523 iact[k++] = ia; \
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
524 } \
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
525 nact = k; \
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
526 v += m; \
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
527 } \
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
528 for (octave_idx_type i = 0; i < m; i++) r[i] = ! ZERO; \
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
529 for (octave_idx_type i = 0; i < nact; i++) r[iact[i]] = ZERO; \
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
530 }
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
531
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
532 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
533 OP_ROW_SHORT_CIRCUIT (mx_inline_all, xis_false, true)
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
534
8743
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
535 #define OP_RED_FCNN(F, TSRC, TRES) \
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
536 template <class T> \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
537 inline void \
8743
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
538 F (const TSRC *v, TRES *r, octave_idx_type l, \
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
539 octave_idx_type n, octave_idx_type u) \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
540 { \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
541 if (l == 1) \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
542 { \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
543 for (octave_idx_type i = 0; i < u; i++) \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
544 { \
8756
d0755c9db5ed implement fast logical sum (counting)
Jaroslav Hajek <highegg@gmail.com>
parents: 8751
diff changeset
545 r[i] = F<T> (v, n); \
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
546 v += n; \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
547 } \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
548 } \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
549 else \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
550 { \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
551 for (octave_idx_type i = 0; i < u; i++) \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
552 { \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
553 F (v, r, l, n); \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
554 v += l*n; \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
555 r += l; \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
556 } \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
557 } \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
558 }
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
559
8743
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
560 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
561 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
562 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
563 OP_RED_FCNN (mx_inline_prod, T, T)
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
564 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
565 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
566 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
567 OP_RED_FCNN (mx_inline_all, T, bool)
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
568
8780
ea76466605ba support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents: 8777
diff changeset
569 #define OP_CUM_FCN(F, TSRC, TRES, OP) \
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
570 template <class T> \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
571 inline void \
8780
ea76466605ba support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents: 8777
diff changeset
572 F (const TSRC *v, TRES *r, octave_idx_type n) \
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
573 { \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
574 if (n) \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
575 { \
8780
ea76466605ba support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents: 8777
diff changeset
576 TRES t = r[0] = v[0]; \
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
577 for (octave_idx_type i = 1; i < n; i++) \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
578 r[i] = t = t OP v[i]; \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
579 } \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
580 }
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
581
8780
ea76466605ba support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents: 8777
diff changeset
582 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
583 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
584 OP_CUM_FCN (mx_inline_cumcount, bool, T, +)
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
585
8780
ea76466605ba support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents: 8777
diff changeset
586 #define OP_CUM_FCN2(F, TSRC, TRES, OP) \
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
587 template <class T> \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
588 inline void \
8780
ea76466605ba support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents: 8777
diff changeset
589 F (const TSRC *v, TRES *r, octave_idx_type m, octave_idx_type n) \
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
590 { \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
591 if (n) \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
592 { \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
593 for (octave_idx_type i = 0; i < m; i++) \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
594 r[i] = v[i]; \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
595 const T *r0 = r; \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
596 for (octave_idx_type j = 1; j < n; j++) \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
597 { \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
598 r += m; v += m; \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
599 for (octave_idx_type i = 0; i < m; i++) \
8780
ea76466605ba support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents: 8777
diff changeset
600 r[i] = r0[i] OP v[i]; \
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
601 r0 += m; \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
602 } \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
603 } \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
604 }
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
605
8780
ea76466605ba support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents: 8777
diff changeset
606 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
607 OP_CUM_FCN2 (mx_inline_cumprod, T, T, *)
ea76466605ba support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents: 8777
diff changeset
608 OP_CUM_FCN2 (mx_inline_cumcount, bool, T, *)
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
609
8780
ea76466605ba support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents: 8777
diff changeset
610 #define OP_CUM_FCNN(F, TSRC, TRES) \
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
611 template <class T> \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
612 inline void \
8780
ea76466605ba support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents: 8777
diff changeset
613 F (const TSRC *v, TRES *r, octave_idx_type l, \
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
614 octave_idx_type n, octave_idx_type u) \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
615 { \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
616 if (l == 1) \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
617 { \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
618 for (octave_idx_type i = 0; i < u; i++) \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
619 { \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
620 F (v, r, n); \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
621 v += n; r += n; \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
622 } \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
623 } \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
624 else \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
625 { \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
626 for (octave_idx_type i = 0; i < u; i++) \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
627 { \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
628 F (v, r, l, n); \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
629 v += l*n; \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
630 r += l*n; \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
631 } \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
632 } \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
633 }
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
634
8780
ea76466605ba support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents: 8777
diff changeset
635 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
636 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
637 OP_CUM_FCNN (mx_inline_cumcount, bool, T)
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
638
8751
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
639 #define OP_MINMAX_FCN(F, OP) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
640 template <class T> \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
641 void F (const T *v, T *r, octave_idx_type n) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
642 { \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
643 if (! n) return; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
644 T tmp = v[0]; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
645 octave_idx_type i = 1; \
8776
d23c33ec6bd3 fix min/max behaviour with NaNs
Jaroslav Hajek <highegg@gmail.com>
parents: 8759
diff changeset
646 if (xisnan (tmp)) \
d23c33ec6bd3 fix min/max behaviour with NaNs
Jaroslav Hajek <highegg@gmail.com>
parents: 8759
diff changeset
647 { \
d23c33ec6bd3 fix min/max behaviour with NaNs
Jaroslav Hajek <highegg@gmail.com>
parents: 8759
diff changeset
648 for (; i < n && xisnan (v[i]); i++) ; \
d23c33ec6bd3 fix min/max behaviour with NaNs
Jaroslav Hajek <highegg@gmail.com>
parents: 8759
diff changeset
649 if (i < n) tmp = v[i]; \
d23c33ec6bd3 fix min/max behaviour with NaNs
Jaroslav Hajek <highegg@gmail.com>
parents: 8759
diff changeset
650 } \
d23c33ec6bd3 fix min/max behaviour with NaNs
Jaroslav Hajek <highegg@gmail.com>
parents: 8759
diff changeset
651 for (; i < n; i++) \
8751
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
652 if (v[i] OP tmp) tmp = v[i]; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
653 *r = tmp; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
654 } \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
655 template <class T> \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
656 void F (const T *v, T *r, octave_idx_type *ri, octave_idx_type n) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
657 { \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
658 if (! n) return; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
659 T tmp = v[0]; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
660 octave_idx_type tmpi = 0; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
661 octave_idx_type i = 1; \
8776
d23c33ec6bd3 fix min/max behaviour with NaNs
Jaroslav Hajek <highegg@gmail.com>
parents: 8759
diff changeset
662 if (xisnan (tmp)) \
d23c33ec6bd3 fix min/max behaviour with NaNs
Jaroslav Hajek <highegg@gmail.com>
parents: 8759
diff changeset
663 { \
d23c33ec6bd3 fix min/max behaviour with NaNs
Jaroslav Hajek <highegg@gmail.com>
parents: 8759
diff changeset
664 for (; i < n && xisnan (v[i]); i++) ; \
d23c33ec6bd3 fix min/max behaviour with NaNs
Jaroslav Hajek <highegg@gmail.com>
parents: 8759
diff changeset
665 if (i < n) { tmp = v[i]; tmpi = i; } \
d23c33ec6bd3 fix min/max behaviour with NaNs
Jaroslav Hajek <highegg@gmail.com>
parents: 8759
diff changeset
666 } \
d23c33ec6bd3 fix min/max behaviour with NaNs
Jaroslav Hajek <highegg@gmail.com>
parents: 8759
diff changeset
667 for (; i < n; i++) \
8751
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
668 if (v[i] OP tmp) { tmp = v[i]; tmpi = i; }\
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
669 *r = tmp; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
670 *ri = tmpi; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
671 }
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
672
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
673 OP_MINMAX_FCN (mx_inline_min, <)
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
674 OP_MINMAX_FCN (mx_inline_max, >)
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
675
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
676 // 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
677 // 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
678 // proceed to a faster code.
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
679
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
680 #define OP_MINMAX_FCN2(F, OP) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
681 template <class T> \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
682 inline void \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
683 F (const T *v, T *r, octave_idx_type m, octave_idx_type n) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
684 { \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
685 if (! n) return; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
686 bool nan = false; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
687 octave_idx_type j = 0; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
688 for (octave_idx_type i = 0; i < m; i++) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
689 { \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
690 r[i] = v[i]; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
691 if (xisnan (v[i])) nan = true; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
692 } \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
693 j++; v += m; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
694 while (nan && j < n) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
695 { \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
696 nan = false; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
697 for (octave_idx_type i = 0; i < m; i++) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
698 { \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
699 if (xisnan (v[i])) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
700 nan = true; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
701 else if (xisnan (r[i]) || v[i] OP r[i]) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
702 r[i] = v[i]; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
703 } \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
704 j++; v += m; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
705 } \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
706 while (j < n) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
707 { \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
708 for (octave_idx_type i = 0; i < m; i++) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
709 if (v[i] OP r[i]) r[i] = v[i]; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
710 j++; v += m; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
711 } \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
712 } \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
713 template <class T> \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
714 inline void \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
715 F (const T *v, T *r, octave_idx_type *ri, \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
716 octave_idx_type m, octave_idx_type n) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
717 { \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
718 if (! n) return; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
719 bool nan = false; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
720 octave_idx_type j = 0; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
721 for (octave_idx_type i = 0; i < m; i++) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
722 { \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
723 r[i] = v[i]; ri[i] = j; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
724 if (xisnan (v[i])) nan = true; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
725 } \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
726 j++; v += m; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
727 while (nan && j < n) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
728 { \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
729 nan = false; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
730 for (octave_idx_type i = 0; i < m; i++) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
731 { \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
732 if (xisnan (v[i])) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
733 nan = true; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
734 else if (xisnan (r[i]) || v[i] OP r[i]) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
735 { r[i] = v[i]; ri[i] = j; } \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
736 } \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
737 j++; v += m; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
738 } \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
739 while (j < n) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
740 { \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
741 for (octave_idx_type i = 0; i < m; i++) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
742 if (v[i] OP r[i]) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
743 { r[i] = v[i]; ri[i] = j; } \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
744 j++; v += m; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
745 } \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
746 }
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
747
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
748 OP_MINMAX_FCN2 (mx_inline_min, <)
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
749 OP_MINMAX_FCN2 (mx_inline_max, >)
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
750
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
751 #define OP_MINMAX_FCNN(F) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
752 template <class T> \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
753 inline void \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
754 F (const T *v, T *r, octave_idx_type l, \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
755 octave_idx_type n, octave_idx_type u) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
756 { \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
757 if (! n) return; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
758 if (l == 1) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
759 { \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
760 for (octave_idx_type i = 0; i < u; i++) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
761 { \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
762 F (v, r, n); \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
763 v += n; r++; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
764 } \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
765 } \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
766 else \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
767 { \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
768 for (octave_idx_type i = 0; i < u; i++) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
769 { \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
770 F (v, r, l, n); \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
771 v += l*n; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
772 r += l; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
773 } \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
774 } \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
775 } \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
776 template <class T> \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
777 inline void \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
778 F (const T *v, T *r, octave_idx_type *ri, \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
779 octave_idx_type l, octave_idx_type n, octave_idx_type u) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
780 { \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
781 if (! n) return; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
782 if (l == 1) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
783 { \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
784 for (octave_idx_type i = 0; i < u; i++) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
785 { \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
786 F (v, r, ri, n); \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
787 v += n; r++; ri++; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
788 } \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
789 } \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
790 else \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
791 { \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
792 for (octave_idx_type i = 0; i < u; i++) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
793 { \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
794 F (v, r, ri, l, n); \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
795 v += l*n; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
796 r += l; ri += l; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
797 } \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
798 } \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
799 }
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
800
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
801 OP_MINMAX_FCNN (mx_inline_min)
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
802 OP_MINMAX_FCNN (mx_inline_max)
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
803
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
804 #define OP_CUMMINMAX_FCN(F, OP) \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
805 template <class T> \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
806 void F (const T *v, T *r, octave_idx_type n) \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
807 { \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
808 if (! n) return; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
809 T tmp = v[0]; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
810 octave_idx_type i = 1, j = 0; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
811 if (xisnan (tmp)) \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
812 { \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
813 for (; i < n && xisnan (v[i]); i++) ; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
814 for (; j < i; j++) r[j] = tmp; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
815 if (i < n) tmp = v[i]; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
816 } \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
817 for (; i < n; i++) \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
818 if (v[i] OP tmp) \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
819 { \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
820 for (; j < i; j++) r[j] = tmp; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
821 tmp = v[i]; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
822 } \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
823 for (; j < i; j++) r[j] = tmp; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
824 } \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
825 template <class T> \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
826 void F (const T *v, T *r, octave_idx_type *ri, octave_idx_type n) \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
827 { \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
828 if (! n) return; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
829 T tmp = v[0]; octave_idx_type tmpi = 0; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
830 octave_idx_type i = 1, j = 0; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
831 if (xisnan (tmp)) \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
832 { \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
833 for (; i < n && xisnan (v[i]); i++) ; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
834 for (; j < i; j++) { r[j] = tmp; ri[j] = tmpi; } \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
835 if (i < n) { tmp = v[i]; tmpi = i; } \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
836 } \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
837 for (; i < n; i++) \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
838 if (v[i] OP tmp) \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
839 { \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
840 for (; j < i; j++) { r[j] = tmp; ri[j] = tmpi; } \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
841 tmp = v[i]; tmpi = i; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
842 } \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
843 for (; j < i; j++) { r[j] = tmp; ri[j] = tmpi; } \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
844 }
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
845
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
846 OP_CUMMINMAX_FCN (mx_inline_cummin, <)
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
847 OP_CUMMINMAX_FCN (mx_inline_cummax, >)
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
848
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
849 // 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
850 // 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
851 // proceed to a faster code.
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
852
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
853 #define OP_CUMMINMAX_FCN2(F, OP) \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
854 template <class T> \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
855 inline void \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
856 F (const T *v, T *r, octave_idx_type m, octave_idx_type n) \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
857 { \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
858 if (! n) return; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
859 bool nan = false; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
860 const T *r0; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
861 octave_idx_type j = 0; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
862 for (octave_idx_type i = 0; i < m; i++) \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
863 { \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
864 r[i] = v[i]; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
865 if (xisnan (v[i])) nan = true; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
866 } \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
867 j++; v += m; r0 = r; r += m; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
868 while (nan && j < n) \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
869 { \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
870 nan = false; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
871 for (octave_idx_type i = 0; i < m; i++) \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
872 { \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
873 if (xisnan (v[i])) \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
874 { r[i] = r0[i]; nan = true; } \
8949
e31d47f2c9bb fixes to row-reducing cummin/cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
875 else if (xisnan (r0[i]) || v[i] OP r0[i]) \
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
876 r[i] = v[i]; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
877 } \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
878 j++; v += m; r0 = r; r += m; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
879 } \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
880 while (j < n) \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
881 { \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
882 for (octave_idx_type i = 0; i < m; i++) \
8949
e31d47f2c9bb fixes to row-reducing cummin/cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
883 if (v[i] OP r0[i]) \
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
884 r[i] = v[i]; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
885 else \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
886 r[i] = r0[i]; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
887 j++; v += m; r0 = r; r += m; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
888 } \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
889 } \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
890 template <class T> \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
891 inline void \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
892 F (const T *v, T *r, octave_idx_type *ri, \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
893 octave_idx_type m, octave_idx_type n) \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
894 { \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
895 if (! n) return; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
896 bool nan = false; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
897 const T *r0; const octave_idx_type *r0i; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
898 octave_idx_type j = 0; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
899 for (octave_idx_type i = 0; i < m; i++) \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
900 { \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
901 r[i] = v[i]; ri[i] = 0; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
902 if (xisnan (v[i])) nan = true; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
903 } \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
904 j++; v += m; r0 = r; r += m; r0i = ri; ri += m; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
905 while (nan && j < n) \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
906 { \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
907 nan = false; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
908 for (octave_idx_type i = 0; i < m; i++) \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
909 { \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
910 if (xisnan (v[i])) \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
911 { r[i] = r0[i]; ri[i] = r0i[i]; nan = true; } \
8949
e31d47f2c9bb fixes to row-reducing cummin/cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
912 else if (xisnan (r0[i]) || v[i] OP r0[i]) \
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
913 { r[i] = v[i]; ri[i] = j; }\
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
914 } \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
915 j++; v += m; r0 = r; r += m; r0i = ri; ri += m; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
916 } \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
917 while (j < n) \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
918 { \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
919 for (octave_idx_type i = 0; i < m; i++) \
8949
e31d47f2c9bb fixes to row-reducing cummin/cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
920 if (v[i] OP r0[i]) \
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
921 { r[i] = v[i]; ri[i] = j; } \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
922 else \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
923 { r[i] = r0[i]; ri[i] = r0i[i]; } \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
924 j++; v += m; r0 = r; r += m; r0i = ri; ri += m; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
925 } \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
926 }
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
927
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
928 OP_CUMMINMAX_FCN2 (mx_inline_cummin, <)
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
929 OP_CUMMINMAX_FCN2 (mx_inline_cummax, >)
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
930
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
931 #define OP_CUMMINMAX_FCNN(F) \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
932 template <class T> \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
933 inline void \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
934 F (const T *v, T *r, octave_idx_type l, \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
935 octave_idx_type n, octave_idx_type u) \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
936 { \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
937 if (! n) return; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
938 if (l == 1) \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
939 { \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
940 for (octave_idx_type i = 0; i < u; i++) \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
941 { \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
942 F (v, r, n); \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
943 v += n; r += n; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
944 } \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
945 } \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
946 else \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
947 { \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
948 for (octave_idx_type i = 0; i < u; i++) \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
949 { \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
950 F (v, r, l, n); \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
951 v += l*n; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
952 r += l*n; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
953 } \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
954 } \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
955 } \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
956 template <class T> \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
957 inline void \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
958 F (const T *v, T *r, octave_idx_type *ri, \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
959 octave_idx_type l, octave_idx_type n, octave_idx_type u) \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
960 { \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
961 if (! n) return; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
962 if (l == 1) \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
963 { \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
964 for (octave_idx_type i = 0; i < u; i++) \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
965 { \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
966 F (v, r, ri, n); \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
967 v += n; r += n; ri += n; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
968 } \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
969 } \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
970 else \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
971 { \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
972 for (octave_idx_type i = 0; i < u; i++) \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
973 { \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
974 F (v, r, ri, l, n); \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
975 v += l*n; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
976 r += l*n; ri += l*n; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
977 } \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
978 } \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
979 }
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
980
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
981 OP_CUMMINMAX_FCNN (mx_inline_cummin)
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
982 OP_CUMMINMAX_FCNN (mx_inline_cummax)
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
983
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
984 template <class T>
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
985 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
986 octave_idx_type order)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
987 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
988 switch (order)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
989 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
990 case 1:
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
991 for (octave_idx_type i = 0; i < n-1; i++)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
992 r[i] = v[i+1] - v[i];
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
993 break;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
994 case 2:
9702
9ecd35a606e3 avoid some warnings from g++
John W. Eaton <jwe@octave.org>
parents: 9612
diff changeset
995 if (n > 1)
9ecd35a606e3 avoid some warnings from g++
John W. Eaton <jwe@octave.org>
parents: 9612
diff changeset
996 {
9ecd35a606e3 avoid some warnings from g++
John W. Eaton <jwe@octave.org>
parents: 9612
diff changeset
997 T lst = v[1] - v[0];
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
998 for (octave_idx_type i = 0; i < n-2; i++)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
999 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1000 T dif = v[i+2] - v[i+1];
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1001 r[i] = dif - lst;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1002 lst = dif;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1003 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1004 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1005 break;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1006 default:
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1007 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1008 OCTAVE_LOCAL_BUFFER (T, buf, n-1);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1009
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1010 for (octave_idx_type i = 0; i < n-1; i++)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1011 buf[i] = v[i+1] - v[i];
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1012
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1013 for (octave_idx_type o = 2; o <= order; o++)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1014 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1015 for (octave_idx_type i = 0; i < n-o; i++)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1016 buf[i] = buf[i+1] - buf[i];
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1017 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1018
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1019 for (octave_idx_type i = 0; i < n-order; i++)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1020 r[i] = buf[i];
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1021 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1022 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1023 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1024
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1025 template <class T>
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1026 void mx_inline_diff (const T *v, T *r,
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1027 octave_idx_type m, octave_idx_type n,
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1028 octave_idx_type order)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1029 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1030 switch (order)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1031 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1032 case 1:
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1033 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
1034 r[i] = v[i+m] - v[i];
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1035 break;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1036 case 2:
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1037 for (octave_idx_type i = 0; i < n-2; i++)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1038 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1039 for (octave_idx_type j = i*m; j < i*m+m; j++)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1040 r[j] = (v[j+m+m] - v[j+m]) + (v[j+m] - v[j]);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1041 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1042 break;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1043 default:
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1044 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1045 OCTAVE_LOCAL_BUFFER (T, buf, n-1);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1046
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1047 for (octave_idx_type j = 0; j < m; j++)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1048 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1049 for (octave_idx_type i = 0; i < n-1; i++)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1050 buf[i] = v[i*m+j+m] - v[i*m+j];
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1051
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1052 for (octave_idx_type o = 2; o <= order; o++)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1053 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1054 for (octave_idx_type i = 0; i < n-o; i++)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1055 buf[i] = buf[i+1] - buf[i];
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1056 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1057
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1058 for (octave_idx_type i = 0; i < n-order; i++)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1059 r[i*m+j] = buf[i];
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1060 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1061 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1062 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1063 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1064
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1065 template <class T>
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1066 inline void
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1067 mx_inline_diff (const T *v, T *r,
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1068 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
1069 octave_idx_type order)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1070 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1071 if (! n) return;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1072 if (l == 1)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1073 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1074 for (octave_idx_type i = 0; i < u; i++)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1075 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1076 mx_inline_diff (v, r, n, order);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1077 v += n; r += n-order;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1078 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1079 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1080 else
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1081 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1082 for (octave_idx_type i = 0; i < u; i++)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1083 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1084 mx_inline_diff (v, r, l, n, order);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1085 v += l*n;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1086 r += l*(n-order);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1087 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1088 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1089 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1090
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1091 // Assistant function
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1092
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1093 inline void
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1094 get_extent_triplet (const dim_vector& dims, int& dim,
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1095 octave_idx_type& l, octave_idx_type& n,
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1096 octave_idx_type& u)
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1097 {
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1098 octave_idx_type ndims = dims.length ();
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1099 if (dim >= ndims)
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1100 {
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1101 l = dims.numel ();
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1102 n = 1;
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1103 u = 1;
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1104 }
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1105 else
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1106 {
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1107 if (dim < 0)
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1108 dim = dims.first_non_singleton ();
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1109
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1110 // calculate extent triplet.
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1111 l = 1, n = dims(dim), u = 1;
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1112 for (octave_idx_type i = 0; i < dim; i++)
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1113 l *= dims (i);
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1114 for (octave_idx_type i = dim + 1; i < ndims; i++)
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1115 u *= dims (i);
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1116 }
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1117 }
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1118
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1119 // Appliers.
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1120 // 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
1121 // maybe it can be done without an explicit parameter?
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1122
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1123 template <class ArrayType, class T>
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1124 inline ArrayType
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1125 do_mx_red_op (const Array<T>& src, int dim,
9800
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
1126 void (*mx_red_op) (const T *, AELEMT(ArrayType) *,
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1127 octave_idx_type, octave_idx_type, octave_idx_type))
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1128 {
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1129 octave_idx_type l, n, u;
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1130 dim_vector dims = src.dims ();
8743
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
1131 // M*b inconsistency: sum([]) = 0 etc.
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
1132 if (dims.length () == 2 && dims(0) == 0 && dims(1) == 0)
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
1133 dims (1) = 1;
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
1134
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1135 get_extent_triplet (dims, dim, l, n, u);
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1136
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1137 // Reduction operation reduces the array size.
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1138 if (dim < dims.length ()) dims(dim) = 1;
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1139 dims.chop_trailing_singletons ();
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1140
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1141 ArrayType ret (dims);
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1142 mx_red_op (src.data (), ret.fortran_vec (), l, n, u);
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1143
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1144 return ret;
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1145 }
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1146
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1147 template <class ArrayType, class T>
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1148 inline ArrayType
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1149 do_mx_cum_op (const Array<T>& src, int dim,
9800
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
1150 void (*mx_cum_op) (const T *, AELEMT(ArrayType) *,
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1151 octave_idx_type, octave_idx_type, octave_idx_type))
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1152 {
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1153 octave_idx_type l, n, u;
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1154 dim_vector dims = src.dims ();
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1155 get_extent_triplet (dims, dim, l, n, u);
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1156
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1157 // Cumulative operation doesn't reduce the array size.
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1158 ArrayType ret (dims);
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1159 mx_cum_op (src.data (), ret.fortran_vec (), l, n, u);
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1160
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1161 return ret;
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1162 }
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1163
8751
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1164 template <class ArrayType>
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1165 inline ArrayType
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1166 do_mx_minmax_op (const ArrayType& src, int dim,
9800
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
1167 void (*mx_minmax_op) (const AELEMT(ArrayType) *, AELEMT(ArrayType) *,
8751
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1168 octave_idx_type, octave_idx_type, octave_idx_type))
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1169 {
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1170 octave_idx_type l, n, u;
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1171 dim_vector dims = src.dims ();
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1172 get_extent_triplet (dims, dim, l, n, u);
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1173
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1174 // If the dimension is zero, we don't do anything.
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1175 if (dim < dims.length () && dims(dim) != 0) dims(dim) = 1;
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1176 dims.chop_trailing_singletons ();
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1177
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1178 ArrayType ret (dims);
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1179 mx_minmax_op (src.data (), ret.fortran_vec (), l, n, u);
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1180
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1181 return ret;
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1182 }
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1183
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1184 template <class ArrayType>
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1185 inline ArrayType
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1186 do_mx_minmax_op (const ArrayType& src, Array<octave_idx_type>& idx, int dim,
9800
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
1187 void (*mx_minmax_op) (const AELEMT(ArrayType) *, AELEMT(ArrayType) *,
8751
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1188 octave_idx_type *,
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1189 octave_idx_type, octave_idx_type, octave_idx_type))
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1190 {
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1191 octave_idx_type l, n, u;
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1192 dim_vector dims = src.dims ();
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1193 get_extent_triplet (dims, dim, l, n, u);
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1194
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1195 // If the dimension is zero, we don't do anything.
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1196 if (dim < dims.length () && dims(dim) != 0) dims(dim) = 1;
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1197 dims.chop_trailing_singletons ();
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1198
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1199 ArrayType ret (dims);
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1200 if (idx.dims () != dims) idx = Array<octave_idx_type> (dims);
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1201
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1202 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
1203 l, n, u);
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1204
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1205 return ret;
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1206 }
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1207
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1208 template <class ArrayType>
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1209 inline ArrayType
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1210 do_mx_cumminmax_op (const ArrayType& src, int dim,
9800
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
1211 void (*mx_cumminmax_op) (const AELEMT(ArrayType) *, AELEMT(ArrayType) *,
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1212 octave_idx_type, octave_idx_type, octave_idx_type))
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1213 {
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1214 octave_idx_type l, n, u;
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1215 dim_vector dims = src.dims ();
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1216 get_extent_triplet (dims, dim, l, n, u);
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1217
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1218 ArrayType ret (dims);
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1219 mx_cumminmax_op (src.data (), ret.fortran_vec (), l, n, u);
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1220
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1221 return ret;
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1222 }
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1223
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1224 template <class ArrayType>
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1225 inline ArrayType
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1226 do_mx_cumminmax_op (const ArrayType& src, Array<octave_idx_type>& idx, int dim,
9800
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
1227 void (*mx_cumminmax_op) (const AELEMT(ArrayType) *, AELEMT(ArrayType) *,
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1228 octave_idx_type *,
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1229 octave_idx_type, octave_idx_type, octave_idx_type))
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1230 {
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1231 octave_idx_type l, n, u;
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1232 dim_vector dims = src.dims ();
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1233 get_extent_triplet (dims, dim, l, n, u);
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1234
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1235 ArrayType ret (dims);
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1236 if (idx.dims () != dims) idx = Array<octave_idx_type> (dims);
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1237
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1238 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
1239 l, n, u);
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1240
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1241 return ret;
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1242 }
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1243
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1244 template <class ArrayType>
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1245 inline ArrayType
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1246 do_mx_diff_op (const ArrayType& src, int dim, octave_idx_type order,
9800
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
1247 void (*mx_diff_op) (const AELEMT(ArrayType) *, AELEMT(ArrayType) *,
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1248 octave_idx_type, octave_idx_type, octave_idx_type,
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1249 octave_idx_type))
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1250 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1251 octave_idx_type l, n, u;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1252 if (order <= 0)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1253 return src;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1254
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1255 dim_vector dims = src.dims ();
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1256
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1257 get_extent_triplet (dims, dim, l, n, u);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1258 if (dim >= dims.length ())
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1259 dims.resize (dim+1, 1);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1260
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1261 if (dims(dim) <= order)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1262 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1263 dims (dim) = 0;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1264 return ArrayType (dims);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1265 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1266 else
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1267 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1268 dims(dim) -= order;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1269 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1270
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1271 ArrayType ret (dims);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1272 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
1273
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1274 return ret;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1275 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1276
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1277 // Fast extra-precise summation. According to
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1278 // 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
1279 // Accurate Sum And Dot Product,
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1280 // 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
1281
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1282 template <class T>
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1283 inline void twosum_accum (T& s, T& e,
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1284 const T& x)
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1285 {
9766
82fe4db20dec fix bad FLOAT_TRUNCATE in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9743
diff changeset
1286 T s1 = s + x, t = s1 - s, 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
1287 s = s1;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1288 e += e1;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1289 }
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1290
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1291 template <class T>
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1292 inline T
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1293 mx_inline_xsum (const T *v, octave_idx_type n)
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1294 {
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1295 T s = 0, e = 0;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1296 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
1297 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
1298
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1299 return s + e;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1300 }
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1301
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1302 template <class T>
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1303 inline void
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1304 mx_inline_xsum (const T *v, T *r,
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1305 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
1306 {
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1307 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
1308 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
1309 e[i] = r[i] = T ();
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1310
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1311 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
1312 {
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1313 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
1314 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
1315
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1316 v += m;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1317 }
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1318
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1319 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
1320 r[i] += e[i];
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1321 }
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1322
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1323 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
1324
2804
eedc2f3f61f7 [project @ 1997-03-11 04:34:50 by jwe]
jwe
parents: 2386
diff changeset
1325 #endif
3
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
1326
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
1327 /*
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
1328 ;;; Local Variables: ***
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
1329 ;;; mode: C++ ***
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
1330 ;;; End: ***
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
1331 */