GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
pt-cbinop.cc
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 2008-2025 The Octave Project Developers
4//
5// See the file COPYRIGHT.md in the top-level directory of this
6// distribution or <https://octave.org/copyright/>.
7//
8// This file is part of Octave.
9//
10// Octave is free software: you can redistribute it and/or modify it
11// under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// Octave is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with Octave; see the file COPYING. If not, see
22// <https://www.gnu.org/licenses/>.
23//
24////////////////////////////////////////////////////////////////////////
25
26#if defined (HAVE_CONFIG_H)
27# include "config.h"
28#endif
29
30#include "interpreter.h"
31#include "ov.h"
32#include "pt-cbinop.h"
33#include "pt-eval.h"
34#include "pt-unop.h"
35
37
40{
41 octave_value val;
42
43 if (m_lhs)
44 {
45 // Evaluate with unknown number of output arguments
46 octave_value a = m_lhs->evaluate (tw, -1);
47
48 if (a.is_defined () && m_rhs)
49 {
50 // Evaluate with unknown number of output arguments
51 octave_value b = m_rhs->evaluate (tw, -1);
52
53 if (b.is_defined ())
54 {
55 interpreter& interp = tw.get_interpreter ();
56
57 type_info& ti = interp.get_type_info ();
58
59 val = binary_op (ti, m_etype, a, b);
60 }
61 }
62 }
63
64 return val;
65}
66
68
69// If a tree expression is a transpose or hermitian transpose, return
70// the argument and corresponding operator.
71
73strip_trans_herm (tree_expression_ptr_t& exp)
74{
75 if (exp->is_unary_expression ())
76 {
78 = dynamic_cast<tree_unary_expression *> (exp);
79
80 octave_value::unary_op op = uexp->op_type ();
81
84 exp = uexp->operand ();
85 else
87
88 return op;
89 }
90 else
92}
93
94// Possibly convert multiplication to trans_mul, mul_trans, herm_mul,
95// or mul_herm.
96
98simplify_mul_op (tree_expression_ptr_t& a, tree_expression_ptr_t& b)
99{
102
103 octave_value::unary_op opa = strip_trans_herm (a);
104
107 else if (opa == octave_value::op_transpose)
109 else
110 {
111 octave_value::unary_op opb = strip_trans_herm (b);
112
115 else if (opb == octave_value::op_transpose)
117 }
118
119 return retop;
120}
121
122// Possibly convert left division to trans_ldiv or herm_ldiv.
123
125simplify_ldiv_op (tree_expression_ptr_t& a, tree_expression_ptr_t&)
126{
129
130 octave_value::unary_op opa = strip_trans_herm (a);
131
134 else if (opa == octave_value::op_transpose)
136
137 return retop;
138}
139
140// Possibly contract and/or with negation.
141
144{
145 tree_expression *ca = a;
146 tree_expression *cb = b;
148
149 switch (t)
150 {
152 ct = simplify_mul_op (ca, cb);
153 break;
154
156 ct = simplify_ldiv_op (ca, cb);
157 break;
158
159 default:
161 break;
162 }
163
166 ? new tree_binary_expression (a, op_tok, b, t)
167 : new tree_compound_binary_expression (a, op_tok, b, t, ca, cb, ct));
168
169 return ret;
170}
171
172OCTAVE_END_NAMESPACE(octave)
type_info & get_type_info()
@ op_hermitian
Definition ov.h:84
@ op_transpose
Definition ov.h:83
@ unknown_unary_op
Definition ov.h:88
compound_binary_op
Definition ov.h:117
@ op_herm_ldiv
Definition ov.h:124
@ op_mul_trans
Definition ov.h:120
@ op_mul_herm
Definition ov.h:122
@ op_trans_ldiv
Definition ov.h:123
@ unknown_compound_binary_op
Definition ov.h:130
@ op_herm_mul
Definition ov.h:121
@ op_trans_mul
Definition ov.h:119
bool is_defined() const
Definition ov.h:592
binary_op
Definition ov.h:92
@ op_ldiv
Definition ov.h:98
@ op_mul
Definition ov.h:95
Definition token.h:42
octave_value evaluate(tree_evaluator &, int nargout=1)
Definition pt-cbinop.cc:39
interpreter & get_interpreter()
Definition pt-eval.h:422
virtual octave_value evaluate(tree_evaluator &tw, int nargout=1)=0
virtual bool is_unary_expression() const
Definition pt-exp.h:76
tree_expression * operand()
Definition pt-unop.h:66
octave_value::unary_op op_type() const
Definition pt-unop.h:70
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
octave_value binary_op(type_info &ti, octave_value::binary_op op, const octave_value &a, const octave_value &b)
tree_binary_expression * maybe_compound_binary_expression(tree_expression *a, const token &op_tok, tree_expression *b, octave_value::binary_op t)
Definition pt-cbinop.cc:143
tree_expression * tree_expression_ptr_t
Definition pt-cbinop.cc:67