GNU Octave  4.2.1
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-2017 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 <jordigh@octave.org>
24 
25 #if ! defined (octave_bsxfun_h)
26 #define octave_bsxfun_h 1
27 
28 #include "octave-config.h"
29 
30 #include <algorithm>
31 
32 #include "Array.h"
33 #include "dim-vector.h"
34 #include "lo-error.h"
35 
36 inline
37 bool
39  const dim_vector& dy)
40 {
41  for (int i = 0; i < std::min (dx.ndims (), dy.ndims ()); i++)
42  {
43  octave_idx_type xk = dx(i);
44  octave_idx_type yk = dy(i);
45  // Check the three conditions for valid bsxfun dims
46  if (! ((xk == yk) || (xk == 1 && yk != 1) || (xk != 1 && yk == 1)))
47  return false;
48  }
49 
50  (*current_liboctave_warning_with_id_handler)
51  ("Octave:language-extension", "performing `%s' automatic broadcasting",
52  name.c_str ());
53 
54  return true;
55 }
56 
57 // since we can't change the size of the assigned-to matrix, we cannot
58 // apply singleton expansion to it, so the conditions to check are
59 // different here.
60 inline
61 bool
63  const dim_vector& dx)
64 {
65  octave_idx_type drl = dr.ndims ();
66  octave_idx_type dxl = dx.ndims ();
67  if (drl < dxl)
68  return false;
69 
70  for (int i = 0; i < drl; i++)
71  {
72  octave_idx_type rk = dr(i);
73  octave_idx_type xk = dx(i);
74 
75  // Only two valid canditions to check; can't stretch rk
76  if (! ((rk == xk) || (rk != 1 && xk == 1)))
77  return false;
78  }
79 
80  (*current_liboctave_warning_with_id_handler)
81  ("Octave:language-extension", "performing `%s' automatic broadcasting",
82  name.c_str ());
83 
84  return true;
85 }
86 
87 #include "bsxfun-defs.cc"
88 
89 #endif
bool is_valid_inplace_bsxfun(const std::string &name, const dim_vector &dr, const dim_vector &dx)
Definition: bsxfun.h:62
OCTAVE_EXPORT octave_value_list any number nd example oindent prints the prompt xample Pick a any number!nd example oindent and waits for the user to enter a value The string entered by the user is evaluated as an so it may be a literal a variable name
Definition: input.cc:871
=val(i)}if ode{val(i)}occurs in table i
Definition: lookup.cc:239
octave_idx_type ndims(void) const
Number of dimensions.
Definition: dim-vector.h:301
bool is_valid_bsxfun(const std::string &name, const dim_vector &dx, const dim_vector &dy)
Definition: bsxfun.h:38
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:87
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:854
charNDArray min(char d, const charNDArray &m)
Definition: chNDArray.cc:205