GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
pt-cbinop.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2008-2018 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
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License 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 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if defined (HAVE_CONFIG_H)
24 # include "config.h"
25 #endif
26 
27 #include "ov.h"
28 #include "pt-cbinop.h"
29 #include "pt-unop.h"
30 
31 namespace octave
32 {
34 
35  // If a tree expression is a transpose or hermitian transpose, return
36  // the argument and corresponding operator.
37 
40  {
41  if (exp->is_unary_expression ())
42  {
44  dynamic_cast<octave::tree_unary_expression *> (exp);
45 
46  octave_value::unary_op op = uexp->op_type ();
47 
50  exp = uexp->operand ();
51  else
53 
54  return op;
55  }
56  else
58  }
59 
60 #if 0
61  // Restore this code if short-circuit behavior can be preserved when needed.
62  // See bug #54465.
63 
65  strip_not (octave::tree_expression_ptr_t& exp)
66  {
67  if (exp->is_unary_expression ())
68  {
70  dynamic_cast<octave::tree_unary_expression *> (exp);
71 
72  octave_value::unary_op op = uexp->op_type ();
73 
74  if (op == octave_value::op_not)
75  exp = uexp->operand ();
76  else
78 
79  return op;
80  }
81  else
83  }
84 #endif
85 
86  // Possibly convert multiplication to trans_mul, mul_trans, herm_mul,
87  // or mul_herm.
88 
92  {
95 
97 
98  if (opa == octave_value::op_hermitian)
100  else if (opa == octave_value::op_transpose)
102  else
103  {
105 
106  if (opb == octave_value::op_hermitian)
108  else if (opb == octave_value::op_transpose)
110  }
111 
112  return retop;
113  }
114 
115  // Possibly convert left division to trans_ldiv or herm_ldiv.
116 
120  {
123 
125 
126  if (opa == octave_value::op_hermitian)
128  else if (opa == octave_value::op_transpose)
130 
131  return retop;
132  }
133 
134  // Possibly contract and/or with negation.
135 
136 #if 0
137  // Restore this code if short-circuit behavior can be preserved when needed.
138  // See bug #54465.
140  simplify_and_or_op (octave::tree_expression_ptr_t& a,
143  {
146 
147  octave_value::unary_op opa = strip_not (a);
148 
149  if (opa == octave_value::op_not)
150  {
151  if (op == octave_value::op_el_and)
153  else if (op == octave_value::op_el_or)
155  }
156  else
157  {
158  octave_value::unary_op opb = strip_not (b);
159 
160  if (opb == octave_value::op_not)
161  {
162  if (op == octave_value::op_el_and)
164  else if (op == octave_value::op_el_or)
166  }
167  }
168 
169  return retop;
170  }
171 #endif
172 
173  tree_binary_expression *
175  int l, int c, octave_value::binary_op t)
176  {
177  tree_expression *ca = a;
178  tree_expression *cb = b;
180 
181  switch (t)
182  {
184  ct = simplify_mul_op (ca, cb);
185  break;
186 
188  ct = simplify_ldiv_op (ca, cb);
189  break;
190 
191 #if 0
192  // Restore this case if short-circuit behavior can be preserved
193  // when needed. See bug #54465.
196  ct = simplify_and_or_op (ca, cb, t);
197  break;
198 #endif
199 
200  default:
202  break;
203  }
204 
207  ? new tree_binary_expression (a, b, l, c, t)
208  : new tree_compound_binary_expression (a, b, l, c, t, ca, cb, ct));
209 
210  return ret;
211  }
212 }
static octave_value::compound_binary_op simplify_mul_op(octave::tree_expression_ptr_t &a, octave::tree_expression_ptr_t &b)
Definition: pt-cbinop.cc:90
octave_value::unary_op op_type(void) const
Definition: pt-unop.h:74
binary_op
Definition: ov.h:94
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:997
tree_expression * tree_expression_ptr_t
Definition: pt-cbinop.cc:33
nd example oindent opens the file binary numeric values will be read assuming they are stored in IEEE format with the least significant bit and then converted to the native representation Opening a file that is already open simply opens it again and returns a separate file id It is not an error to open a file several though writing to the same file through several different file ids may produce unexpected results The possible values of text mode reading and writing automatically converts linefeeds to the appropriate line end character for the you may append a you must also open the file in binary mode The parameter conversions are currently only supported for and permissions will be set to and then everything is written in a single operation This is very efficient and improves performance c
Definition: file-io.cc:587
static octave_value::unary_op strip_trans_herm(octave::tree_expression_ptr_t &exp)
Definition: pt-cbinop.cc:39
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:400
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:174
compound_binary_op
Definition: ov.h:119
b
Definition: cellfun.cc:400
virtual bool is_unary_expression(void) const
Definition: pt-exp.h:77
tree_expression * operand(void)
Definition: pt-unop.h:70
unary_op
Definition: ov.h:81
static octave_value::compound_binary_op simplify_ldiv_op(octave::tree_expression_ptr_t &a, octave::tree_expression_ptr_t &)
Definition: pt-cbinop.cc:118