00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifdef HAVE_CONFIG_H
00024 #include <config.h>
00025 #endif
00026
00027 #include "gripes.h"
00028 #include "oct-obj.h"
00029 #include "ov.h"
00030 #include "ov-re-mat.h"
00031 #include "ov-flt-re-mat.h"
00032 #include "ov-flt-cx-mat.h"
00033 #include "ov-scalar.h"
00034 #include "ov-typeinfo.h"
00035 #include "ops.h"
00036 #include "xdiv.h"
00037 #include "xpow.h"
00038
00039
00040
00041 DEFNDBINOP_OP (add, matrix, scalar, array, scalar, +)
00042 DEFNDBINOP_OP (sub, matrix, scalar, array, scalar, -)
00043 DEFNDBINOP_OP (mul, matrix, scalar, array, scalar, *)
00044
00045 DEFBINOP (div, matrix, scalar)
00046 {
00047 CAST_BINOP_ARGS (const octave_matrix&, const octave_scalar&);
00048
00049 double d = v2.double_value ();
00050
00051 if (d == 0.0)
00052 gripe_divide_by_zero ();
00053
00054 return octave_value (v1.array_value () / d);
00055 }
00056
00057 DEFBINOP_FN (pow, matrix, scalar, xpow)
00058
00059 DEFBINOP (ldiv, matrix, scalar)
00060 {
00061 CAST_BINOP_ARGS (const octave_matrix&, const octave_scalar&);
00062
00063 Matrix m1 = v1.matrix_value ();
00064 Matrix m2 = v2.matrix_value ();
00065 MatrixType typ = v1.matrix_type ();
00066
00067 Matrix ret = xleftdiv (m1, m2, typ);
00068
00069 v1.matrix_type (typ);
00070 return ret;
00071 }
00072
00073 DEFNDBINOP_FN (lt, matrix, scalar, array, scalar, mx_el_lt)
00074 DEFNDBINOP_FN (le, matrix, scalar, array, scalar, mx_el_le)
00075 DEFNDBINOP_FN (eq, matrix, scalar, array, scalar, mx_el_eq)
00076 DEFNDBINOP_FN (ge, matrix, scalar, array, scalar, mx_el_ge)
00077 DEFNDBINOP_FN (gt, matrix, scalar, array, scalar, mx_el_gt)
00078 DEFNDBINOP_FN (ne, matrix, scalar, array, scalar, mx_el_ne)
00079
00080 DEFNDBINOP_OP (el_mul, matrix, scalar, array, scalar, *)
00081
00082 DEFBINOP (el_div, matrix, scalar)
00083 {
00084 CAST_BINOP_ARGS (const octave_matrix&, const octave_scalar&);
00085
00086 double d = v2.double_value ();
00087
00088 if (d == 0.0)
00089 gripe_divide_by_zero ();
00090
00091 return octave_value (v1.array_value () / d);
00092 }
00093
00094 DEFNDBINOP_FN (el_pow, matrix, scalar, array, scalar, elem_xpow)
00095
00096 DEFBINOP (el_ldiv, matrix, scalar)
00097 {
00098 CAST_BINOP_ARGS (const octave_matrix&, const octave_scalar&);
00099
00100 return x_el_div (v2.double_value (), v1.array_value ());
00101 }
00102
00103 DEFNDBINOP_FN (el_and, matrix, scalar, array, scalar, mx_el_and)
00104 DEFNDBINOP_FN (el_or, matrix, scalar, array, scalar, mx_el_or)
00105
00106 DEFNDCATOP_FN (m_s, matrix, scalar, array, array, concat)
00107
00108 DEFNDASSIGNOP_FN (assign, matrix, scalar, scalar, assign)
00109 DEFNDASSIGNOP_FN (sgl_assign, float_matrix, scalar, float_scalar, assign)
00110 DEFNDASSIGNOP_FN (clx_sgl_assign, float_complex_matrix, scalar, float_complex, assign)
00111
00112 DEFNDASSIGNOP_OP (assign_add, matrix, scalar, scalar, +=)
00113 DEFNDASSIGNOP_OP (assign_sub, matrix, scalar, scalar, -=)
00114 DEFNDASSIGNOP_OP (assign_mul, matrix, scalar, scalar, *=)
00115 DEFNDASSIGNOP_OP (assign_div, matrix, scalar, scalar, /=)
00116
00117 void
00118 install_m_s_ops (void)
00119 {
00120 INSTALL_BINOP (op_add, octave_matrix, octave_scalar, add);
00121 INSTALL_BINOP (op_sub, octave_matrix, octave_scalar, sub);
00122 INSTALL_BINOP (op_mul, octave_matrix, octave_scalar, mul);
00123 INSTALL_BINOP (op_div, octave_matrix, octave_scalar, div);
00124 INSTALL_BINOP (op_pow, octave_matrix, octave_scalar, pow);
00125 INSTALL_BINOP (op_ldiv, octave_matrix, octave_scalar, ldiv);
00126
00127
00128
00129 octave_value_typeinfo::register_binary_op
00130 (octave_value::op_lt, octave_matrix::static_type_id (),
00131 octave_scalar::static_type_id (), oct_binop_lt);
00132
00133 INSTALL_BINOP (op_le, octave_matrix, octave_scalar, le);
00134 INSTALL_BINOP (op_eq, octave_matrix, octave_scalar, eq);
00135 INSTALL_BINOP (op_ge, octave_matrix, octave_scalar, ge);
00136 INSTALL_BINOP (op_gt, octave_matrix, octave_scalar, gt);
00137 INSTALL_BINOP (op_ne, octave_matrix, octave_scalar, ne);
00138 INSTALL_BINOP (op_el_mul, octave_matrix, octave_scalar, el_mul);
00139 INSTALL_BINOP (op_el_div, octave_matrix, octave_scalar, el_div);
00140 INSTALL_BINOP (op_el_pow, octave_matrix, octave_scalar, el_pow);
00141 INSTALL_BINOP (op_el_ldiv, octave_matrix, octave_scalar, el_ldiv);
00142 INSTALL_BINOP (op_el_and, octave_matrix, octave_scalar, el_and);
00143 INSTALL_BINOP (op_el_or, octave_matrix, octave_scalar, el_or);
00144
00145 INSTALL_CATOP (octave_matrix, octave_scalar, m_s);
00146
00147 INSTALL_ASSIGNOP (op_asn_eq, octave_matrix, octave_scalar, assign);
00148 INSTALL_ASSIGNOP (op_asn_eq, octave_float_matrix, octave_scalar, sgl_assign);
00149 INSTALL_ASSIGNOP (op_asn_eq, octave_float_complex_matrix, octave_scalar, clx_sgl_assign);
00150
00151 INSTALL_ASSIGNOP (op_add_eq, octave_matrix, octave_scalar, assign_add);
00152 INSTALL_ASSIGNOP (op_sub_eq, octave_matrix, octave_scalar, assign_sub);
00153 INSTALL_ASSIGNOP (op_mul_eq, octave_matrix, octave_scalar, assign_mul);
00154 INSTALL_ASSIGNOP (op_div_eq, octave_matrix, octave_scalar, assign_div);
00155 }