2928
|
1 /* |
|
2 |
7017
|
3 Copyright (C) 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2004, 2005, |
|
4 2006, 2007 John W. Eaton |
2928
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
7016
|
10 Free Software Foundation; either version 3 of the License, or (at your |
|
11 option) any later version. |
2928
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
7016
|
19 along with Octave; see the file COPYING. If not, see |
|
20 <http://www.gnu.org/licenses/>. |
2928
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include <config.h> |
|
26 #endif |
|
27 |
|
28 #include "mx-s-cm.h" |
3145
|
29 #include "mx-cm-s.h" |
4544
|
30 #include "mx-s-cnda.h" |
|
31 #include "mx-cnda-s.h" |
2928
|
32 |
|
33 #include "gripes.h" |
4055
|
34 #include "oct-obj.h" |
2928
|
35 #include "ov.h" |
|
36 #include "ov-scalar.h" |
|
37 #include "ov-cx-mat.h" |
3766
|
38 #include "ov-re-mat.h" |
2928
|
39 #include "ov-typeinfo.h" |
|
40 #include "ops.h" |
|
41 #include "xdiv.h" |
|
42 #include "xpow.h" |
|
43 |
|
44 // scalar by complex matrix ops. |
|
45 |
4550
|
46 DEFNDBINOP_OP (add, scalar, complex_matrix, scalar, complex_array, +) |
|
47 DEFNDBINOP_OP (sub, scalar, complex_matrix, scalar, complex_array, -) |
|
48 DEFNDBINOP_OP (mul, scalar, complex_matrix, scalar, complex_array, *) |
2928
|
49 |
|
50 DEFBINOP (div, scalar, complex_matrix) |
|
51 { |
3766
|
52 CAST_BINOP_ARGS (const octave_scalar&, const octave_complex_matrix&); |
|
53 |
|
54 Matrix m1 = v1.matrix_value (); |
|
55 ComplexMatrix m2 = v2.complex_matrix_value (); |
5785
|
56 MatrixType typ = v2.matrix_type (); |
3766
|
57 |
5785
|
58 ComplexMatrix ret = xdiv (m1, m2, typ); |
|
59 |
|
60 v2.matrix_type (typ); |
|
61 return ret; |
2928
|
62 } |
|
63 |
|
64 DEFBINOP_FN (pow, scalar, complex_matrix, xpow) |
|
65 |
|
66 DEFBINOP (ldiv, scalar, complex_matrix) |
|
67 { |
|
68 CAST_BINOP_ARGS (const octave_scalar&, const octave_complex_matrix&); |
|
69 |
|
70 double d = v1.double_value (); |
|
71 |
|
72 if (d == 0.0) |
|
73 gripe_divide_by_zero (); |
|
74 |
4550
|
75 return octave_value (v2.complex_array_value () / d); |
2928
|
76 } |
|
77 |
4550
|
78 DEFNDBINOP_FN (lt, scalar, complex_matrix, scalar, complex_array, mx_el_lt) |
|
79 DEFNDBINOP_FN (le, scalar, complex_matrix, scalar, complex_array, mx_el_le) |
|
80 DEFNDBINOP_FN (eq, scalar, complex_matrix, scalar, complex_array, mx_el_eq) |
|
81 DEFNDBINOP_FN (ge, scalar, complex_matrix, scalar, complex_array, mx_el_ge) |
|
82 DEFNDBINOP_FN (gt, scalar, complex_matrix, scalar, complex_array, mx_el_gt) |
|
83 DEFNDBINOP_FN (ne, scalar, complex_matrix, scalar, complex_array, mx_el_ne) |
2928
|
84 |
4550
|
85 DEFNDBINOP_OP (el_mul, scalar, complex_matrix, scalar, complex_array, *) |
|
86 DEFNDBINOP_FN (el_div, scalar, complex_matrix, scalar, complex_array, x_el_div) |
|
87 DEFNDBINOP_FN (el_pow, scalar, complex_matrix, scalar, complex_array, elem_xpow) |
2928
|
88 |
|
89 DEFBINOP (el_ldiv, scalar, complex_matrix) |
|
90 { |
|
91 CAST_BINOP_ARGS (const octave_scalar&, const octave_complex_matrix&); |
|
92 |
|
93 double d = v1.double_value (); |
|
94 |
|
95 if (d == 0.0) |
|
96 gripe_divide_by_zero (); |
|
97 |
4550
|
98 return octave_value (v2.complex_array_value () / d); |
2928
|
99 } |
|
100 |
|
101 DEFBINOP (el_and, scalar, complex_matrix) |
|
102 { |
|
103 CAST_BINOP_ARGS (const octave_scalar&, const octave_complex_matrix&); |
|
104 |
4550
|
105 return mx_el_and (v1.double_value (), v2.complex_array_value ()); |
2928
|
106 } |
|
107 |
|
108 DEFBINOP (el_or, scalar, complex_matrix) |
|
109 { |
|
110 CAST_BINOP_ARGS (const octave_scalar&, const octave_complex_matrix&); |
|
111 |
4550
|
112 return mx_el_or (v1.double_value (), v2.complex_array_value ()); |
2928
|
113 } |
|
114 |
4915
|
115 DEFNDCATOP_FN (s_cm, scalar, complex_matrix, array, complex_array, concat) |
|
116 |
2928
|
117 DEFCONV (complex_matrix_conv, scalar, complex_matrix) |
|
118 { |
|
119 CAST_CONV_ARG (const octave_scalar&); |
|
120 |
|
121 return new octave_complex_matrix (ComplexMatrix (v.matrix_value ())); |
|
122 } |
|
123 |
|
124 void |
|
125 install_s_cm_ops (void) |
|
126 { |
3538
|
127 INSTALL_BINOP (op_add, octave_scalar, octave_complex_matrix, add); |
|
128 INSTALL_BINOP (op_sub, octave_scalar, octave_complex_matrix, sub); |
|
129 INSTALL_BINOP (op_mul, octave_scalar, octave_complex_matrix, mul); |
|
130 INSTALL_BINOP (op_div, octave_scalar, octave_complex_matrix, div); |
|
131 INSTALL_BINOP (op_pow, octave_scalar, octave_complex_matrix, pow); |
|
132 INSTALL_BINOP (op_ldiv, octave_scalar, octave_complex_matrix, ldiv); |
|
133 INSTALL_BINOP (op_lt, octave_scalar, octave_complex_matrix, lt); |
|
134 INSTALL_BINOP (op_le, octave_scalar, octave_complex_matrix, le); |
|
135 INSTALL_BINOP (op_eq, octave_scalar, octave_complex_matrix, eq); |
|
136 INSTALL_BINOP (op_ge, octave_scalar, octave_complex_matrix, ge); |
|
137 INSTALL_BINOP (op_gt, octave_scalar, octave_complex_matrix, gt); |
|
138 INSTALL_BINOP (op_ne, octave_scalar, octave_complex_matrix, ne); |
|
139 INSTALL_BINOP (op_el_mul, octave_scalar, octave_complex_matrix, el_mul); |
|
140 INSTALL_BINOP (op_el_div, octave_scalar, octave_complex_matrix, el_div); |
|
141 INSTALL_BINOP (op_el_pow, octave_scalar, octave_complex_matrix, el_pow); |
|
142 INSTALL_BINOP (op_el_ldiv, octave_scalar, octave_complex_matrix, el_ldiv); |
|
143 INSTALL_BINOP (op_el_and, octave_scalar, octave_complex_matrix, el_and); |
|
144 INSTALL_BINOP (op_el_or, octave_scalar, octave_complex_matrix, el_or); |
2928
|
145 |
4915
|
146 INSTALL_CATOP (octave_scalar, octave_complex_matrix, s_cm); |
|
147 |
2928
|
148 INSTALL_ASSIGNCONV (octave_scalar, octave_complex_matrix, octave_complex_matrix); |
|
149 |
3540
|
150 INSTALL_WIDENOP (octave_scalar, octave_complex_matrix, complex_matrix_conv); |
2928
|
151 } |
|
152 |
|
153 /* |
|
154 ;;; Local Variables: *** |
|
155 ;;; mode: C++ *** |
|
156 ;;; End: *** |
|
157 */ |