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 |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
4192
|
23 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) |
2928
|
24 #pragma implementation |
|
25 #endif |
|
26 |
|
27 #ifdef HAVE_CONFIG_H |
|
28 #include <config.h> |
|
29 #endif |
|
30 |
|
31 #include "gripes.h" |
4055
|
32 #include "oct-obj.h" |
2928
|
33 #include "ov.h" |
|
34 #include "ov-scalar.h" |
|
35 #include "ov-re-mat.h" |
|
36 #include "ov-typeinfo.h" |
|
37 #include "ops.h" |
|
38 #include "xdiv.h" |
|
39 #include "xpow.h" |
|
40 |
|
41 // scalar by matrix ops. |
|
42 |
4543
|
43 DEFNDBINOP_OP (add, scalar, matrix, scalar, array, +) |
|
44 DEFNDBINOP_OP (sub, scalar, matrix, scalar, array, -) |
|
45 DEFNDBINOP_OP (mul, scalar, matrix, scalar, array, *) |
2928
|
46 |
|
47 DEFBINOP (div, scalar, matrix) |
|
48 { |
3766
|
49 CAST_BINOP_ARGS (const octave_scalar&, const octave_matrix&); |
|
50 |
|
51 Matrix m1 = v1.matrix_value (); |
|
52 Matrix m2 = v2.matrix_value (); |
|
53 |
|
54 return octave_value (xdiv (m1, m2)); |
2928
|
55 } |
|
56 |
|
57 DEFBINOP_FN (pow, scalar, matrix, xpow) |
|
58 |
|
59 DEFBINOP (ldiv, scalar, matrix) |
|
60 { |
|
61 CAST_BINOP_ARGS (const octave_scalar&, const octave_matrix&); |
|
62 |
|
63 double d = v1.double_value (); |
|
64 |
|
65 if (d == 0.0) |
|
66 gripe_divide_by_zero (); |
|
67 |
4543
|
68 return octave_value (v2.array_value () / d); |
2928
|
69 } |
|
70 |
4543
|
71 DEFNDBINOP_FN (lt, scalar, matrix, scalar, array, mx_el_lt) |
|
72 DEFNDBINOP_FN (le, scalar, matrix, scalar, array, mx_el_le) |
|
73 DEFNDBINOP_FN (eq, scalar, matrix, scalar, array, mx_el_eq) |
|
74 DEFNDBINOP_FN (ge, scalar, matrix, scalar, array, mx_el_ge) |
|
75 DEFNDBINOP_FN (gt, scalar, matrix, scalar, array, mx_el_gt) |
|
76 DEFNDBINOP_FN (ne, scalar, matrix, scalar, array, mx_el_ne) |
2928
|
77 |
4543
|
78 DEFNDBINOP_OP (el_mul, scalar, matrix, scalar, array, *) |
|
79 DEFNDBINOP_FN (el_div, scalar, matrix, scalar, array, x_el_div) |
|
80 DEFNDBINOP_FN (el_pow, scalar, matrix, scalar, array, elem_xpow) |
2928
|
81 |
|
82 DEFBINOP (el_ldiv, scalar, matrix) |
|
83 { |
|
84 CAST_BINOP_ARGS (const octave_scalar&, const octave_matrix&); |
|
85 |
|
86 double d = v1.double_value (); |
|
87 |
|
88 if (d == 0.0) |
|
89 gripe_divide_by_zero (); |
|
90 |
4543
|
91 return octave_value (v2.array_value () / d); |
2928
|
92 } |
|
93 |
4543
|
94 DEFNDBINOP_FN (el_and, scalar, matrix, scalar, array, mx_el_and) |
|
95 DEFNDBINOP_FN (el_or, scalar, matrix, scalar, array, mx_el_or) |
2928
|
96 |
|
97 DEFCONV (matrix_conv, scalar, matrix) |
|
98 { |
|
99 CAST_CONV_ARG (const octave_scalar&); |
|
100 |
|
101 return new octave_matrix (v.matrix_value ()); |
|
102 } |
|
103 |
|
104 void |
|
105 install_s_m_ops (void) |
|
106 { |
3538
|
107 INSTALL_BINOP (op_add, octave_scalar, octave_matrix, add); |
|
108 INSTALL_BINOP (op_sub, octave_scalar, octave_matrix, sub); |
|
109 INSTALL_BINOP (op_mul, octave_scalar, octave_matrix, mul); |
|
110 INSTALL_BINOP (op_div, octave_scalar, octave_matrix, div); |
|
111 INSTALL_BINOP (op_pow, octave_scalar, octave_matrix, pow); |
|
112 INSTALL_BINOP (op_ldiv, octave_scalar, octave_matrix, ldiv); |
|
113 INSTALL_BINOP (op_lt, octave_scalar, octave_matrix, lt); |
|
114 INSTALL_BINOP (op_le, octave_scalar, octave_matrix, le); |
|
115 INSTALL_BINOP (op_eq, octave_scalar, octave_matrix, eq); |
|
116 INSTALL_BINOP (op_ge, octave_scalar, octave_matrix, ge); |
|
117 INSTALL_BINOP (op_gt, octave_scalar, octave_matrix, gt); |
|
118 INSTALL_BINOP (op_ne, octave_scalar, octave_matrix, ne); |
|
119 INSTALL_BINOP (op_el_mul, octave_scalar, octave_matrix, el_mul); |
|
120 INSTALL_BINOP (op_el_div, octave_scalar, octave_matrix, el_div); |
|
121 INSTALL_BINOP (op_el_pow, octave_scalar, octave_matrix, el_pow); |
|
122 INSTALL_BINOP (op_el_ldiv, octave_scalar, octave_matrix, el_ldiv); |
|
123 INSTALL_BINOP (op_el_and, octave_scalar, octave_matrix, el_and); |
|
124 INSTALL_BINOP (op_el_or, octave_scalar, octave_matrix, el_or); |
2928
|
125 |
|
126 INSTALL_ASSIGNCONV (octave_scalar, octave_matrix, octave_matrix); |
|
127 |
3540
|
128 INSTALL_WIDENOP (octave_scalar, octave_matrix, matrix_conv); |
2928
|
129 } |
|
130 |
|
131 /* |
|
132 ;;; Local Variables: *** |
|
133 ;;; mode: C++ *** |
|
134 ;;; End: *** |
|
135 */ |