00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifdef HAVE_CONFIG_H
00025 #include <config.h>
00026 #endif
00027
00028 #include "gripes.h"
00029 #include "oct-obj.h"
00030 #include "ov.h"
00031 #include "ov-typeinfo.h"
00032 #include "ov-cx-mat.h"
00033 #include "ov-scalar.h"
00034 #include "ops.h"
00035 #include "xpow.h"
00036
00037 #include "sparse-xpow.h"
00038 #include "sparse-xdiv.h"
00039 #include "smx-scm-s.h"
00040 #include "smx-s-scm.h"
00041 #include "ov-re-sparse.h"
00042 #include "ov-cx-sparse.h"
00043
00044
00045
00046 DEFBINOP_OP (add, sparse_complex_matrix, scalar, +)
00047 DEFBINOP_OP (sub, sparse_complex_matrix, scalar, -)
00048 DEFBINOP_OP (mul, sparse_complex_matrix, scalar, *)
00049
00050 DEFBINOP (div, sparse_complex_matrix, scalar)
00051 {
00052 CAST_BINOP_ARGS (const octave_sparse_complex_matrix&,
00053 const octave_scalar&);
00054
00055 double d = v2.double_value ();
00056 octave_value retval;
00057
00058 if (d == 0.0)
00059 gripe_divide_by_zero ();
00060
00061 retval = octave_value (v1.sparse_complex_matrix_value () / d);
00062
00063 return retval;
00064 }
00065
00066 DEFBINOP (pow, sparse_complex_matrix, scalar)
00067 {
00068 CAST_BINOP_ARGS (const octave_sparse_complex_matrix&,
00069 const octave_scalar&);
00070
00071 double tmp = v2.scalar_value ();
00072 if (static_cast<int> (tmp) == tmp)
00073 return xpow (v1.sparse_complex_matrix_value (), tmp);
00074 else
00075 return xpow (v1.complex_matrix_value (), tmp);
00076 }
00077
00078 DEFBINOP (ldiv, sparse_complex_matrix, scalar)
00079 {
00080 CAST_BINOP_ARGS (const octave_sparse_complex_matrix&, const octave_scalar&);
00081
00082 if (v1.rows() == 1 && v1.columns() == 1)
00083 {
00084 Complex d = v1.complex_value ();
00085
00086 if (d == 0.0)
00087 gripe_divide_by_zero ();
00088
00089 return octave_value (SparseComplexMatrix (1, 1, v2.scalar_value () / d));
00090 }
00091 else
00092 {
00093 MatrixType typ = v1.matrix_type ();
00094 SparseComplexMatrix m1 = v1.sparse_complex_matrix_value ();
00095 Matrix m2 = Matrix (1, 1, v2.scalar_value ());
00096 ComplexMatrix ret = xleftdiv (m1, m2, typ);
00097 v1.matrix_type (typ);
00098 return ret;
00099 }
00100 }
00101
00102 DEFBINOP_FN (lt, sparse_complex_matrix, scalar, mx_el_lt)
00103 DEFBINOP_FN (le, sparse_complex_matrix, scalar, mx_el_le)
00104 DEFBINOP_FN (eq, sparse_complex_matrix, scalar, mx_el_eq)
00105 DEFBINOP_FN (ge, sparse_complex_matrix, scalar, mx_el_ge)
00106 DEFBINOP_FN (gt, sparse_complex_matrix, scalar, mx_el_gt)
00107 DEFBINOP_FN (ne, sparse_complex_matrix, scalar, mx_el_ne)
00108
00109 DEFBINOP_OP (el_mul, sparse_complex_matrix, scalar, *)
00110
00111 DEFBINOP (el_div, sparse_complex_matrix, scalar)
00112 {
00113 CAST_BINOP_ARGS (const octave_sparse_complex_matrix&,
00114 const octave_scalar&);
00115
00116 double d = v2.double_value ();
00117 octave_value retval;
00118
00119 if (d == 0.0)
00120 gripe_divide_by_zero ();
00121
00122 retval = octave_value (v1.sparse_complex_matrix_value () / d);
00123
00124 return retval;
00125 }
00126
00127 DEFBINOP_FN (el_pow, sparse_complex_matrix, scalar, elem_xpow)
00128
00129 DEFBINOP (el_ldiv, sparse_complex_matrix, scalar)
00130 {
00131 CAST_BINOP_ARGS (const octave_sparse_complex_matrix&, const octave_scalar&);
00132
00133 return octave_value
00134 (x_el_div (v2.double_value (), v1.sparse_complex_matrix_value ()));
00135 }
00136
00137 DEFBINOP_FN (el_and, sparse_complex_matrix, scalar, mx_el_and)
00138 DEFBINOP_FN (el_or, sparse_complex_matrix, scalar, mx_el_or)
00139
00140 DEFCATOP (scm_s, sparse_complex_matrix, scalar)
00141 {
00142 CAST_BINOP_ARGS (octave_sparse_complex_matrix&, const octave_scalar&);
00143 SparseComplexMatrix tmp (1, 1, v2.complex_value ());
00144 return octave_value
00145 (v1.sparse_complex_matrix_value (). concat (tmp, ra_idx));
00146 }
00147
00148 DEFASSIGNOP (assign, sparse_complex_matrix, scalar)
00149 {
00150 CAST_BINOP_ARGS (octave_sparse_complex_matrix&, const octave_scalar&);
00151
00152 SparseComplexMatrix tmp (1, 1, v2.complex_value ());
00153 v1.assign (idx, tmp);
00154 return octave_value ();
00155 }
00156
00157 void
00158 install_scm_s_ops (void)
00159 {
00160 INSTALL_BINOP (op_add, octave_sparse_complex_matrix, octave_scalar, add);
00161 INSTALL_BINOP (op_sub, octave_sparse_complex_matrix, octave_scalar, sub);
00162 INSTALL_BINOP (op_mul, octave_sparse_complex_matrix, octave_scalar, mul);
00163 INSTALL_BINOP (op_div, octave_sparse_complex_matrix, octave_scalar, div);
00164 INSTALL_BINOP (op_pow, octave_sparse_complex_matrix, octave_scalar, pow);
00165 INSTALL_BINOP (op_ldiv, octave_sparse_complex_matrix, octave_scalar, ldiv);
00166 INSTALL_BINOP (op_lt, octave_sparse_complex_matrix, octave_scalar, lt);
00167 INSTALL_BINOP (op_le, octave_sparse_complex_matrix, octave_scalar, le);
00168 INSTALL_BINOP (op_eq, octave_sparse_complex_matrix, octave_scalar, eq);
00169 INSTALL_BINOP (op_ge, octave_sparse_complex_matrix, octave_scalar, ge);
00170 INSTALL_BINOP (op_gt, octave_sparse_complex_matrix, octave_scalar, gt);
00171 INSTALL_BINOP (op_ne, octave_sparse_complex_matrix, octave_scalar, ne);
00172 INSTALL_BINOP (op_el_mul, octave_sparse_complex_matrix, octave_scalar,
00173 el_mul);
00174 INSTALL_BINOP (op_el_div, octave_sparse_complex_matrix, octave_scalar,
00175 el_div);
00176 INSTALL_BINOP (op_el_pow, octave_sparse_complex_matrix, octave_scalar,
00177 el_pow);
00178 INSTALL_BINOP (op_el_ldiv, octave_sparse_complex_matrix, octave_scalar,
00179 el_ldiv);
00180 INSTALL_BINOP (op_el_and, octave_sparse_complex_matrix, octave_scalar,
00181 el_and);
00182 INSTALL_BINOP (op_el_or, octave_sparse_complex_matrix, octave_scalar,
00183 el_or);
00184
00185 INSTALL_CATOP (octave_sparse_complex_matrix, octave_scalar, scm_s);
00186
00187 INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_complex_matrix, octave_scalar,
00188 assign);
00189 }