2928
|
1 /* |
|
2 |
|
3 Copyright (C) 1996, 1997 John W. Eaton |
|
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 2, or (at your option) any |
|
10 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, write to the Free |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
2928
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include <config.h> |
|
26 #endif |
|
27 |
|
28 #include "gripes.h" |
4055
|
29 #include "oct-obj.h" |
2928
|
30 #include "ov.h" |
|
31 #include "ov-re-mat.h" |
|
32 #include "ov-scalar.h" |
|
33 #include "ov-typeinfo.h" |
|
34 #include "ops.h" |
|
35 #include "xdiv.h" |
|
36 #include "xpow.h" |
|
37 |
|
38 // matrix by scalar ops. |
|
39 |
4543
|
40 DEFNDBINOP_OP (add, matrix, scalar, array, scalar, +) |
|
41 DEFNDBINOP_OP (sub, matrix, scalar, array, scalar, -) |
|
42 DEFNDBINOP_OP (mul, matrix, scalar, array, scalar, *) |
2928
|
43 |
|
44 DEFBINOP (div, matrix, scalar) |
|
45 { |
|
46 CAST_BINOP_ARGS (const octave_matrix&, const octave_scalar&); |
|
47 |
|
48 double d = v2.double_value (); |
|
49 |
|
50 if (d == 0.0) |
|
51 gripe_divide_by_zero (); |
|
52 |
4543
|
53 return octave_value (v1.array_value () / d); |
2928
|
54 } |
|
55 |
|
56 DEFBINOP_FN (pow, matrix, scalar, xpow) |
|
57 |
|
58 DEFBINOP (ldiv, matrix, scalar) |
|
59 { |
3766
|
60 CAST_BINOP_ARGS (const octave_matrix&, const octave_scalar&); |
|
61 |
|
62 Matrix m1 = v1.matrix_value (); |
|
63 Matrix m2 = v2.matrix_value (); |
|
64 |
|
65 return octave_value (xleftdiv (m1, m2)); |
2928
|
66 } |
|
67 |
4543
|
68 DEFNDBINOP_FN (lt, matrix, scalar, array, scalar, mx_el_lt) |
|
69 DEFNDBINOP_FN (le, matrix, scalar, array, scalar, mx_el_le) |
|
70 DEFNDBINOP_FN (eq, matrix, scalar, array, scalar, mx_el_eq) |
|
71 DEFNDBINOP_FN (ge, matrix, scalar, array, scalar, mx_el_ge) |
|
72 DEFNDBINOP_FN (gt, matrix, scalar, array, scalar, mx_el_gt) |
|
73 DEFNDBINOP_FN (ne, matrix, scalar, array, scalar, mx_el_ne) |
2928
|
74 |
4543
|
75 DEFNDBINOP_OP (el_mul, matrix, scalar, array, scalar, *) |
2928
|
76 |
|
77 DEFBINOP (el_div, matrix, scalar) |
|
78 { |
|
79 CAST_BINOP_ARGS (const octave_matrix&, const octave_scalar&); |
|
80 |
|
81 double d = v2.double_value (); |
|
82 |
|
83 if (d == 0.0) |
|
84 gripe_divide_by_zero (); |
|
85 |
4543
|
86 return octave_value (v1.array_value () / d); |
2928
|
87 } |
|
88 |
4543
|
89 DEFNDBINOP_FN (el_pow, matrix, scalar, array, scalar, elem_xpow) |
2928
|
90 |
|
91 DEFBINOP (el_ldiv, matrix, scalar) |
|
92 { |
|
93 CAST_BINOP_ARGS (const octave_matrix&, const octave_scalar&); |
|
94 |
4543
|
95 return x_el_div (v2.double_value (), v1.array_value ()); |
2928
|
96 } |
|
97 |
4543
|
98 DEFNDBINOP_FN (el_and, matrix, scalar, array, scalar, mx_el_and) |
|
99 DEFNDBINOP_FN (el_or, matrix, scalar, array, scalar, mx_el_or) |
2928
|
100 |
4915
|
101 DEFNDCATOP_FN (m_s, matrix, scalar, array, array, concat) |
|
102 |
4686
|
103 DEFNDASSIGNOP_FN (assign, matrix, scalar, array, assign) |
2928
|
104 |
|
105 void |
|
106 install_m_s_ops (void) |
|
107 { |
3538
|
108 INSTALL_BINOP (op_add, octave_matrix, octave_scalar, add); |
|
109 INSTALL_BINOP (op_sub, octave_matrix, octave_scalar, sub); |
|
110 INSTALL_BINOP (op_mul, octave_matrix, octave_scalar, mul); |
|
111 INSTALL_BINOP (op_div, octave_matrix, octave_scalar, div); |
|
112 INSTALL_BINOP (op_pow, octave_matrix, octave_scalar, pow); |
|
113 INSTALL_BINOP (op_ldiv, octave_matrix, octave_scalar, ldiv); |
4543
|
114 |
|
115 // INSTALL_BINOP (op_lt, octave_matrix, octave_scalar, lt); |
|
116 |
|
117 octave_value_typeinfo::register_binary_op |
|
118 (octave_value::op_lt, octave_matrix::static_type_id (), |
|
119 octave_scalar::static_type_id (), oct_binop_lt); |
|
120 |
3538
|
121 INSTALL_BINOP (op_le, octave_matrix, octave_scalar, le); |
|
122 INSTALL_BINOP (op_eq, octave_matrix, octave_scalar, eq); |
|
123 INSTALL_BINOP (op_ge, octave_matrix, octave_scalar, ge); |
|
124 INSTALL_BINOP (op_gt, octave_matrix, octave_scalar, gt); |
|
125 INSTALL_BINOP (op_ne, octave_matrix, octave_scalar, ne); |
|
126 INSTALL_BINOP (op_el_mul, octave_matrix, octave_scalar, el_mul); |
|
127 INSTALL_BINOP (op_el_div, octave_matrix, octave_scalar, el_div); |
|
128 INSTALL_BINOP (op_el_pow, octave_matrix, octave_scalar, el_pow); |
|
129 INSTALL_BINOP (op_el_ldiv, octave_matrix, octave_scalar, el_ldiv); |
|
130 INSTALL_BINOP (op_el_and, octave_matrix, octave_scalar, el_and); |
|
131 INSTALL_BINOP (op_el_or, octave_matrix, octave_scalar, el_or); |
2928
|
132 |
4915
|
133 INSTALL_CATOP (octave_matrix, octave_scalar, m_s); |
|
134 |
3538
|
135 INSTALL_ASSIGNOP (op_asn_eq, octave_matrix, octave_scalar, assign); |
2928
|
136 } |
|
137 |
|
138 /* |
|
139 ;;; Local Variables: *** |
|
140 ;;; mode: C++ *** |
|
141 ;;; End: *** |
|
142 */ |