annotate liboctave/mx-inlines.cc @ 9550:3d6a9aea2aea

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