Mercurial > hg > octave-nkf
annotate liboctave/numeric/bsxfun.h @ 17296:3a9efb68272d ss-3-7-6
snapshot 3.7.6
* configure.ac (OCTAVE_VERSION): Bump to 3.7.6.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 20 Aug 2013 15:17:54 -0400 |
parents | e2de3c8882be |
children | d63878346099 |
rev | line source |
---|---|
13004
d9d65c3017c3
Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
1 /* |
d9d65c3017c3
Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
2 |
16768 | 3 Copyright (C) 2012 Jordi GutiƩrrez Hermoso |
13004
d9d65c3017c3
Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
4 |
d9d65c3017c3
Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
5 This file is part of Octave. |
d9d65c3017c3
Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
6 |
d9d65c3017c3
Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
7 Octave is free software; you can redistribute it and/or modify it |
d9d65c3017c3
Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
8 under the terms of the GNU General Public License as published by the |
d9d65c3017c3
Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
9 Free Software Foundation; either version 3 of the License, or (at your |
d9d65c3017c3
Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
10 option) any later version. |
d9d65c3017c3
Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
11 |
d9d65c3017c3
Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
d9d65c3017c3
Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
d9d65c3017c3
Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
d9d65c3017c3
Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
15 for more details. |
d9d65c3017c3
Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
16 |
d9d65c3017c3
Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
17 You should have received a copy of the GNU General Public License |
d9d65c3017c3
Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
18 along with Octave; see the file COPYING. If not, see |
d9d65c3017c3
Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
19 <http://www.gnu.org/licenses/>. |
d9d65c3017c3
Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
20 |
d9d65c3017c3
Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
21 */ |
16768 | 22 |
23 // Author: Jordi GutiƩrrez Hermoso <jordigh@octave.org> | |
24 | |
13005
4061106b1c4b
Enable automatic bsxfun for power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
13004
diff
changeset
|
25 #if !defined (bsxfun_h) |
4061106b1c4b
Enable automatic bsxfun for power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
13004
diff
changeset
|
26 #define bsxfun_h 1 |
13004
d9d65c3017c3
Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
27 |
d9d65c3017c3
Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
28 #include <algorithm> |
d9d65c3017c3
Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
29 |
d9d65c3017c3
Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
30 #include "Array.h" |
d9d65c3017c3
Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
31 #include "dim-vector.h" |
14056
c3d401562410
allow warning (or error) for automatic bsxfun
John W. Eaton <jwe@octave.org>
parents:
13139
diff
changeset
|
32 #include "lo-error.h" |
13004
d9d65c3017c3
Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
33 |
d9d65c3017c3
Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
34 inline |
d9d65c3017c3
Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
35 bool |
14056
c3d401562410
allow warning (or error) for automatic bsxfun
John W. Eaton <jwe@octave.org>
parents:
13139
diff
changeset
|
36 is_valid_bsxfun (const std::string& name, const dim_vector& dx, |
c3d401562410
allow warning (or error) for automatic bsxfun
John W. Eaton <jwe@octave.org>
parents:
13139
diff
changeset
|
37 const dim_vector& dy) |
13004
d9d65c3017c3
Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
38 { |
d9d65c3017c3
Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
39 for (int i = 0; i < std::min (dx.length (), dy.length ()); i++) |
d9d65c3017c3
Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
40 { |
13139
aa4a23337a0f
Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13006
diff
changeset
|
41 octave_idx_type xk = dx(i), yk = dy(i); |
aa4a23337a0f
Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13006
diff
changeset
|
42 // Check the three conditions for valid bsxfun dims |
aa4a23337a0f
Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13006
diff
changeset
|
43 if (! ( (xk == yk) || (xk == 1 && yk > 1) || (xk > 1 && yk == 1))) |
aa4a23337a0f
Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13006
diff
changeset
|
44 return false; |
aa4a23337a0f
Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13006
diff
changeset
|
45 } |
14056
c3d401562410
allow warning (or error) for automatic bsxfun
John W. Eaton <jwe@octave.org>
parents:
13139
diff
changeset
|
46 |
c3d401562410
allow warning (or error) for automatic bsxfun
John W. Eaton <jwe@octave.org>
parents:
13139
diff
changeset
|
47 (*current_liboctave_warning_with_id_handler) |
14116
951eacaf9381
Initial documentation for broadcasting and general vectorization guidelines
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14056
diff
changeset
|
48 ("Octave:broadcast", "%s: automatic broadcasting operation applied", name.c_str ()); |
14056
c3d401562410
allow warning (or error) for automatic bsxfun
John W. Eaton <jwe@octave.org>
parents:
13139
diff
changeset
|
49 |
13139
aa4a23337a0f
Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13006
diff
changeset
|
50 return true; |
aa4a23337a0f
Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13006
diff
changeset
|
51 } |
aa4a23337a0f
Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13006
diff
changeset
|
52 |
aa4a23337a0f
Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13006
diff
changeset
|
53 // since we can't change the size of the assigned-to matrix, we cannot |
aa4a23337a0f
Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13006
diff
changeset
|
54 // apply singleton expansion to it, so the conditions to check are |
aa4a23337a0f
Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13006
diff
changeset
|
55 // different here. |
aa4a23337a0f
Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13006
diff
changeset
|
56 inline |
aa4a23337a0f
Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13006
diff
changeset
|
57 bool |
14056
c3d401562410
allow warning (or error) for automatic bsxfun
John W. Eaton <jwe@octave.org>
parents:
13139
diff
changeset
|
58 is_valid_inplace_bsxfun (const std::string& name, const dim_vector& dr, |
c3d401562410
allow warning (or error) for automatic bsxfun
John W. Eaton <jwe@octave.org>
parents:
13139
diff
changeset
|
59 const dim_vector& dx) |
13139
aa4a23337a0f
Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13006
diff
changeset
|
60 { |
aa4a23337a0f
Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13006
diff
changeset
|
61 octave_idx_type drl = dr.length (), dxl = dx.length (); |
aa4a23337a0f
Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13006
diff
changeset
|
62 if (drl < dxl) |
aa4a23337a0f
Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13006
diff
changeset
|
63 return false; |
aa4a23337a0f
Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13006
diff
changeset
|
64 |
aa4a23337a0f
Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13006
diff
changeset
|
65 for (int i = 0; i < drl; i++) |
aa4a23337a0f
Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13006
diff
changeset
|
66 { |
aa4a23337a0f
Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13006
diff
changeset
|
67 octave_idx_type rk = dr(i), xk = dx(i); |
aa4a23337a0f
Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13006
diff
changeset
|
68 |
aa4a23337a0f
Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13006
diff
changeset
|
69 // Only two valid canditions to check; can't stretch rk |
aa4a23337a0f
Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13006
diff
changeset
|
70 if (! ( (rk == xk) || (rk > 1 && xk == 1))) |
13004
d9d65c3017c3
Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
71 return false; |
d9d65c3017c3
Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
72 } |
14056
c3d401562410
allow warning (or error) for automatic bsxfun
John W. Eaton <jwe@octave.org>
parents:
13139
diff
changeset
|
73 |
c3d401562410
allow warning (or error) for automatic bsxfun
John W. Eaton <jwe@octave.org>
parents:
13139
diff
changeset
|
74 (*current_liboctave_warning_with_id_handler) |
14116
951eacaf9381
Initial documentation for broadcasting and general vectorization guidelines
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14056
diff
changeset
|
75 ("Octave:broadcast", "%s: automatic broadcasting operation applied", name.c_str ()); |
14056
c3d401562410
allow warning (or error) for automatic bsxfun
John W. Eaton <jwe@octave.org>
parents:
13139
diff
changeset
|
76 |
13004
d9d65c3017c3
Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
77 return true; |
d9d65c3017c3
Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff
changeset
|
78 } |
13005
4061106b1c4b
Enable automatic bsxfun for power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
13004
diff
changeset
|
79 |
13006
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
13005
diff
changeset
|
80 #include "bsxfun-defs.cc" |
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
13005
diff
changeset
|
81 |
13005
4061106b1c4b
Enable automatic bsxfun for power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
13004
diff
changeset
|
82 #endif |