annotate liboctave/bsxfun.h @ 14193:72aebe619641 stable rc-3-6-0-0

3.6.0-rc0 release candidate * configure.ac (AC_INIT): Version is now 3.6.0-rc0. (OCTAVE_RELEASE_DATE): Now 2012-01-10. (OCTAVE_API_VERSION_NUMBER): Now 47.
author John W. Eaton <jwe@octave.org>
date Tue, 10 Jan 2012 16:43:41 -0500
parents 72c96de7a403
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
14138
72c96de7a403 maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents: 14116
diff changeset
3 Copyright (C) 2012 Jordi GutiƩrrez Hermoso <jordigh@octave.org>
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 */
13005
4061106b1c4b Enable automatic bsxfun for power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 13004
diff changeset
22 #if !defined (bsxfun_h)
4061106b1c4b Enable automatic bsxfun for power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 13004
diff changeset
23 #define bsxfun_h 1
13004
d9d65c3017c3 Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff changeset
24
d9d65c3017c3 Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff changeset
25 #include <algorithm>
d9d65c3017c3 Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff changeset
26
d9d65c3017c3 Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff changeset
27 #include "Array.h"
d9d65c3017c3 Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff changeset
28 #include "dim-vector.h"
14056
c3d401562410 allow warning (or error) for automatic bsxfun
John W. Eaton <jwe@octave.org>
parents: 13139
diff changeset
29 #include "lo-error.h"
13004
d9d65c3017c3 Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff changeset
30
d9d65c3017c3 Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff changeset
31 inline
d9d65c3017c3 Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff changeset
32 bool
14056
c3d401562410 allow warning (or error) for automatic bsxfun
John W. Eaton <jwe@octave.org>
parents: 13139
diff changeset
33 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
34 const dim_vector& dy)
13004
d9d65c3017c3 Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff changeset
35 {
d9d65c3017c3 Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff changeset
36 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
37 {
13139
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13006
diff changeset
38 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
39 // 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
40 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
41 return false;
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13006
diff changeset
42 }
14056
c3d401562410 allow warning (or error) for automatic bsxfun
John W. Eaton <jwe@octave.org>
parents: 13139
diff changeset
43
c3d401562410 allow warning (or error) for automatic bsxfun
John W. Eaton <jwe@octave.org>
parents: 13139
diff changeset
44 (*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
45 ("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
46
13139
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13006
diff changeset
47 return true;
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13006
diff changeset
48 }
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13006
diff changeset
49
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13006
diff changeset
50 // 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
51 // 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
52 // different here.
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13006
diff changeset
53 inline
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13006
diff changeset
54 bool
14056
c3d401562410 allow warning (or error) for automatic bsxfun
John W. Eaton <jwe@octave.org>
parents: 13139
diff changeset
55 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
56 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
57 {
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13006
diff changeset
58 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
59 if (drl < dxl)
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13006
diff changeset
60 return false;
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13006
diff changeset
61
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13006
diff changeset
62 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
63 {
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13006
diff changeset
64 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
65
aa4a23337a0f Enable BSX in-place for missing assignment operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13006
diff changeset
66 // 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
67 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
68 return false;
d9d65c3017c3 Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff changeset
69 }
14056
c3d401562410 allow warning (or error) for automatic bsxfun
John W. Eaton <jwe@octave.org>
parents: 13139
diff changeset
70
c3d401562410 allow warning (or error) for automatic bsxfun
John W. Eaton <jwe@octave.org>
parents: 13139
diff changeset
71 (*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
72 ("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
73
13004
d9d65c3017c3 Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff changeset
74 return true;
d9d65c3017c3 Make bsxfun automatic for most binary operators.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
diff changeset
75 }
13005
4061106b1c4b Enable automatic bsxfun for power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 13004
diff changeset
76
13006
61be447052c3 Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 13005
diff changeset
77 #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
78
13005
4061106b1c4b Enable automatic bsxfun for power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 13004
diff changeset
79 #endif