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
pt-cbinop.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2008-2017 Jaroslav Hajek
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 #if defined (HAVE_CONFIG_H)
24 # include "config.h"
25 #endif
26 
27 #include "error.h"
28 #include "ovl.h"
29 #include "ov.h"
30 #include "pt-cbinop.h"
31 #include "pt-bp.h"
32 #include "pt-unop.h"
33 #include "pt-walk.h"
34 
36 
39 {
41 
42  if (nargout > 1)
43  error ("binary operator '%s': invalid number of output arguments",
44  oper ().c_str ());
45 
46  retval = rvalue1 (nargout);
47 
48  return retval;
49 }
50 
53 {
55 
56  if (op_lhs)
57  {
59 
60  if (a.is_defined () && op_rhs)
61  {
63 
64  if (b.is_defined ())
65  retval = ::do_binary_op (etype, a, b);
66  }
67  }
68 
69  return retval;
70 }
71 
72 // If a tree expression is a transpose or hermitian transpose, return
73 // the argument and corresponding operator.
74 
77 {
78  if (exp->is_unary_expression ())
79  {
80  tree_unary_expression *uexp =
81  dynamic_cast<tree_unary_expression *> (exp);
82 
83  octave_value::unary_op op = uexp->op_type ();
84 
87  exp = uexp->operand ();
88  else
90 
91  return op;
92  }
93  else
95 }
96 
99 {
100  if (exp->is_unary_expression ())
101  {
102  tree_unary_expression *uexp =
103  dynamic_cast<tree_unary_expression *> (exp);
104 
105  octave_value::unary_op op = uexp->op_type ();
106 
107  if (op == octave_value::op_not)
108  exp = uexp->operand ();
109  else
111 
112  return op;
113  }
114  else
116 }
117 
118 // Possibly convert multiplication to trans_mul, mul_trans, herm_mul,
119 // or mul_herm.
120 
123 {
126 
128 
129  if (opa == octave_value::op_hermitian)
131  else if (opa == octave_value::op_transpose)
133  else
134  {
136 
137  if (opb == octave_value::op_hermitian)
139  else if (opb == octave_value::op_transpose)
141  }
142 
143  return retop;
144 }
145 
146 // Possibly convert left division to trans_ldiv or herm_ldiv.
147 
150 {
153 
155 
156  if (opa == octave_value::op_hermitian)
158  else if (opa == octave_value::op_transpose)
160 
161  return retop;
162 }
163 
164 // Possibly contract and/or with negation.
165 
169 {
172 
174 
175  if (opa == octave_value::op_not)
176  {
177  if (op == octave_value::op_el_and)
179  else if (op == octave_value::op_el_or)
181  }
182  else
183  {
185 
186  if (opb == octave_value::op_not)
187  {
188  if (op == octave_value::op_el_and)
190  else if (op == octave_value::op_el_or)
192  }
193  }
194 
195  return retop;
196 }
197 
200  int l, int c, octave_value::binary_op t)
201 {
202  tree_expression *ca = a;
203  tree_expression *cb = b;
205 
206  switch (t)
207  {
209  ct = simplify_mul_op (ca, cb);
210  break;
211 
213  ct = simplify_ldiv_op (ca, cb);
214  break;
215 
218  ct = simplify_and_or_op (ca, cb, t);
219  break;
220 
221  default:
223  break;
224  }
225 
227  ? new tree_binary_expression (a, b, l, c, t)
228  : new tree_compound_binary_expression (a, b, l,
229  c, t, ca,
230  cb, ct);
231 
232  return ret;
233 }
tree_expression * operand(void)
Definition: pt-unop.h:62
octave_value::unary_op op_type(void) const
Definition: pt-unop.h:66
tree_expression * tree_expression_ptr_t
Definition: pt-cbinop.cc:35
bool is_defined(void) const
Definition: ov.h:536
binary_op
Definition: ov.h:89
tree_expression * op_lhs
Definition: pt-cbinop.h:65
void error(const char *fmt,...)
Definition: error.cc:570
octave_value_list rvalue(int nargout)
Definition: pt-cbinop.cc:38
static octave_value::compound_binary_op simplify_mul_op(tree_expression_ptr_t &a, tree_expression_ptr_t &b)
Definition: pt-cbinop.cc:122
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function t
Definition: ov-usr-fcn.cc:935
octave_value::compound_binary_op etype
Definition: pt-cbinop.h:67
static octave_value::compound_binary_op simplify_ldiv_op(tree_expression_ptr_t &a, tree_expression_ptr_t &)
Definition: pt-cbinop.cc:149
static octave_value::unary_op strip_trans_herm(tree_expression_ptr_t &exp)
Definition: pt-cbinop.cc:76
calling an anonymous function involves an overhead quite comparable to the overhead of an m file function Passing a handle to a built in function is because the interpreter is not involved in the internal loop For a
Definition: cellfun.cc:398
std::string oper(void) const
Definition: pt-binop.cc:143
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function xample nargout(@histc)
Definition: ov-usr-fcn.cc:935
octave_value retval
Definition: data.cc:6294
static octave_value::compound_binary_op simplify_and_or_op(tree_expression_ptr_t &a, tree_expression_ptr_t &b, octave_value::binary_op op)
Definition: pt-cbinop.cc:167
octave_value rvalue1(int nargout=1)
Definition: pt-cbinop.cc:52
the sparsity preserving column transformation such that that defines the pivoting threshold can be given in which case it defines the c
Definition: lu.cc:138
tree_binary_expression * maybe_compound_binary_expression(tree_expression *a, tree_expression *b, int l, int c, octave_value::binary_op t)
Definition: pt-cbinop.cc:199
virtual octave_value rvalue1(int nargout=1)
Definition: pt-exp.cc:54
virtual bool is_unary_expression(void) const
Definition: pt-exp.h:69
tree_expression * op_rhs
Definition: pt-cbinop.h:66
compound_binary_op
Definition: ov.h:114
b
Definition: cellfun.cc:398
unary_op
Definition: ov.h:76
static octave_value::unary_op strip_not(tree_expression_ptr_t &exp)
Definition: pt-cbinop.cc:98
octave_value do_binary_op(octave_value::binary_op op, const octave_value &v1, const octave_value &v2)
Definition: ov.cc:2214