annotate liboctave/numeric/bsxfun-defs.cc @ 31249:de6fc38c78c6

Make Jacobian types offered by dlsode.f accessible by lsode (bug #31626). * liboctave/numeric/LSODE-opts.in: Add options "jacobian type", "lower jacobian subdiagonals", and "upper jacobian subdiagonals". * liboctave/numeric/LSODE.cc (file scope, lsode_j, LSODE::do_integrate (double)): Handle new configurable Jacobian types. * build-aux/mk-opts.pl: Don't implicitly convert to integer in condition.
author Olaf Till <olaf.till@uni-jena.de>
date Fri, 12 Nov 2010 08:53:05 +0100
parents 796f54d4ddbf
children 26da1722407b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 //
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 29931
diff changeset
3 // Copyright (C) 2009-2022 The Octave Project Developers
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
4 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 // distribution or <https://octave.org/copyright/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
7 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
8 // This file is part of Octave.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
9 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
11 // under the terms of the GNU General Public License as published by
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
13 // (at your option) any later version.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
14 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
18 // GNU General Public License for more details.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
19 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
20 // You should have received a copy of the GNU General Public License
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
21 // along with Octave; see the file COPYING. If not, see
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
22 // <https://www.gnu.org/licenses/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ////////////////////////////////////////////////////////////////////////
9747
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
25
20791
f7084eae3318 maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents: 19861
diff changeset
26 #if ! defined (octave_bsxfun_defs_h)
9747
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
27 #define octave_bsxfun_defs_h 1
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
28
23475
d691ed308237 maint: Clean up #includes in liboctave/numeric directory.
Rik <rik@octave.org>
parents: 23449
diff changeset
29 // This file should *not* include config.h. It is only included in other C++
d691ed308237 maint: Clean up #includes in liboctave/numeric directory.
Rik <rik@octave.org>
parents: 23449
diff changeset
30 // source files that should have included config.h before including this file.
21690
b6a686543080 Only include config.h in files that are compiled separately.
John W. Eaton <jwe@octave.org>
parents: 21139
diff changeset
31
9747
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
32 #include <algorithm>
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
33
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
34 #include "dim-vector.h"
23475
d691ed308237 maint: Clean up #includes in liboctave/numeric directory.
Rik <rik@octave.org>
parents: 23449
diff changeset
35 #include "lo-error.h"
d691ed308237 maint: Clean up #includes in liboctave/numeric directory.
Rik <rik@octave.org>
parents: 23449
diff changeset
36 #include "mx-inlines.cc"
9747
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
37 #include "oct-locbuf.h"
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
38
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21136
diff changeset
39 template <typename R, typename X, typename Y>
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10142
diff changeset
40 Array<R>
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10142
diff changeset
41 do_bsxfun_op (const Array<X>& x, const Array<Y>& y,
29572
aef11bb4e6d1 use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
42 void (*op_vv) (std::size_t, R *, const X *, const Y *),
aef11bb4e6d1 use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
43 void (*op_sv) (std::size_t, R *, X, const Y *),
aef11bb4e6d1 use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
44 void (*op_vs) (std::size_t, R *, const X *, Y))
9747
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
45 {
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
46 int nd = std::max (x.ndims (), y.ndims ());
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17744
diff changeset
47 dim_vector dvx = x.dims ().redim (nd);
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17744
diff changeset
48 dim_vector dvy = y.dims ().redim (nd);
9747
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
49
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
50 // Construct the result dimensions.
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
51 dim_vector dvr;
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
52 dvr.resize (nd);
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
53 for (int i = 0; i < nd; i++)
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
54 {
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17744
diff changeset
55 octave_idx_type xk = dvx(i);
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17744
diff changeset
56 octave_idx_type yk = dvy(i);
9747
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
57 if (xk == 1)
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
58 dvr(i) = yk;
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
59 else if (yk == 1 || xk == yk)
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
60 dvr(i) = xk;
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
61 else
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20791
diff changeset
62 (*current_liboctave_error_handler)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20791
diff changeset
63 ("bsxfun: nonconformant dimensions: %s and %s",
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 20791
diff changeset
64 x.dims ().str ().c_str (), y.dims ().str ().c_str ());
9747
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
65 }
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
66
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10142
diff changeset
67 Array<R> retval (dvr);
9747
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
68
29931
7faff48840eb prefer data over fortran_vec for read-only access to data
John W. Eaton <jwe@octave.org>
parents: 29572
diff changeset
69 const X *xvec = x.data ();
7faff48840eb prefer data over fortran_vec for read-only access to data
John W. Eaton <jwe@octave.org>
parents: 29572
diff changeset
70 const Y *yvec = y.data ();
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10142
diff changeset
71 R *rvec = retval.fortran_vec ();
9747
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
72
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
73 // Fold the common leading dimensions.
13704
6f779cc391fb More 64bit integer type fixes for bsxfun-defs.cc
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13700
diff changeset
74 octave_idx_type start, ldr = 1;
9747
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
75 for (start = 0; start < nd; start++)
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
76 {
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
77 if (dvx(start) != dvy(start))
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
78 break;
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
79 ldr *= dvr(start);
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
80 }
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
81
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23475
diff changeset
82 if (retval.isempty ())
9747
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
83 ; // do nothing
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
84 else if (start == nd)
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
85 op_vv (retval.numel (), rvec, xvec, yvec);
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
86 else
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
87 {
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
88 // Determine the type of the low-level loop.
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17744
diff changeset
89 bool xsing = false;
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17744
diff changeset
90 bool ysing = false;
9747
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
91 if (ldr == 1)
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
92 {
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
93 xsing = dvx(start) == 1;
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
94 ysing = dvy(start) == 1;
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
95 if (xsing || ysing)
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
96 {
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
97 ldr *= dvx(start) * dvy(start);
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
98 start++;
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
99 }
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
100 }
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17744
diff changeset
101 dim_vector cdvx = dvx.cumulative ();
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17744
diff changeset
102 dim_vector cdvy = dvy.cumulative ();
9747
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
103 // Nullify singleton dims to achieve a spread effect.
13700
782dc237a02d Pass correct integer type to std::max in bsxfun-defs.cc
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13139
diff changeset
104 for (int i = std::max (start, octave_idx_type (1)); i < nd; i++)
9747
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
105 {
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
106 if (dvx(i) == 1)
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
107 cdvx(i-1) = 0;
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
108 if (dvy(i) == 1)
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
109 cdvy(i-1) = 0;
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
110 }
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
111
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
112 octave_idx_type niter = dvr.numel (start);
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
113 // The index array.
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
114 OCTAVE_LOCAL_BUFFER_INIT (octave_idx_type, idx, nd, 0);
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
115 for (octave_idx_type iter = 0; iter < niter; iter++)
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
116 {
10142
829e69ec3110 make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents: 10140
diff changeset
117 octave_quit ();
9827
c15a5ed0da58 optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents: 9747
diff changeset
118
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
119 // Compute indices.
9747
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
120 // FIXME: performance impact noticeable?
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
121 octave_idx_type xidx = cdvx.cum_compute_index (idx);
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
122 octave_idx_type yidx = cdvy.cum_compute_index (idx);
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
123 octave_idx_type ridx = dvr.compute_index (idx);
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
124
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
125 // Apply the low-level loop.
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
126 if (xsing)
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
127 op_sv (ldr, rvec + ridx, xvec[xidx], yvec + yidx);
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
128 else if (ysing)
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
129 op_vs (ldr, rvec + ridx, xvec + xidx, yvec[yidx]);
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
130 else
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
131 op_vv (ldr, rvec + ridx, xvec + xidx, yvec + yidx);
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
132
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
133 dvr.increment_index (idx + start, start);
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
134 }
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
135 }
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
136
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
137 return retval;
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
138 }
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
139
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21136
diff changeset
140 template <typename R, typename X>
13139
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
141 void
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
142 do_inplace_bsxfun_op (Array<R>& r, const Array<X>& x,
29572
aef11bb4e6d1 use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
143 void (*op_vv) (std::size_t, R *, const X *),
aef11bb4e6d1 use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
144 void (*op_vs) (std::size_t, R *, X))
13139
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
145 {
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17744
diff changeset
146 dim_vector dvr = r.dims ();
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 17744
diff changeset
147 dim_vector dvx = x.dims ();
13139
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
148 octave_idx_type nd = r.ndims ();
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
149 dvx.redim (nd);
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
150
29931
7faff48840eb prefer data over fortran_vec for read-only access to data
John W. Eaton <jwe@octave.org>
parents: 29572
diff changeset
151 const X *xvec = x.data ();
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23220
diff changeset
152 R *rvec = r.fortran_vec ();
13139
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
153
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
154 // Fold the common leading dimensions.
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
155 octave_idx_type start, ldr = 1;
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
156 for (start = 0; start < nd; start++)
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
157 {
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
158 if (dvr(start) != dvx(start))
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
159 break;
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
160 ldr *= dvr(start);
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
161 }
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
162
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23475
diff changeset
163 if (r.isempty ())
13139
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
164 ; // do nothing
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
165 else if (start == nd)
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
166 op_vv (r.numel (), rvec, xvec);
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
167 else
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
168 {
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
169 // Determine the type of the low-level loop.
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
170 bool xsing = false;
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
171 if (ldr == 1)
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
172 {
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
173 xsing = dvx(start) == 1;
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
174 if (xsing)
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
175 {
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
176 ldr *= dvr(start) * dvx(start);
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
177 start++;
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
178 }
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
179 }
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
180
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
181 dim_vector cdvx = dvx.cumulative ();
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
182 // Nullify singleton dims to achieve a spread effect.
13700
782dc237a02d Pass correct integer type to std::max in bsxfun-defs.cc
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13139
diff changeset
183 for (int i = std::max (start, octave_idx_type (1)); i < nd; i++)
13139
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
184 {
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
185 if (dvx(i) == 1)
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
186 cdvx(i-1) = 0;
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
187 }
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
188
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
189 octave_idx_type niter = dvr.numel (start);
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
190 // The index array.
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
191 OCTAVE_LOCAL_BUFFER_INIT (octave_idx_type, idx, nd, 0);
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
192 for (octave_idx_type iter = 0; iter < niter; iter++)
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
193 {
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
194 octave_quit ();
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
195
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
196 // Compute indices.
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
197 // FIXME: performance impact noticeable?
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
198 octave_idx_type xidx = cdvx.cum_compute_index (idx);
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
199 octave_idx_type ridx = dvr.compute_index (idx);
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
200
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
201 // Apply the low-level loop.
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
202 if (xsing)
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
203 op_vs (ldr, rvec + ridx, xvec[xidx]);
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
204 else
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
205 op_vv (ldr, rvec + ridx, xvec + xidx);
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
206
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
207 dvr.increment_index (idx + start, start);
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
208 }
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
209 }
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
210 }
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13012
diff changeset
211
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
212 #define BSXFUN_OP_DEF(OP, ARRAY) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
213 ARRAY bsxfun_ ## OP (const ARRAY& x, const ARRAY& y)
9747
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
214
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
215 #define BSXFUN_OP2_DEF(OP, ARRAY, ARRAY1, ARRAY2) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
216 ARRAY bsxfun_ ## OP (const ARRAY1& x, const ARRAY2& y)
9827
c15a5ed0da58 optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents: 9747
diff changeset
217
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
218 #define BSXFUN_REL_DEF(OP, ARRAY) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
219 boolNDArray bsxfun_ ## OP (const ARRAY& x, const ARRAY& y)
9747
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
220
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
221 #define BSXFUN_OP_DEF_MXLOOP(OP, ARRAY, LOOP) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
222 BSXFUN_OP_DEF(OP, ARRAY) \
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10142
diff changeset
223 { return do_bsxfun_op<ARRAY::element_type, ARRAY::element_type, ARRAY::element_type> \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
224 (x, y, LOOP, LOOP, LOOP); }
9747
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
225
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
226 #define BSXFUN_OP2_DEF_MXLOOP(OP, ARRAY, ARRAY1, ARRAY2, LOOP) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
227 BSXFUN_OP2_DEF(OP, ARRAY, ARRAY1, ARRAY2) \
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10142
diff changeset
228 { return do_bsxfun_op<ARRAY::element_type, ARRAY1::element_type, ARRAY2::element_type> \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
229 (x, y, LOOP, LOOP, LOOP); }
9827
c15a5ed0da58 optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents: 9747
diff changeset
230
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
231 #define BSXFUN_REL_DEF_MXLOOP(OP, ARRAY, LOOP) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
232 BSXFUN_REL_DEF(OP, ARRAY) \
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10142
diff changeset
233 { return do_bsxfun_op<bool, ARRAY::element_type, ARRAY::element_type> \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
234 (x, y, LOOP, LOOP, LOOP); }
9747
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
235
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
236 #define BSXFUN_STDOP_DEFS_MXLOOP(ARRAY) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
237 BSXFUN_OP_DEF_MXLOOP (add, ARRAY, mx_inline_add) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
238 BSXFUN_OP_DEF_MXLOOP (sub, ARRAY, mx_inline_sub) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
239 BSXFUN_OP_DEF_MXLOOP (mul, ARRAY, mx_inline_mul) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
240 BSXFUN_OP_DEF_MXLOOP (div, ARRAY, mx_inline_div) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
241 BSXFUN_OP_DEF_MXLOOP (min, ARRAY, mx_inline_xmin) \
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
242 BSXFUN_OP_DEF_MXLOOP (max, ARRAY, mx_inline_xmax)
9747
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
243
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
244 #define BSXFUN_STDREL_DEFS_MXLOOP(ARRAY) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
245 BSXFUN_REL_DEF_MXLOOP (eq, ARRAY, mx_inline_eq) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
246 BSXFUN_REL_DEF_MXLOOP (ne, ARRAY, mx_inline_ne) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
247 BSXFUN_REL_DEF_MXLOOP (lt, ARRAY, mx_inline_lt) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
248 BSXFUN_REL_DEF_MXLOOP (le, ARRAY, mx_inline_le) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
249 BSXFUN_REL_DEF_MXLOOP (gt, ARRAY, mx_inline_gt) \
9747
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
250 BSXFUN_REL_DEF_MXLOOP (ge, ARRAY, mx_inline_ge)
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
251
13012
15eefbd9d4e8 Implement a few missing automatic bsxfun power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
252 //For bsxfun power with mixed integer/float types
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
253 #define BSXFUN_POW_MIXED_MXLOOP(INT_TYPE) \
13012
15eefbd9d4e8 Implement a few missing automatic bsxfun power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
254 BSXFUN_OP2_DEF_MXLOOP (pow, INT_TYPE, INT_TYPE, NDArray, mx_inline_pow) \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 21690
diff changeset
255 BSXFUN_OP2_DEF_MXLOOP (pow, INT_TYPE, INT_TYPE, FloatNDArray, mx_inline_pow) \
13012
15eefbd9d4e8 Implement a few missing automatic bsxfun power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
256 BSXFUN_OP2_DEF_MXLOOP (pow, INT_TYPE, NDArray, INT_TYPE, mx_inline_pow) \
15eefbd9d4e8 Implement a few missing automatic bsxfun power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
257 BSXFUN_OP2_DEF_MXLOOP (pow, INT_TYPE, FloatNDArray, INT_TYPE, mx_inline_pow)
15eefbd9d4e8 Implement a few missing automatic bsxfun power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11586
diff changeset
258
9747
7bda650b691a add omitted files from 26abff55f6fe
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
259 #endif