annotate liboctave/operators/mx-inlines.cc @ 18759:8cc66f091584

Add "native" option to prod() (bug #40349). * data.cc (Fprod): Rewrite docstring to mention new "native", "double" options. Borrow code from Fsum replacing sum with prod. Add %!tests for new behavior. * fCNDArray.h (dprod): New function prototype. * fCNDArray.cc (FloatComplexNDArray::dprod): New function. * fNDArray.h (dprod): New function prototype. * fNDArray.cc (FloatNDArray::dprod): New function. * intNDArray.h (prod): New function prototype. * intNDArray.cc (intNDArray<T>::prod): New function. * mx-inlines.cc (op_dble_prod): New inline functions for implementing double product.
author Rik <rik@octave.org>
date Sun, 04 May 2014 16:08:46 -0700
parents 6c706a83070f
children af41e41ad28e
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
17744
d63878346099 maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents: 15285
diff changeset
3 Copyright (C) 1993-2013 John W. Eaton
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
4 Copyright (C) 2009 Jaroslav Hajek
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
5 Copyright (C) 2009 VZLU Prague
3
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
6
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
7 This file is part of Octave.
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
8
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
9 Octave is free software; you can redistribute it and/or modify it
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
10 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5972
diff changeset
11 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5972
diff changeset
12 option) any later version.
3
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
13
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
14 Octave is distributed in the hope that it will be useful, but WITHOUT
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
17 for more details.
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
18
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
19 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5972
diff changeset
20 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5972
diff changeset
21 <http://www.gnu.org/licenses/>.
3
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
22
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
23 */
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
24
2828
92826d6e8bd9 [project @ 1997-03-25 23:41:41 by jwe]
jwe
parents: 2811
diff changeset
25 #if !defined (octave_mx_inlines_h)
92826d6e8bd9 [project @ 1997-03-25 23:41:41 by jwe]
jwe
parents: 2811
diff changeset
26 #define octave_mx_inlines_h 1
2804
eedc2f3f61f7 [project @ 1997-03-11 04:34:50 by jwe]
jwe
parents: 2386
diff changeset
27
eedc2f3f61f7 [project @ 1997-03-11 04:34:50 by jwe]
jwe
parents: 2386
diff changeset
28 #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
29 #include <cmath>
10146
9597eea7fa36 inline xmin/xmax & optimize special cases
Jaroslav Hajek <highegg@gmail.com>
parents: 9827
diff changeset
30 #include <memory>
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"
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
37 #include "Array.h"
10146
9597eea7fa36 inline xmin/xmax & optimize special cases
Jaroslav Hajek <highegg@gmail.com>
parents: 9827
diff changeset
38 #include "Array-util.h"
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
39
13004
d9d65c3017c3 Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
40 #include "bsxfun.h"
d9d65c3017c3 Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
41
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
42 // Provides some commonly repeated, basic loop templates.
461
00f8b2242a18 [project @ 1994-06-06 00:45:57 by jwe]
jwe
parents: 238
diff changeset
43
8380
dbe67764e628 fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents: 7789
diff changeset
44 template <class R, class S>
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
45 inline void mx_inline_fill (size_t n, R *r, S s) throw ()
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
46 { 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
47
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
48 #define DEFMXUNOP(F, OP) \
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
49 template <class R, class X> \
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
50 inline void F (size_t n, R *r, const X *x) throw () \
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
51 { 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
52
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
53 DEFMXUNOP (mx_inline_uminus, -)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
54
9607
1be3c73ed7b5 reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents: 9578
diff changeset
55 #define DEFMXUNOPEQ(F, OP) \
1be3c73ed7b5 reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents: 9578
diff changeset
56 template <class R> \
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
57 inline void F (size_t n, R *r) throw () \
9607
1be3c73ed7b5 reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents: 9578
diff changeset
58 { 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
59
1be3c73ed7b5 reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents: 9578
diff changeset
60 DEFMXUNOPEQ (mx_inline_uminus2, -)
1be3c73ed7b5 reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents: 9578
diff changeset
61
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
62 #define DEFMXUNBOOLOP(F, OP) \
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
63 template <class X> \
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
64 inline void F (size_t n, bool *r, const X *x) throw () \
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
65 { const X zero = X (); for (size_t i = 0; i < n; i++) r[i] = x[i] OP zero; }
9550
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 DEFMXUNBOOLOP (mx_inline_iszero, ==)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
68 DEFMXUNBOOLOP (mx_inline_notzero, !=)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
69
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
70 #define DEFMXBINOP(F, OP) \
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
71 template <class R, class X, class Y> \
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
72 inline void F (size_t n, R *r, const X *x, const Y *y) throw () \
9550
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[i]; } \
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
74 template <class R, class X, class Y> \
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
75 inline void F (size_t n, R *r, const X *x, Y y) throw () \
9550
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[i] OP y; } \
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
77 template <class R, class X, class Y> \
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
78 inline void F (size_t n, R *r, X x, const Y *y) throw () \
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
79 { 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
80
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
81 DEFMXBINOP (mx_inline_add, +)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
82 DEFMXBINOP (mx_inline_sub, -)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
83 DEFMXBINOP (mx_inline_mul, *)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
84 DEFMXBINOP (mx_inline_div, /)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
85
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
86 #define DEFMXBINOPEQ(F, OP) \
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
87 template <class R, class X> \
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
88 inline void F (size_t n, R *r, const X *x) throw () \
9550
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[i]; } \
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
90 template <class R, class X> \
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
91 inline void F (size_t n, R *r, X x) throw () \
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
92 { 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
93
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
94 DEFMXBINOPEQ (mx_inline_add2, +=)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
95 DEFMXBINOPEQ (mx_inline_sub2, -=)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
96 DEFMXBINOPEQ (mx_inline_mul2, *=)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
97 DEFMXBINOPEQ (mx_inline_div2, /=)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
98
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
99 #define DEFMXCMPOP(F, OP) \
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
100 template <class X, class Y> \
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
101 inline void F (size_t n, bool *r, const X *x, const Y *y) throw () \
9550
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[i]; } \
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
103 template <class X, class Y> \
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
104 inline void F (size_t n, bool *r, const X *x, Y y) throw () \
9550
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[i] OP y; } \
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
106 template <class X, class Y> \
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
107 inline void F (size_t n, bool *r, X x, const Y *y) throw () \
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
108 { 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
109
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
110 DEFMXCMPOP (mx_inline_lt, <)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
111 DEFMXCMPOP (mx_inline_le, <=)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
112 DEFMXCMPOP (mx_inline_gt, >)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
113 DEFMXCMPOP (mx_inline_ge, >=)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
114 DEFMXCMPOP (mx_inline_eq, ==)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
115 DEFMXCMPOP (mx_inline_ne, !=)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
116
9553
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
117 // Convert to logical value, for logical op purposes.
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
118 template <class T> inline bool logical_value (T x) { return x; }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
119 template <class T> inline bool logical_value (const std::complex<T>& x)
10482
2645a6b1027b fix typo in last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 10481
diff changeset
120 { return x.real () != 0 || x.imag () != 0; }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
121 template <class T> inline bool logical_value (const octave_int<T>& x)
9553
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
122 { return x.value (); }
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
123
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
124 template <class X>
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
125 void mx_inline_not (size_t n, bool *r, const X* x) throw ()
9553
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
126 {
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
127 for (size_t i = 0; i < n; i++)
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
128 r[i] = ! logical_value (x[i]);
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
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
131 inline void mx_inline_not2 (size_t n, bool *r) throw ()
9607
1be3c73ed7b5 reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents: 9578
diff changeset
132 {
1be3c73ed7b5 reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents: 9578
diff changeset
133 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
134 }
1be3c73ed7b5 reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents: 9578
diff changeset
135
9553
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
136 #define DEFMXBOOLOP(F, NOT1, OP, NOT2) \
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
137 template <class X, class Y> \
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
138 inline void F (size_t n, bool *r, const X *x, const Y *y) throw () \
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
139 { \
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
140 for (size_t i = 0; i < n; i++) \
9553
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
141 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
142 } \
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
143 template <class X, class Y> \
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
144 inline void F (size_t n, bool *r, const X *x, Y y) throw () \
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
145 { \
9553
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
146 const bool yy = (NOT2 logical_value (y)); \
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
147 for (size_t i = 0; i < n; i++) \
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
148 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
149 } \
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
150 template <class X, class Y> \
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
151 inline void F (size_t n, bool *r, X x, const Y *y) throw () \
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
152 { \
9553
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
153 const bool xx = (NOT1 logical_value (x)); \
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
154 for (size_t i = 0; i < n; i++) \
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
155 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
156 }
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
157
9553
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
158 DEFMXBOOLOP (mx_inline_and, , &, )
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
159 DEFMXBOOLOP (mx_inline_or, , |, )
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
160 DEFMXBOOLOP (mx_inline_not_and, !, &, )
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
161 DEFMXBOOLOP (mx_inline_not_or, !, |, )
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
162 DEFMXBOOLOP (mx_inline_and_not, , &, !)
0c72d9284087 further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
163 DEFMXBOOLOP (mx_inline_or_not, , |, !)
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
164
9612
66970dd627f6 further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9607
diff changeset
165 #define DEFMXBOOLOPEQ(F, OP) \
66970dd627f6 further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9607
diff changeset
166 template <class X> \
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
167 inline void F (size_t n, bool *r, const X *x) throw () \
9612
66970dd627f6 further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9607
diff changeset
168 { \
66970dd627f6 further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9607
diff changeset
169 for (size_t i = 0; i < n; i++) \
66970dd627f6 further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9607
diff changeset
170 r[i] OP logical_value (x[i]); \
66970dd627f6 further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9607
diff changeset
171 } \
13139
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13005
diff changeset
172 template <class X> \
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13005
diff changeset
173 inline void F (size_t n, bool *r, X x) throw () \
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13005
diff changeset
174 { for (size_t i = 0; i < n; i++) r[i] OP x; }
9612
66970dd627f6 further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9607
diff changeset
175
66970dd627f6 further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9607
diff changeset
176 DEFMXBOOLOPEQ (mx_inline_and2, &=)
66970dd627f6 further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9607
diff changeset
177 DEFMXBOOLOPEQ (mx_inline_or2, |=)
66970dd627f6 further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9607
diff changeset
178
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
179 template <class T>
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
180 inline bool
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
181 mx_inline_any_nan (size_t n, const T* x) throw ()
9814
2b29f3472e20 add a couple of useful loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
182 {
2b29f3472e20 add a couple of useful loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
183 for (size_t i = 0; i < n; i++)
2b29f3472e20 add a couple of useful loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
184 {
2b29f3472e20 add a couple of useful loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
185 if (xisnan (x[i]))
2b29f3472e20 add a couple of useful loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
186 return true;
2b29f3472e20 add a couple of useful loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
187 }
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
188
9814
2b29f3472e20 add a couple of useful loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
189 return false;
8380
dbe67764e628 fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents: 7789
diff changeset
190 }
dbe67764e628 fix & improve speed of diagonal matrix multiplication
Jaroslav Hajek <highegg@gmail.com>
parents: 7789
diff changeset
191
10900
b64803a8be4e optimize element-wise sparse-dense multiplication and division
Jaroslav Hajek <highegg@gmail.com>
parents: 10643
diff changeset
192 template <class T>
b64803a8be4e optimize element-wise sparse-dense multiplication and division
Jaroslav Hajek <highegg@gmail.com>
parents: 10643
diff changeset
193 inline bool
b64803a8be4e optimize element-wise sparse-dense multiplication and division
Jaroslav Hajek <highegg@gmail.com>
parents: 10643
diff changeset
194 mx_inline_all_finite (size_t n, const T* x) throw ()
b64803a8be4e optimize element-wise sparse-dense multiplication and division
Jaroslav Hajek <highegg@gmail.com>
parents: 10643
diff changeset
195 {
b64803a8be4e optimize element-wise sparse-dense multiplication and division
Jaroslav Hajek <highegg@gmail.com>
parents: 10643
diff changeset
196 for (size_t i = 0; i < n; i++)
b64803a8be4e optimize element-wise sparse-dense multiplication and division
Jaroslav Hajek <highegg@gmail.com>
parents: 10643
diff changeset
197 {
b64803a8be4e optimize element-wise sparse-dense multiplication and division
Jaroslav Hajek <highegg@gmail.com>
parents: 10643
diff changeset
198 if (! xfinite (x[i]))
b64803a8be4e optimize element-wise sparse-dense multiplication and division
Jaroslav Hajek <highegg@gmail.com>
parents: 10643
diff changeset
199 return false;
b64803a8be4e optimize element-wise sparse-dense multiplication and division
Jaroslav Hajek <highegg@gmail.com>
parents: 10643
diff changeset
200 }
b64803a8be4e optimize element-wise sparse-dense multiplication and division
Jaroslav Hajek <highegg@gmail.com>
parents: 10643
diff changeset
201
b64803a8be4e optimize element-wise sparse-dense multiplication and division
Jaroslav Hajek <highegg@gmail.com>
parents: 10643
diff changeset
202 return true;
b64803a8be4e optimize element-wise sparse-dense multiplication and division
Jaroslav Hajek <highegg@gmail.com>
parents: 10643
diff changeset
203 }
b64803a8be4e optimize element-wise sparse-dense multiplication and division
Jaroslav Hajek <highegg@gmail.com>
parents: 10643
diff changeset
204
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
205 template <class T>
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
206 inline bool
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
207 mx_inline_any_negative (size_t n, const T* x) throw ()
9827
c15a5ed0da58 optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents: 9814
diff changeset
208 {
c15a5ed0da58 optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents: 9814
diff changeset
209 for (size_t i = 0; i < n; i++)
c15a5ed0da58 optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents: 9814
diff changeset
210 {
c15a5ed0da58 optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents: 9814
diff changeset
211 if (x[i] < 0)
c15a5ed0da58 optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents: 9814
diff changeset
212 return true;
c15a5ed0da58 optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents: 9814
diff changeset
213 }
c15a5ed0da58 optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents: 9814
diff changeset
214
c15a5ed0da58 optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents: 9814
diff changeset
215 return false;
c15a5ed0da58 optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents: 9814
diff changeset
216 }
c15a5ed0da58 optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents: 9814
diff changeset
217
13756
6dfebfa334cb allow negative data log plots with OpenGL+FLTK graphics (bug #34232)
John W. Eaton <jwe@octave.org>
parents: 13139
diff changeset
218 template <class T>
6dfebfa334cb allow negative data log plots with OpenGL+FLTK graphics (bug #34232)
John W. Eaton <jwe@octave.org>
parents: 13139
diff changeset
219 inline bool
6dfebfa334cb allow negative data log plots with OpenGL+FLTK graphics (bug #34232)
John W. Eaton <jwe@octave.org>
parents: 13139
diff changeset
220 mx_inline_any_positive (size_t n, const T* x) throw ()
6dfebfa334cb allow negative data log plots with OpenGL+FLTK graphics (bug #34232)
John W. Eaton <jwe@octave.org>
parents: 13139
diff changeset
221 {
6dfebfa334cb allow negative data log plots with OpenGL+FLTK graphics (bug #34232)
John W. Eaton <jwe@octave.org>
parents: 13139
diff changeset
222 for (size_t i = 0; i < n; i++)
6dfebfa334cb allow negative data log plots with OpenGL+FLTK graphics (bug #34232)
John W. Eaton <jwe@octave.org>
parents: 13139
diff changeset
223 {
6dfebfa334cb allow negative data log plots with OpenGL+FLTK graphics (bug #34232)
John W. Eaton <jwe@octave.org>
parents: 13139
diff changeset
224 if (x[i] > 0)
6dfebfa334cb allow negative data log plots with OpenGL+FLTK graphics (bug #34232)
John W. Eaton <jwe@octave.org>
parents: 13139
diff changeset
225 return true;
6dfebfa334cb allow negative data log plots with OpenGL+FLTK graphics (bug #34232)
John W. Eaton <jwe@octave.org>
parents: 13139
diff changeset
226 }
6dfebfa334cb allow negative data log plots with OpenGL+FLTK graphics (bug #34232)
John W. Eaton <jwe@octave.org>
parents: 13139
diff changeset
227
6dfebfa334cb allow negative data log plots with OpenGL+FLTK graphics (bug #34232)
John W. Eaton <jwe@octave.org>
parents: 13139
diff changeset
228 return false;
6dfebfa334cb allow negative data log plots with OpenGL+FLTK graphics (bug #34232)
John W. Eaton <jwe@octave.org>
parents: 13139
diff changeset
229 }
6dfebfa334cb allow negative data log plots with OpenGL+FLTK graphics (bug #34232)
John W. Eaton <jwe@octave.org>
parents: 13139
diff changeset
230
9814
2b29f3472e20 add a couple of useful loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
231 template<class T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
232 inline bool
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
233 mx_inline_all_real (size_t n, const std::complex<T>* x) throw ()
9814
2b29f3472e20 add a couple of useful loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
234 {
2b29f3472e20 add a couple of useful loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
235 for (size_t i = 0; i < n; i++)
2b29f3472e20 add a couple of useful loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
236 {
2b29f3472e20 add a couple of useful loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
237 if (x[i].imag () != 0)
2b29f3472e20 add a couple of useful loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
238 return false;
2b29f3472e20 add a couple of useful loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
239 }
2b29f3472e20 add a couple of useful loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
240
2b29f3472e20 add a couple of useful loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
241 return true;
2b29f3472e20 add a couple of useful loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9800
diff changeset
242 }
2811
1dd37f97364a [project @ 1997-03-12 23:06:13 by jwe]
jwe
parents: 2804
diff changeset
243
9800
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
244 #define DEFMXMAPPER(F, FUN) \
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
245 template <class T> \
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
246 inline void F (size_t n, T *r, const T *x) throw () \
9800
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
247 { 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
248
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
249 template<class T>
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
250 inline void mx_inline_real (size_t n, T *r, const std::complex<T>* x) throw ()
9800
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
251 { 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
252 template<class T>
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
253 inline void mx_inline_imag (size_t n, T *r, const std::complex<T>* x) throw ()
9800
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
254 { 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
255
9743
26abff55f6fe optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents: 9721
diff changeset
256 // Pairwise minimums/maximums
9800
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
257 #define DEFMXMAPPER2(F, FUN) \
9743
26abff55f6fe optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents: 9721
diff changeset
258 template <class T> \
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
259 inline void F (size_t n, T *r, const T *x, const T *y) throw () \
9743
26abff55f6fe optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents: 9721
diff changeset
260 { 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
261 template <class T> \
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
262 inline void F (size_t n, T *r, const T *x, T y) throw () \
9743
26abff55f6fe optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents: 9721
diff changeset
263 { 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
264 template <class T> \
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
265 inline void F (size_t n, T *r, T x, const T *y) throw () \
9743
26abff55f6fe optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents: 9721
diff changeset
266 { 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
267
9800
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
268 DEFMXMAPPER2 (mx_inline_xmin, xmin)
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
269 DEFMXMAPPER2 (mx_inline_xmax, xmax)
2811
1dd37f97364a [project @ 1997-03-12 23:06:13 by jwe]
jwe
parents: 2804
diff changeset
270
10146
9597eea7fa36 inline xmin/xmax & optimize special cases
Jaroslav Hajek <highegg@gmail.com>
parents: 9827
diff changeset
271 // Specialize array-scalar max/min
9597eea7fa36 inline xmin/xmax & optimize special cases
Jaroslav Hajek <highegg@gmail.com>
parents: 9827
diff changeset
272 #define DEFMINMAXSPEC(T, F, OP) \
9597eea7fa36 inline xmin/xmax & optimize special cases
Jaroslav Hajek <highegg@gmail.com>
parents: 9827
diff changeset
273 template <> \
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
274 inline void F<T> (size_t n, T *r, const T *x, T y) throw () \
10146
9597eea7fa36 inline xmin/xmax & optimize special cases
Jaroslav Hajek <highegg@gmail.com>
parents: 9827
diff changeset
275 { \
9597eea7fa36 inline xmin/xmax & optimize special cases
Jaroslav Hajek <highegg@gmail.com>
parents: 9827
diff changeset
276 if (xisnan (y)) \
9597eea7fa36 inline xmin/xmax & optimize special cases
Jaroslav Hajek <highegg@gmail.com>
parents: 9827
diff changeset
277 std::memcpy (r, x, n * sizeof (T)); \
9597eea7fa36 inline xmin/xmax & optimize special cases
Jaroslav Hajek <highegg@gmail.com>
parents: 9827
diff changeset
278 else \
9597eea7fa36 inline xmin/xmax & optimize special cases
Jaroslav Hajek <highegg@gmail.com>
parents: 9827
diff changeset
279 for (size_t i = 0; i < n; i++) r[i] = (x[i] OP y) ? x[i] : y; \
9597eea7fa36 inline xmin/xmax & optimize special cases
Jaroslav Hajek <highegg@gmail.com>
parents: 9827
diff changeset
280 } \
9597eea7fa36 inline xmin/xmax & optimize special cases
Jaroslav Hajek <highegg@gmail.com>
parents: 9827
diff changeset
281 template <> \
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
282 inline void F<T> (size_t n, T *r, T x, const T *y) throw () \
10146
9597eea7fa36 inline xmin/xmax & optimize special cases
Jaroslav Hajek <highegg@gmail.com>
parents: 9827
diff changeset
283 { \
9597eea7fa36 inline xmin/xmax & optimize special cases
Jaroslav Hajek <highegg@gmail.com>
parents: 9827
diff changeset
284 if (xisnan (x)) \
9597eea7fa36 inline xmin/xmax & optimize special cases
Jaroslav Hajek <highegg@gmail.com>
parents: 9827
diff changeset
285 std::memcpy (r, y, n * sizeof (T)); \
9597eea7fa36 inline xmin/xmax & optimize special cases
Jaroslav Hajek <highegg@gmail.com>
parents: 9827
diff changeset
286 else \
9597eea7fa36 inline xmin/xmax & optimize special cases
Jaroslav Hajek <highegg@gmail.com>
parents: 9827
diff changeset
287 for (size_t i = 0; i < n; i++) r[i] = (y[i] OP x) ? y[i] : x; \
9597eea7fa36 inline xmin/xmax & optimize special cases
Jaroslav Hajek <highegg@gmail.com>
parents: 9827
diff changeset
288 }
9597eea7fa36 inline xmin/xmax & optimize special cases
Jaroslav Hajek <highegg@gmail.com>
parents: 9827
diff changeset
289
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
290 DEFMINMAXSPEC (double, mx_inline_xmin, <=)
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
291 DEFMINMAXSPEC (double, mx_inline_xmax, >=)
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
292 DEFMINMAXSPEC (float, mx_inline_xmin, <=)
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
293 DEFMINMAXSPEC (float, mx_inline_xmax, >=)
10146
9597eea7fa36 inline xmin/xmax & optimize special cases
Jaroslav Hajek <highegg@gmail.com>
parents: 9827
diff changeset
294
9827
c15a5ed0da58 optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents: 9814
diff changeset
295 // Pairwise power
c15a5ed0da58 optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents: 9814
diff changeset
296 #define DEFMXMAPPER2X(F, FUN) \
c15a5ed0da58 optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents: 9814
diff changeset
297 template <class R, class X, class Y> \
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
298 inline void F (size_t n, R *r, const X *x, const Y *y) throw () \
9827
c15a5ed0da58 optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents: 9814
diff changeset
299 { for (size_t i = 0; i < n; i++) r[i] = FUN (x[i], y[i]); } \
c15a5ed0da58 optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents: 9814
diff changeset
300 template <class R, class X, class Y> \
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
301 inline void F (size_t n, R *r, const X *x, Y y) throw () \
9827
c15a5ed0da58 optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents: 9814
diff changeset
302 { for (size_t i = 0; i < n; i++) r[i] = FUN (x[i], y); } \
c15a5ed0da58 optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents: 9814
diff changeset
303 template <class R, class X, class Y> \
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
304 inline void F (size_t n, R *r, X x, const Y *y) throw () \
9827
c15a5ed0da58 optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents: 9814
diff changeset
305 { for (size_t i = 0; i < n; i++) r[i] = FUN (x, y[i]); }
c15a5ed0da58 optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents: 9814
diff changeset
306
13005
4061106b1c4b Enable automatic bsxfun for power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 13004
diff changeset
307 // Let the compiler decide which pow to use, whichever best matches the
4061106b1c4b Enable automatic bsxfun for power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 13004
diff changeset
308 // arguments provided.
4061106b1c4b Enable automatic bsxfun for power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 13004
diff changeset
309 using std::pow;
4061106b1c4b Enable automatic bsxfun for power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 13004
diff changeset
310 DEFMXMAPPER2X (mx_inline_pow, pow)
9827
c15a5ed0da58 optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents: 9814
diff changeset
311
9800
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
312 // 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
313 // inlining.
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
314 template <class R, class X, R fun (X x)>
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
315 inline void mx_inline_map (size_t n, R *r, const X *x) throw ()
9800
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
316 { 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
317
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
318 template <class R, class X, R fun (const X& x)>
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
319 inline void mx_inline_map (size_t n, R *r, const X *x) throw ()
9800
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
320 { 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
321
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
322 // 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
323 // 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
324
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
325 template <class R, class X>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
326 inline Array<R>
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
327 do_mx_unary_op (const Array<X>& x,
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
328 void (*op) (size_t, R *, const X *) throw ())
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
329 {
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
330 Array<R> r (x.dims ());
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
331 op (r.numel (), r.fortran_vec (), x.data ());
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
332 return r;
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
333 }
2811
1dd37f97364a [project @ 1997-03-12 23:06:13 by jwe]
jwe
parents: 2804
diff changeset
334
9800
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
335 // Shortcuts for applying mx_inline_map.
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
336
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
337 template <class R, class X, R fun (X)>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
338 inline Array<R>
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
339 do_mx_unary_map (const Array<X>& x)
9800
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
340 {
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
341 return do_mx_unary_op<R, X> (x, mx_inline_map<R, X, fun>);
9800
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
342 }
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
343
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
344 template <class R, class X, R fun (const X&)>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
345 inline Array<R>
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
346 do_mx_unary_map (const Array<X>& x)
9800
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
347 {
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
348 return do_mx_unary_op<R, X> (x, mx_inline_map<R, X, fun>);
9800
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
349 }
ef4c4186cb47 improve some mx_inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 9766
diff changeset
350
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
351 template <class R>
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
352 inline Array<R>&
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
353 do_mx_inplace_op (Array<R>& r,
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
354 void (*op) (size_t, R *) throw ())
9607
1be3c73ed7b5 reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents: 9578
diff changeset
355 {
1be3c73ed7b5 reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents: 9578
diff changeset
356 op (r.numel (), r.fortran_vec ());
1be3c73ed7b5 reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents: 9578
diff changeset
357 return r;
1be3c73ed7b5 reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents: 9578
diff changeset
358 }
1be3c73ed7b5 reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents: 9578
diff changeset
359
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
360 template <class R, class X, class Y>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
361 inline Array<R>
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
362 do_mm_binary_op (const Array<X>& x, const Array<Y>& y,
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
363 void (*op) (size_t, R *, const X *, const Y *) throw (),
13004
d9d65c3017c3 Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
364 void (*op1) (size_t, R *, X, const Y *) throw (),
d9d65c3017c3 Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
365 void (*op2) (size_t, R *, const X *, Y) throw (),
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
366 const char *opname)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
367 {
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17769
diff changeset
368 dim_vector dx = x.dims ();
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17769
diff changeset
369 dim_vector dy = y.dims ();
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
370 if (dx == dy)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
371 {
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
372 Array<R> r (dx);
9612
66970dd627f6 further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9607
diff changeset
373 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
374 return r;
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
375 }
14056
c3d401562410 allow warning (or error) for automatic bsxfun
John W. Eaton <jwe@octave.org>
parents: 13756
diff changeset
376 else if (is_valid_bsxfun (opname, dx, dy))
13004
d9d65c3017c3 Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
377 {
d9d65c3017c3 Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
378 return do_bsxfun_op (x, y, op, op1, op2);
d9d65c3017c3 Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
379 }
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
380 else
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
381 {
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
382 gripe_nonconformant (opname, dx, dy);
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
383 return Array<R> ();
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
384 }
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
385 }
3
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
386
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
387 template <class R, class X, class Y>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
388 inline Array<R>
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
389 do_ms_binary_op (const Array<X>& x, const Y& y,
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
390 void (*op) (size_t, R *, const X *, Y) throw ())
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
391 {
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
392 Array<R> r (x.dims ());
9612
66970dd627f6 further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9607
diff changeset
393 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
394 return r;
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
395 }
3
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
396
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
397 template <class R, class X, class Y>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
398 inline Array<R>
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
399 do_sm_binary_op (const X& x, const Array<Y>& y,
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
400 void (*op) (size_t, R *, X, const Y *) throw ())
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
401 {
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
402 Array<R> r (y.dims ());
9612
66970dd627f6 further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9607
diff changeset
403 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
404 return r;
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
405 }
3
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
406
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
407 template <class R, class X>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
408 inline Array<R>&
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
409 do_mm_inplace_op (Array<R>& r, const Array<X>& x,
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
410 void (*op) (size_t, R *, const X *) throw (),
13139
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13005
diff changeset
411 void (*op1) (size_t, R *, X) throw (),
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
412 const char *opname)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
413 {
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17769
diff changeset
414 dim_vector dr = r.dims ();
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17769
diff changeset
415 dim_vector dx = x.dims ();
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
416 if (dr == dx)
13139
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13005
diff changeset
417 {
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13005
diff changeset
418 op (r.length (), r.fortran_vec (), x.data ());
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13005
diff changeset
419 }
14056
c3d401562410 allow warning (or error) for automatic bsxfun
John W. Eaton <jwe@octave.org>
parents: 13756
diff changeset
420 else if (is_valid_inplace_bsxfun (opname, dr, dx))
13139
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13005
diff changeset
421 {
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13005
diff changeset
422 do_inplace_bsxfun_op (r, x, op, op1);
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13005
diff changeset
423 }
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
424 else
9612
66970dd627f6 further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9607
diff changeset
425 gripe_nonconformant (opname, dr, dx);
66970dd627f6 further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9607
diff changeset
426 return r;
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
427 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
428
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
429 template <class R, class X>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
430 inline Array<R>&
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
431 do_ms_inplace_op (Array<R>& r, const X& x,
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
432 void (*op) (size_t, R *, X) throw ())
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
433 {
9612
66970dd627f6 further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9607
diff changeset
434 op (r.length (), r.fortran_vec (), x);
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
435 return r;
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
436 }
3
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
437
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
438 template <class T1, class T2>
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
439 inline bool
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
440 mx_inline_equal (size_t n, const T1 *x, const T2 *y) throw ()
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
441 {
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
442 for (size_t i = 0; i < n; i++)
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
443 if (x[i] != y[i])
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
444 return false;
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
445 return true;
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
446 }
3
9a4c07481e61 [project @ 1993-08-08 01:20:23 by jwe]
jwe
parents:
diff changeset
447
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
448 template <class T>
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
449 inline bool
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
450 do_mx_check (const Array<T>& a,
10481
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
451 bool (*op) (size_t, const T *) throw ())
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
452 {
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
453 return op (a.numel (), a.data ());
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
454 }
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
455
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
456 // NOTE: we don't use std::norm because it typically does some heavyweight
e8811e5dd699 avoid exception throwing in mx-inline loops
Jaroslav Hajek <highegg@gmail.com>
parents: 10365
diff changeset
457 // magic to avoid underflows, which we don't need here.
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
458 template <class T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
459 inline T cabsq (const std::complex<T>& c)
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
460 { return c.real () * c.real () + c.imag () * c.imag (); }
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
461
8743
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
462 // default. works for integers and bool.
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
463 template <class T>
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
464 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
465 template <class T>
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
466 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
467 // for octave_ints
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
468 template <class T>
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
469 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
470 template <class T>
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
471 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
472 // 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
473 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
474 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
475 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
476 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
477 // Ditto for complex.
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
478 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
479 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
480 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
481 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
482
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
483 #define OP_RED_SUM(ac, el) ac += el
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
484 #define OP_RED_PROD(ac, el) ac *= el
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9513
diff changeset
485 #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
486 #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
487
18759
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18098
diff changeset
488 inline void op_dble_prod (double& ac, float el)
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18098
diff changeset
489 { ac *= el; }
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18098
diff changeset
490 inline void op_dble_prod (Complex& ac, const FloatComplex& el)
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18098
diff changeset
491 { ac *= el; } // FIXME: guaranteed?
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18098
diff changeset
492 template <class T>
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18098
diff changeset
493 inline void op_dble_prod (double& ac, const octave_int<T>& el)
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18098
diff changeset
494 { ac *= el.double_value (); }
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18098
diff changeset
495
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
496 inline void op_dble_sum (double& ac, float el)
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
497 { ac += el; }
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
498 inline void op_dble_sum (Complex& ac, const FloatComplex& el)
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
499 { ac += el; } // FIXME: guaranteed?
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
500 template <class T>
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
501 inline void op_dble_sum (double& ac, const octave_int<T>& el)
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
502 { ac += el.double_value (); }
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
503
8743
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
504 // 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
505 #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
506 #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
507
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
508 #define OP_RED_FCN(F, TSRC, TRES, OP, ZERO) \
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
509 template <class T> \
8743
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
510 inline TRES \
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
511 F (const TSRC* v, octave_idx_type n) \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
512 { \
8743
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
513 TRES ac = ZERO; \
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
514 for (octave_idx_type i = 0; i < n; i++) \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
515 OP(ac, v[i]); \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
516 return ac; \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
517 }
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
518
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
519 #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
520
8743
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
521 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
522 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
523 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
524 OP_RED_FCN (mx_inline_prod, T, T, OP_RED_PROD, 1)
18759
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18098
diff changeset
525 OP_RED_FCN (mx_inline_dprod, T, PROMOTE_DOUBLE(T), op_dble_prod, 1)
8743
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
526 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
527 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
528 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
529 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
530
8743
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
531
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
532 #define OP_RED_FCN2(F, TSRC, TRES, OP, ZERO) \
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
533 template <class T> \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
534 inline void \
8743
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
535 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
536 { \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
537 for (octave_idx_type i = 0; i < m; i++) \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
538 r[i] = ZERO; \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
539 for (octave_idx_type j = 0; j < n; j++) \
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 for (octave_idx_type i = 0; i < m; i++) \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
542 OP(r[i], v[i]); \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
543 v += m; \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
544 } \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
545 }
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
546
8743
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
547 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
548 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
549 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
550 OP_RED_FCN2 (mx_inline_prod, T, T, OP_RED_PROD, 1)
18759
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18098
diff changeset
551 OP_RED_FCN2 (mx_inline_dprod, T, PROMOTE_DOUBLE(T), op_dble_prod, 0.0)
8743
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
552 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
553 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
554
10147
adc0143e9419 optimize any/all (x, 2) with small number of rows
Jaroslav Hajek <highegg@gmail.com>
parents: 10146
diff changeset
555 #define OP_RED_ANYR(ac, el) ac |= xis_true (el)
adc0143e9419 optimize any/all (x, 2) with small number of rows
Jaroslav Hajek <highegg@gmail.com>
parents: 10146
diff changeset
556 #define OP_RED_ALLR(ac, el) ac &= xis_true (el)
adc0143e9419 optimize any/all (x, 2) with small number of rows
Jaroslav Hajek <highegg@gmail.com>
parents: 10146
diff changeset
557
adc0143e9419 optimize any/all (x, 2) with small number of rows
Jaroslav Hajek <highegg@gmail.com>
parents: 10146
diff changeset
558 OP_RED_FCN2 (mx_inline_any_r, T, bool, OP_RED_ANYR, false)
adc0143e9419 optimize any/all (x, 2) with small number of rows
Jaroslav Hajek <highegg@gmail.com>
parents: 10146
diff changeset
559 OP_RED_FCN2 (mx_inline_all_r, T, bool, OP_RED_ALLR, true)
adc0143e9419 optimize any/all (x, 2) with small number of rows
Jaroslav Hajek <highegg@gmail.com>
parents: 10146
diff changeset
560
8758
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
561 // 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
562 // 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
563 // 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
564
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
565 #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
566 template <class T> \
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
567 inline void \
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
568 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
569 { \
10147
adc0143e9419 optimize any/all (x, 2) with small number of rows
Jaroslav Hajek <highegg@gmail.com>
parents: 10146
diff changeset
570 if (n <= 8) \
adc0143e9419 optimize any/all (x, 2) with small number of rows
Jaroslav Hajek <highegg@gmail.com>
parents: 10146
diff changeset
571 return F ## _r (v, r, m, n); \
adc0143e9419 optimize any/all (x, 2) with small number of rows
Jaroslav Hajek <highegg@gmail.com>
parents: 10146
diff changeset
572 \
8758
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
573 /* 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
574 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
575 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
576 octave_idx_type nact = m; \
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
577 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
578 { \
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
579 octave_idx_type k = 0; \
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
580 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
581 { \
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
582 octave_idx_type ia = iact[i]; \
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
583 if (! PRED (v[ia])) \
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
584 iact[k++] = ia; \
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
585 } \
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
586 nact = k; \
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
587 v += m; \
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
588 } \
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
589 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
590 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
591 }
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
592
83c9d60c3c47 implement short-circuiting row-reduction any/all algorithm
Jaroslav Hajek <highegg@gmail.com>
parents: 8756
diff changeset
593 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
594 OP_ROW_SHORT_CIRCUIT (mx_inline_all, xis_false, true)
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
595
8743
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
596 #define OP_RED_FCNN(F, TSRC, TRES) \
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
597 template <class T> \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
598 inline void \
8743
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
599 F (const TSRC *v, TRES *r, octave_idx_type l, \
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
600 octave_idx_type n, octave_idx_type u) \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
601 { \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
602 if (l == 1) \
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 for (octave_idx_type i = 0; i < u; i++) \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
605 { \
8756
d0755c9db5ed implement fast logical sum (counting)
Jaroslav Hajek <highegg@gmail.com>
parents: 8751
diff changeset
606 r[i] = F<T> (v, n); \
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
607 v += n; \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
608 } \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
609 } \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
610 else \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
611 { \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
612 for (octave_idx_type i = 0; i < u; i++) \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
613 { \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
614 F (v, r, l, n); \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
615 v += l*n; \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
616 r += l; \
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 } \
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
8743
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
621 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
622 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
623 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
624 OP_RED_FCNN (mx_inline_prod, T, T)
18759
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18098
diff changeset
625 OP_RED_FCNN (mx_inline_dprod, T, PROMOTE_DOUBLE(T))
8743
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
626 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
627 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
628 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
629 OP_RED_FCNN (mx_inline_all, T, bool)
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
630
8780
ea76466605ba support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents: 8777
diff changeset
631 #define OP_CUM_FCN(F, TSRC, TRES, OP) \
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
632 template <class T> \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
633 inline void \
8780
ea76466605ba support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents: 8777
diff changeset
634 F (const TSRC *v, TRES *r, octave_idx_type n) \
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
635 { \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
636 if (n) \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
637 { \
8780
ea76466605ba support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents: 8777
diff changeset
638 TRES t = r[0] = v[0]; \
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
639 for (octave_idx_type i = 1; i < n; i++) \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
640 r[i] = t = t OP v[i]; \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
641 } \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
642 }
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
643
8780
ea76466605ba support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents: 8777
diff changeset
644 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
645 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
646 OP_CUM_FCN (mx_inline_cumcount, bool, T, +)
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
647
8780
ea76466605ba support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents: 8777
diff changeset
648 #define OP_CUM_FCN2(F, TSRC, TRES, OP) \
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
649 template <class T> \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
650 inline void \
8780
ea76466605ba support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents: 8777
diff changeset
651 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
652 { \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
653 if (n) \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
654 { \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
655 for (octave_idx_type i = 0; i < m; i++) \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
656 r[i] = v[i]; \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
657 const T *r0 = r; \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
658 for (octave_idx_type j = 1; j < n; j++) \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
659 { \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
660 r += m; v += m; \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
661 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
662 r[i] = r0[i] OP v[i]; \
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
663 r0 += m; \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
664 } \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
665 } \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
666 }
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
667
8780
ea76466605ba support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents: 8777
diff changeset
668 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
669 OP_CUM_FCN2 (mx_inline_cumprod, T, T, *)
10643
9852264314d1 fix cumulative logical sum
Jaroslav Hajek <highegg@gmail.com>
parents: 10482
diff changeset
670 OP_CUM_FCN2 (mx_inline_cumcount, bool, T, +)
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
671
8780
ea76466605ba support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents: 8777
diff changeset
672 #define OP_CUM_FCNN(F, TSRC, TRES) \
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
673 template <class T> \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
674 inline void \
8780
ea76466605ba support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents: 8777
diff changeset
675 F (const TSRC *v, TRES *r, octave_idx_type l, \
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
676 octave_idx_type n, octave_idx_type u) \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
677 { \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
678 if (l == 1) \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
679 { \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
680 for (octave_idx_type i = 0; i < u; i++) \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
681 { \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
682 F (v, r, n); \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
683 v += n; r += n; \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
684 } \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
685 } \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
686 else \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
687 { \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
688 for (octave_idx_type i = 0; i < u; i++) \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
689 { \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
690 F (v, r, l, n); \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
691 v += l*n; \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
692 r += l*n; \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
693 } \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
694 } \
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
695 }
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
696
8780
ea76466605ba support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents: 8777
diff changeset
697 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
698 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
699 OP_CUM_FCNN (mx_inline_cumcount, bool, T)
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
700
8751
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
701 #define OP_MINMAX_FCN(F, OP) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
702 template <class T> \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
703 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
704 { \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
705 if (! n) return; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
706 T tmp = v[0]; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
707 octave_idx_type i = 1; \
8776
d23c33ec6bd3 fix min/max behaviour with NaNs
Jaroslav Hajek <highegg@gmail.com>
parents: 8759
diff changeset
708 if (xisnan (tmp)) \
d23c33ec6bd3 fix min/max behaviour with NaNs
Jaroslav Hajek <highegg@gmail.com>
parents: 8759
diff changeset
709 { \
d23c33ec6bd3 fix min/max behaviour with NaNs
Jaroslav Hajek <highegg@gmail.com>
parents: 8759
diff changeset
710 for (; i < n && xisnan (v[i]); i++) ; \
d23c33ec6bd3 fix min/max behaviour with NaNs
Jaroslav Hajek <highegg@gmail.com>
parents: 8759
diff changeset
711 if (i < n) tmp = v[i]; \
d23c33ec6bd3 fix min/max behaviour with NaNs
Jaroslav Hajek <highegg@gmail.com>
parents: 8759
diff changeset
712 } \
d23c33ec6bd3 fix min/max behaviour with NaNs
Jaroslav Hajek <highegg@gmail.com>
parents: 8759
diff changeset
713 for (; i < n; i++) \
8751
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
714 if (v[i] OP tmp) tmp = v[i]; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
715 *r = tmp; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
716 } \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
717 template <class T> \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
718 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
719 { \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
720 if (! n) return; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
721 T tmp = v[0]; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
722 octave_idx_type tmpi = 0; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
723 octave_idx_type i = 1; \
8776
d23c33ec6bd3 fix min/max behaviour with NaNs
Jaroslav Hajek <highegg@gmail.com>
parents: 8759
diff changeset
724 if (xisnan (tmp)) \
d23c33ec6bd3 fix min/max behaviour with NaNs
Jaroslav Hajek <highegg@gmail.com>
parents: 8759
diff changeset
725 { \
d23c33ec6bd3 fix min/max behaviour with NaNs
Jaroslav Hajek <highegg@gmail.com>
parents: 8759
diff changeset
726 for (; i < n && xisnan (v[i]); i++) ; \
d23c33ec6bd3 fix min/max behaviour with NaNs
Jaroslav Hajek <highegg@gmail.com>
parents: 8759
diff changeset
727 if (i < n) { tmp = v[i]; tmpi = i; } \
d23c33ec6bd3 fix min/max behaviour with NaNs
Jaroslav Hajek <highegg@gmail.com>
parents: 8759
diff changeset
728 } \
d23c33ec6bd3 fix min/max behaviour with NaNs
Jaroslav Hajek <highegg@gmail.com>
parents: 8759
diff changeset
729 for (; i < n; i++) \
8751
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
730 if (v[i] OP tmp) { tmp = v[i]; tmpi = i; }\
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
731 *r = tmp; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
732 *ri = tmpi; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
733 }
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
734
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
735 OP_MINMAX_FCN (mx_inline_min, <)
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
736 OP_MINMAX_FCN (mx_inline_max, >)
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
737
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
738 // 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
739 // 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
740 // proceed to a faster code.
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
741
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
742 #define OP_MINMAX_FCN2(F, OP) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
743 template <class T> \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
744 inline void \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
745 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
746 { \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
747 if (! n) return; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
748 bool nan = false; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
749 octave_idx_type j = 0; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
750 for (octave_idx_type i = 0; i < m; i++) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
751 { \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
752 r[i] = v[i]; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
753 if (xisnan (v[i])) nan = true; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
754 } \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
755 j++; v += m; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
756 while (nan && j < n) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
757 { \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
758 nan = false; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
759 for (octave_idx_type i = 0; i < m; i++) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
760 { \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
761 if (xisnan (v[i])) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
762 nan = true; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
763 else if (xisnan (r[i]) || v[i] OP r[i]) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
764 r[i] = v[i]; \
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 j++; v += m; \
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 while (j < n) \
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 for (octave_idx_type i = 0; i < m; i++) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
771 if (v[i] OP r[i]) r[i] = v[i]; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
772 j++; v += m; \
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 template <class T> \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
776 inline void \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
777 F (const T *v, T *r, octave_idx_type *ri, \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
778 octave_idx_type m, octave_idx_type n) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
779 { \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
780 if (! n) return; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
781 bool nan = false; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
782 octave_idx_type j = 0; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
783 for (octave_idx_type i = 0; i < m; i++) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
784 { \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
785 r[i] = v[i]; ri[i] = j; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
786 if (xisnan (v[i])) nan = true; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
787 } \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
788 j++; v += m; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
789 while (nan && j < n) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
790 { \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
791 nan = false; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
792 for (octave_idx_type i = 0; i < m; 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 if (xisnan (v[i])) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
795 nan = true; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
796 else if (xisnan (r[i]) || v[i] OP r[i]) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
797 { r[i] = v[i]; ri[i] = j; } \
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 j++; v += m; \
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 while (j < n) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
802 { \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
803 for (octave_idx_type i = 0; i < m; i++) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
804 if (v[i] OP r[i]) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
805 { r[i] = v[i]; ri[i] = j; } \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
806 j++; v += m; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
807 } \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
808 }
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
809
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
810 OP_MINMAX_FCN2 (mx_inline_min, <)
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
811 OP_MINMAX_FCN2 (mx_inline_max, >)
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
812
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
813 #define OP_MINMAX_FCNN(F) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
814 template <class T> \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
815 inline void \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
816 F (const T *v, T *r, octave_idx_type l, \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
817 octave_idx_type n, octave_idx_type u) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
818 { \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
819 if (! n) return; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
820 if (l == 1) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
821 { \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
822 for (octave_idx_type i = 0; i < u; i++) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
823 { \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
824 F (v, r, n); \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
825 v += n; r++; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
826 } \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
827 } \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
828 else \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
829 { \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
830 for (octave_idx_type i = 0; i < u; i++) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
831 { \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
832 F (v, r, l, n); \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
833 v += l*n; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
834 r += l; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
835 } \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
836 } \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
837 } \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
838 template <class T> \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
839 inline void \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
840 F (const T *v, T *r, octave_idx_type *ri, \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
841 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
842 { \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
843 if (! n) return; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
844 if (l == 1) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
845 { \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
846 for (octave_idx_type i = 0; i < u; i++) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
847 { \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
848 F (v, r, ri, n); \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
849 v += n; r++; ri++; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
850 } \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
851 } \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
852 else \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
853 { \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
854 for (octave_idx_type i = 0; i < u; i++) \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
855 { \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
856 F (v, r, ri, l, n); \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
857 v += l*n; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
858 r += l; ri += l; \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
859 } \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
860 } \
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
861 }
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
862
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
863 OP_MINMAX_FCNN (mx_inline_min)
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
864 OP_MINMAX_FCNN (mx_inline_max)
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
865
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
866 #define OP_CUMMINMAX_FCN(F, OP) \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
867 template <class T> \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
868 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
869 { \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
870 if (! n) return; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
871 T tmp = v[0]; \
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17769
diff changeset
872 octave_idx_type i = 1; \
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17769
diff changeset
873 octave_idx_type j = 0; \
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
874 if (xisnan (tmp)) \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
875 { \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
876 for (; i < n && xisnan (v[i]); i++) ; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
877 for (; j < i; j++) r[j] = tmp; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
878 if (i < n) tmp = v[i]; \
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 for (; i < n; i++) \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
881 if (v[i] OP tmp) \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
882 { \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
883 for (; j < i; j++) r[j] = tmp; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
884 tmp = v[i]; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
885 } \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
886 for (; j < i; j++) r[j] = tmp; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
887 } \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
888 template <class T> \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
889 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
890 { \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
891 if (! n) return; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
892 T tmp = v[0]; octave_idx_type tmpi = 0; \
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17769
diff changeset
893 octave_idx_type i = 1; \
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17769
diff changeset
894 octave_idx_type j = 0; \
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
895 if (xisnan (tmp)) \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
896 { \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
897 for (; i < n && xisnan (v[i]); i++) ; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
898 for (; j < i; j++) { r[j] = tmp; ri[j] = tmpi; } \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
899 if (i < n) { tmp = v[i]; tmpi = 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 for (; i < n; i++) \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
902 if (v[i] OP tmp) \
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 for (; j < i; j++) { r[j] = tmp; ri[j] = tmpi; } \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
905 tmp = v[i]; tmpi = i; \
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 for (; j < i; j++) { r[j] = tmp; ri[j] = tmpi; } \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
908 }
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 OP_CUMMINMAX_FCN (mx_inline_cummin, <)
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
911 OP_CUMMINMAX_FCN (mx_inline_cummax, >)
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
912
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
913 // 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
914 // 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
915 // proceed to a faster code.
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 #define OP_CUMMINMAX_FCN2(F, OP) \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
918 template <class T> \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
919 inline void \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
920 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
921 { \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
922 if (! n) return; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
923 bool nan = false; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
924 const T *r0; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
925 octave_idx_type j = 0; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
926 for (octave_idx_type i = 0; i < m; i++) \
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 r[i] = v[i]; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
929 if (xisnan (v[i])) nan = true; \
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 j++; v += m; r0 = r; r += m; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
932 while (nan && j < n) \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
933 { \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
934 nan = false; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
935 for (octave_idx_type i = 0; i < m; i++) \
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 (xisnan (v[i])) \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
938 { r[i] = r0[i]; nan = true; } \
8949
e31d47f2c9bb fixes to row-reducing cummin/cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
939 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
940 r[i] = v[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 j++; v += m; r0 = r; r += m; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
943 } \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
944 while (j < n) \
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 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
947 if (v[i] OP r0[i]) \
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
948 r[i] = v[i]; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
949 else \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
950 r[i] = r0[i]; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
951 j++; v += m; r0 = r; r += m; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
952 } \
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 template <class T> \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
955 inline void \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
956 F (const T *v, T *r, octave_idx_type *ri, \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
957 octave_idx_type m, octave_idx_type n) \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
958 { \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
959 if (! n) return; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
960 bool nan = false; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
961 const T *r0; const octave_idx_type *r0i; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
962 octave_idx_type j = 0; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
963 for (octave_idx_type i = 0; i < m; i++) \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
964 { \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
965 r[i] = v[i]; ri[i] = 0; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
966 if (xisnan (v[i])) nan = true; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
967 } \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
968 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
969 while (nan && j < n) \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
970 { \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
971 nan = false; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
972 for (octave_idx_type i = 0; i < m; 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 if (xisnan (v[i])) \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
975 { 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
976 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
977 { r[i] = v[i]; ri[i] = j; }\
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 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
980 } \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
981 while (j < n) \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
982 { \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
983 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
984 if (v[i] OP r0[i]) \
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
985 { r[i] = v[i]; ri[i] = j; } \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
986 else \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
987 { r[i] = r0[i]; ri[i] = r0i[i]; } \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
988 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
989 } \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
990 }
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
991
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
992 OP_CUMMINMAX_FCN2 (mx_inline_cummin, <)
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
993 OP_CUMMINMAX_FCN2 (mx_inline_cummax, >)
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
994
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
995 #define OP_CUMMINMAX_FCNN(F) \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
996 template <class T> \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
997 inline void \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
998 F (const T *v, T *r, octave_idx_type l, \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
999 octave_idx_type n, octave_idx_type u) \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1000 { \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1001 if (! n) return; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1002 if (l == 1) \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1003 { \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1004 for (octave_idx_type i = 0; i < u; i++) \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1005 { \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1006 F (v, r, n); \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1007 v += n; r += n; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1008 } \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1009 } \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1010 else \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1011 { \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1012 for (octave_idx_type i = 0; i < u; i++) \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1013 { \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1014 F (v, r, l, n); \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1015 v += l*n; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1016 r += l*n; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1017 } \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1018 } \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1019 } \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1020 template <class T> \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1021 inline void \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1022 F (const T *v, T *r, octave_idx_type *ri, \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1023 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
1024 { \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1025 if (! n) return; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1026 if (l == 1) \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1027 { \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1028 for (octave_idx_type i = 0; i < u; i++) \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1029 { \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1030 F (v, r, ri, n); \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1031 v += n; r += n; ri += n; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1032 } \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1033 } \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1034 else \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1035 { \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1036 for (octave_idx_type i = 0; i < u; i++) \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1037 { \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1038 F (v, r, ri, l, n); \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1039 v += l*n; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1040 r += l*n; ri += l*n; \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1041 } \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1042 } \
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1043 }
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1044
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1045 OP_CUMMINMAX_FCNN (mx_inline_cummin)
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1046 OP_CUMMINMAX_FCNN (mx_inline_cummax)
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1047
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1048 template <class T>
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1049 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
1050 octave_idx_type order)
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 switch (order)
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 case 1:
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1055 for (octave_idx_type i = 0; i < n-1; i++)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1056 r[i] = v[i+1] - v[i];
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1057 break;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1058 case 2:
9702
9ecd35a606e3 avoid some warnings from g++
John W. Eaton <jwe@octave.org>
parents: 9612
diff changeset
1059 if (n > 1)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1060 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1061 T lst = v[1] - v[0];
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1062 for (octave_idx_type i = 0; i < n-2; i++)
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 T dif = v[i+2] - v[i+1];
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1065 r[i] = dif - lst;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1066 lst = dif;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1067 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1068 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1069 break;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1070 default:
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1071 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1072 OCTAVE_LOCAL_BUFFER (T, buf, n-1);
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1073
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1074 for (octave_idx_type i = 0; i < n-1; i++)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1075 buf[i] = v[i+1] - v[i];
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1076
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1077 for (octave_idx_type o = 2; o <= order; o++)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1078 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1079 for (octave_idx_type i = 0; i < n-o; i++)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1080 buf[i] = buf[i+1] - buf[i];
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1081 }
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1082
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1083 for (octave_idx_type i = 0; i < n-order; i++)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1084 r[i] = buf[i];
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1085 }
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1086 }
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 template <class T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1090 void mx_inline_diff (const T *v, T *r,
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1091 octave_idx_type m, octave_idx_type n,
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1092 octave_idx_type order)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1093 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1094 switch (order)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1095 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1096 case 1:
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1097 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
1098 r[i] = v[i+m] - v[i];
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1099 break;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1100 case 2:
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1101 for (octave_idx_type i = 0; i < n-2; i++)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1102 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1103 for (octave_idx_type j = i*m; j < i*m+m; j++)
15118
a4e94933fed3 Fix bug #37033 in diff ()
Carlo de Falco <cdf@users.sourceforge.net>
parents: 14138
diff changeset
1104 r[j] = (v[j+m+m] - v[j+m]) - (v[j+m] - v[j]);
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1105 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1106 break;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1107 default:
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1108 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1109 OCTAVE_LOCAL_BUFFER (T, buf, n-1);
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1110
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1111 for (octave_idx_type j = 0; j < m; j++)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1112 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1113 for (octave_idx_type i = 0; i < n-1; i++)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1114 buf[i] = v[i*m+j+m] - v[i*m+j];
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1115
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1116 for (octave_idx_type o = 2; o <= order; o++)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1117 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1118 for (octave_idx_type i = 0; i < n-o; i++)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1119 buf[i] = buf[i+1] - buf[i];
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1120 }
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1121
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1122 for (octave_idx_type i = 0; i < n-order; i++)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1123 r[i*m+j] = buf[i];
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1124 }
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1125 }
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1126 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1127 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1128
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1129 template <class T>
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1130 inline void
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1131 mx_inline_diff (const T *v, T *r,
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1132 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
1133 octave_idx_type order)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1134 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1135 if (! n) return;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1136 if (l == 1)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1137 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1138 for (octave_idx_type i = 0; i < u; i++)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1139 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1140 mx_inline_diff (v, r, n, order);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1141 v += n; r += n-order;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1142 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1143 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1144 else
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1145 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1146 for (octave_idx_type i = 0; i < u; i++)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1147 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1148 mx_inline_diff (v, r, l, n, order);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1149 v += l*n;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1150 r += l*(n-order);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1151 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1152 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1153 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1154
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1155 // Assistant function
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 inline void
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1158 get_extent_triplet (const dim_vector& dims, int& dim,
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1159 octave_idx_type& l, octave_idx_type& n,
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1160 octave_idx_type& u)
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1161 {
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1162 octave_idx_type ndims = dims.length ();
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1163 if (dim >= ndims)
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1164 {
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1165 l = dims.numel ();
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1166 n = 1;
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1167 u = 1;
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1168 }
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1169 else
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1170 {
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1171 if (dim < 0)
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1172 dim = dims.first_non_singleton ();
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1173
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1174 // calculate extent triplet.
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1175 l = 1, n = dims(dim), u = 1;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1176 for (octave_idx_type i = 0; i < dim; i++)
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1177 l *= dims (i);
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1178 for (octave_idx_type i = dim + 1; i < ndims; i++)
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1179 u *= dims (i);
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1180 }
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1181 }
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1182
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1183 // Appliers.
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1184 // 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
1185 // maybe it can be done without an explicit parameter?
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1186
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1187 template <class R, class T>
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1188 inline Array<R>
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1189 do_mx_red_op (const Array<T>& src, int dim,
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1190 void (*mx_red_op) (const T *, R *, octave_idx_type,
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1191 octave_idx_type, octave_idx_type))
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1192 {
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1193 octave_idx_type l, n, u;
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1194 dim_vector dims = src.dims ();
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
1195 // M*b inconsistency: sum ([]) = 0 etc.
8743
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
1196 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
1197 dims (1) = 1;
1bd918cfb6e2 reimplement any & all using the new reduction code
Jaroslav Hajek <highegg@gmail.com>
parents: 8736
diff changeset
1198
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1199 get_extent_triplet (dims, dim, l, n, u);
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1200
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1201 // Reduction operation reduces the array size.
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1202 if (dim < dims.length ()) dims(dim) = 1;
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1203 dims.chop_trailing_singletons ();
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1204
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1205 Array<R> ret (dims);
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1206 mx_red_op (src.data (), ret.fortran_vec (), l, n, u);
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1207
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1208 return ret;
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1209 }
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1210
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1211 template <class R, class T>
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1212 inline Array<R>
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1213 do_mx_cum_op (const Array<T>& src, int dim,
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1214 void (*mx_cum_op) (const T *, R *, octave_idx_type,
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1215 octave_idx_type, octave_idx_type))
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1216 {
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1217 octave_idx_type l, n, u;
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1218 dim_vector dims = src.dims ();
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1219 get_extent_triplet (dims, dim, l, n, u);
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1220
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1221 // Cumulative operation doesn't reduce the array size.
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1222 Array<R> ret (dims);
8736
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1223 mx_cum_op (src.data (), ret.fortran_vec (), l, n, u);
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1224
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1225 return ret;
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1226 }
53b4fdeacc2e improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8650
diff changeset
1227
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1228 template <class R>
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1229 inline Array<R>
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1230 do_mx_minmax_op (const Array<R>& src, int dim,
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1231 void (*mx_minmax_op) (const R *, R *, octave_idx_type,
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1232 octave_idx_type, octave_idx_type))
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1233 {
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1234 octave_idx_type l, n, u;
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1235 dim_vector dims = src.dims ();
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1236 get_extent_triplet (dims, dim, l, n, u);
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1237
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1238 // If the dimension is zero, we don't do anything.
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1239 if (dim < dims.length () && dims(dim) != 0) dims(dim) = 1;
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1240 dims.chop_trailing_singletons ();
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1241
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1242 Array<R> ret (dims);
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1243 mx_minmax_op (src.data (), ret.fortran_vec (), l, n, u);
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1244
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1245 return ret;
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1246 }
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1247
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1248 template <class R>
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1249 inline Array<R>
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1250 do_mx_minmax_op (const Array<R>& src, Array<octave_idx_type>& idx, int dim,
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1251 void (*mx_minmax_op) (const R *, R *, octave_idx_type *,
8751
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1252 octave_idx_type, octave_idx_type, octave_idx_type))
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1253 {
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1254 octave_idx_type l, n, u;
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1255 dim_vector dims = src.dims ();
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1256 get_extent_triplet (dims, dim, l, n, u);
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1257
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1258 // If the dimension is zero, we don't do anything.
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1259 if (dim < dims.length () && dims(dim) != 0) dims(dim) = 1;
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1260 dims.chop_trailing_singletons ();
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1261
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1262 Array<R> ret (dims);
8751
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1263 if (idx.dims () != dims) idx = Array<octave_idx_type> (dims);
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1264
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1265 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
1266 l, n, u);
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1267
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1268 return ret;
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1269 }
9f7ce4bf7650 optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8743
diff changeset
1270
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1271 template <class R>
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1272 inline Array<R>
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1273 do_mx_cumminmax_op (const Array<R>& src, int dim,
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1274 void (*mx_cumminmax_op) (const R *, R *, octave_idx_type,
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1275 octave_idx_type, octave_idx_type))
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1276 {
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1277 octave_idx_type l, n, u;
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1278 dim_vector dims = src.dims ();
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1279 get_extent_triplet (dims, dim, l, n, u);
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1280
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1281 Array<R> ret (dims);
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1282 mx_cumminmax_op (src.data (), ret.fortran_vec (), l, n, u);
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1283
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1284 return ret;
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1285 }
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1286
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1287 template <class R>
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1288 inline Array<R>
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1289 do_mx_cumminmax_op (const Array<R>& src, Array<octave_idx_type>& idx, int dim,
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1290 void (*mx_cumminmax_op) (const R *, R *, octave_idx_type *,
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1291 octave_idx_type, octave_idx_type, octave_idx_type))
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1292 {
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1293 octave_idx_type l, n, u;
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1294 dim_vector dims = src.dims ();
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1295 get_extent_triplet (dims, dim, l, n, u);
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1296
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1297 Array<R> ret (dims);
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1298 if (idx.dims () != dims) idx = Array<octave_idx_type> (dims);
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1299
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1300 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
1301 l, n, u);
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1302
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1303 return ret;
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1304 }
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 8776
diff changeset
1305
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1306 template <class R>
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1307 inline Array<R>
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1308 do_mx_diff_op (const Array<R>& src, int dim, octave_idx_type order,
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1309 void (*mx_diff_op) (const R *, R *,
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1310 octave_idx_type, octave_idx_type, octave_idx_type,
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1311 octave_idx_type))
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1312 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1313 octave_idx_type l, n, u;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1314 if (order <= 0)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1315 return src;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1316
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1317 dim_vector dims = src.dims ();
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1318
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1319 get_extent_triplet (dims, dim, l, n, u);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1320 if (dim >= dims.length ())
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1321 dims.resize (dim+1, 1);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1322
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1323 if (dims(dim) <= order)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1324 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1325 dims (dim) = 0;
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1326 return Array<R> (dims);
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1327 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1328 else
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1329 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1330 dims(dim) -= order;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1331 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1332
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
1333 Array<R> ret (dims);
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1334 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
1335
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1336 return ret;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1337 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8949
diff changeset
1338
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1339 // 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
1340 // 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
1341 // Accurate Sum And Dot Product,
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1342 // 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
1343
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1344 template <class T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1345 inline void twosum_accum (T& s, T& e,
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1346 const T& x)
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1347 {
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17769
diff changeset
1348 T s1 = s + x;
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17769
diff changeset
1349 T t = s1 - s;
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17769
diff changeset
1350 T e1 = (s - (s1 - t)) + (x - t);
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1351 s = s1;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1352 e += e1;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1353 }
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1354
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1355 template <class T>
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1356 inline T
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1357 mx_inline_xsum (const T *v, octave_idx_type n)
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1358 {
18098
6c706a83070f Tweak cset 8e056300994b defining 1 var per line in liboctave.
Rik <rik@octave.org>
parents: 18084
diff changeset
1359 T s, e;
6c706a83070f Tweak cset 8e056300994b defining 1 var per line in liboctave.
Rik <rik@octave.org>
parents: 18084
diff changeset
1360 s = e = 0;
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1361 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
1362 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
1363
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1364 return s + e;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1365 }
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1366
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1367 template <class T>
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1368 inline void
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1369 mx_inline_xsum (const T *v, T *r,
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1370 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
1371 {
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1372 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
1373 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
1374 e[i] = r[i] = T ();
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1375
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1376 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
1377 {
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1378 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
1379 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
1380
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1381 v += m;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1382 }
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1383
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1384 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
1385 r[i] += e[i];
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1386 }
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1387
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9702
diff changeset
1388 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
1389
2804
eedc2f3f61f7 [project @ 1997-03-11 04:34:50 by jwe]
jwe
parents: 2386
diff changeset
1390 #endif