GNU Octave  4.0.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
bsxfun.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2012-2015 Jordi GutiĆ©rrez Hermoso
4 
5 This file is part of Octave.
6 
7 Octave is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 // Author: Jordi GutiĆ©rrez Hermoso <[email protected]>
24 
25 #if !defined (octave_bsxfun_h)
26 #define octave_bsxfun_h 1
27 
28 #include <algorithm>
29 
30 #include "Array.h"
31 #include "dim-vector.h"
32 #include "lo-error.h"
33 
34 inline
35 bool
36 is_valid_bsxfun (const std::string& name, const dim_vector& dx,
37  const dim_vector& dy)
38 {
39  for (int i = 0; i < std::min (dx.length (), dy.length ()); i++)
40  {
41  octave_idx_type xk = dx(i);
42  octave_idx_type yk = dy(i);
43  // Check the three conditions for valid bsxfun dims
44  if (! ((xk == yk) || (xk == 1 && yk > 1) || (xk > 1 && yk == 1)))
45  return false;
46  }
47 
48  (*current_liboctave_warning_with_id_handler)
49  ("Octave:language-extension", "performing `%s' automatic broadcasting",
50  name.c_str ());
51 
52  return true;
53 }
54 
55 // since we can't change the size of the assigned-to matrix, we cannot
56 // apply singleton expansion to it, so the conditions to check are
57 // different here.
58 inline
59 bool
60 is_valid_inplace_bsxfun (const std::string& name, const dim_vector& dr,
61  const dim_vector& dx)
62 {
63  octave_idx_type drl = dr.length ();
64  octave_idx_type dxl = dx.length ();
65  if (drl < dxl)
66  return false;
67 
68  for (int i = 0; i < drl; i++)
69  {
70  octave_idx_type rk = dr(i);
71  octave_idx_type xk = dx(i);
72 
73  // Only two valid canditions to check; can't stretch rk
74  if (! ((rk == xk) || (rk > 1 && xk == 1)))
75  return false;
76  }
77 
78  (*current_liboctave_warning_with_id_handler)
79  ("Octave:language-extension", "performing `%s' automatic broadcasting",
80  name.c_str ());
81 
82  return true;
83 }
84 
85 #include "bsxfun-defs.cc"
86 
87 #endif
bool is_valid_inplace_bsxfun(const std::string &name, const dim_vector &dr, const dim_vector &dx)
Definition: bsxfun.h:60
bool is_valid_bsxfun(const std::string &name, const dim_vector &dx, const dim_vector &dy)
Definition: bsxfun.h:36
int length(void) const
Definition: dim-vector.h:281
charNDArray min(char d, const charNDArray &m)
Definition: chNDArray.cc:210