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 "ops.h"
00034 #include "xdiv.h"
00035
00036 #include "sparse-xpow.h"
00037 #include "sparse-xdiv.h"
00038 #include "smx-scm-cm.h"
00039 #include "smx-cm-scm.h"
00040 #include "ov-cx-sparse.h"
00041
00042
00043
00044 DEFBINOP_OP (add, sparse_complex_matrix, complex_matrix, +)
00045 DEFBINOP_OP (sub, sparse_complex_matrix, complex_matrix, -)
00046
00047 DEFBINOP_OP (mul, sparse_complex_matrix, complex_matrix, *)
00048
00049 DEFBINOP (div, sparse_complex_matrix, complex_matrix)
00050 {
00051 CAST_BINOP_ARGS (const octave_sparse_complex_matrix&,
00052 const octave_complex_matrix&);
00053 MatrixType typ = v2.matrix_type ();
00054
00055 ComplexMatrix ret = xdiv (v1.complex_matrix_value (),
00056 v2.complex_matrix_value (), typ);
00057
00058 v2.matrix_type (typ);
00059 return ret;
00060 }
00061
00062 DEFBINOPX (pow, sparse_complex_matrix, complex_matrix)
00063 {
00064 error ("can't do A ^ B for A and B both matrices");
00065 return octave_value ();
00066 }
00067
00068 DEFBINOP (ldiv, sparse_complex_matrix, complex_matrix)
00069 {
00070 CAST_BINOP_ARGS (const octave_sparse_complex_matrix&, const octave_complex_matrix&);
00071
00072 if (v1.rows() == 1 && v1.columns() == 1)
00073 {
00074 Complex d = v1.complex_value ();
00075
00076 if (d == 0.0)
00077 gripe_divide_by_zero ();
00078
00079 return octave_value (v2.complex_array_value () / d);
00080 }
00081 else
00082 {
00083 MatrixType typ = v1.matrix_type ();
00084
00085 ComplexMatrix ret = xleftdiv (v1.sparse_complex_matrix_value (),
00086 v2.complex_matrix_value (), typ);
00087
00088 v1.matrix_type (typ);
00089 return ret;
00090 }
00091 }
00092
00093 DEFBINOP_FN (trans_mul, sparse_complex_matrix, complex_matrix, trans_mul);
00094 DEFBINOP_FN (herm_mul, sparse_complex_matrix, complex_matrix, herm_mul);
00095
00096 DEFBINOP_FN (lt, sparse_complex_matrix, complex_matrix, mx_el_lt)
00097 DEFBINOP_FN (le, sparse_complex_matrix, complex_matrix, mx_el_le)
00098 DEFBINOP_FN (eq, sparse_complex_matrix, complex_matrix, mx_el_eq)
00099 DEFBINOP_FN (ge, sparse_complex_matrix, complex_matrix, mx_el_ge)
00100 DEFBINOP_FN (gt, sparse_complex_matrix, complex_matrix, mx_el_gt)
00101 DEFBINOP_FN (ne, sparse_complex_matrix, complex_matrix, mx_el_ne)
00102
00103 DEFBINOP_FN (el_mul, sparse_complex_matrix, complex_matrix, product)
00104 DEFBINOP_FN (el_div, sparse_complex_matrix, complex_matrix, quotient)
00105
00106 DEFBINOP (el_pow, sparse_complex_matrix, complex_matrix)
00107 {
00108 CAST_BINOP_ARGS (const octave_sparse_complex_matrix&,
00109 const octave_complex_matrix&);
00110
00111 return octave_value
00112 (elem_xpow (v1.sparse_complex_matrix_value (), SparseComplexMatrix
00113 (v2.complex_matrix_value ())));
00114 }
00115
00116 DEFBINOP (el_ldiv, sparse_complex_matrix, matrix)
00117 {
00118 CAST_BINOP_ARGS (const octave_sparse_complex_matrix&,
00119 const octave_complex_matrix&);
00120
00121 return octave_value (quotient (v2.complex_matrix_value (),
00122 v1.sparse_complex_matrix_value ()));
00123 }
00124
00125 DEFBINOP_FN (el_and, sparse_complex_matrix, complex_matrix, mx_el_and)
00126 DEFBINOP_FN (el_or, sparse_complex_matrix, complex_matrix, mx_el_or)
00127
00128 DEFCATOP (scm_cm, sparse_complex_matrix, complex_matrix)
00129 {
00130 CAST_BINOP_ARGS (octave_sparse_complex_matrix&,
00131 const octave_complex_matrix&);
00132 SparseComplexMatrix tmp (v2.complex_matrix_value ());
00133 return octave_value
00134 (v1.sparse_complex_matrix_value (). concat (tmp, ra_idx));
00135 }
00136
00137 DEFASSIGNOP (assign, sparse_complex_matrix, complex_matrix)
00138 {
00139 CAST_BINOP_ARGS (octave_sparse_complex_matrix&,
00140 const octave_complex_matrix&);
00141
00142 SparseComplexMatrix tmp (v2.complex_matrix_value ());
00143 v1.assign (idx, tmp);
00144 return octave_value ();
00145 }
00146
00147 void
00148 install_scm_cm_ops (void)
00149 {
00150 INSTALL_BINOP (op_add, octave_sparse_complex_matrix,
00151 octave_complex_matrix, add);
00152 INSTALL_BINOP (op_sub, octave_sparse_complex_matrix,
00153 octave_complex_matrix, sub);
00154 INSTALL_BINOP (op_mul, octave_sparse_complex_matrix,
00155 octave_complex_matrix, mul);
00156 INSTALL_BINOP (op_div, octave_sparse_complex_matrix,
00157 octave_complex_matrix, div);
00158 INSTALL_BINOP (op_pow, octave_sparse_complex_matrix,
00159 octave_complex_matrix, pow);
00160 INSTALL_BINOP (op_ldiv, octave_sparse_complex_matrix,
00161 octave_complex_matrix, ldiv);
00162 INSTALL_BINOP (op_trans_mul, octave_sparse_complex_matrix,
00163 octave_complex_matrix, trans_mul);
00164 INSTALL_BINOP (op_herm_mul, octave_sparse_complex_matrix,
00165 octave_complex_matrix, herm_mul);
00166 INSTALL_BINOP (op_lt, octave_sparse_complex_matrix,
00167 octave_complex_matrix, lt);
00168 INSTALL_BINOP (op_le, octave_sparse_complex_matrix,
00169 octave_complex_matrix, le);
00170 INSTALL_BINOP (op_eq, octave_sparse_complex_matrix,
00171 octave_complex_matrix, eq);
00172 INSTALL_BINOP (op_ge, octave_sparse_complex_matrix,
00173 octave_complex_matrix, ge);
00174 INSTALL_BINOP (op_gt, octave_sparse_complex_matrix,
00175 octave_complex_matrix, gt);
00176 INSTALL_BINOP (op_ne, octave_sparse_complex_matrix,
00177 octave_complex_matrix, ne);
00178 INSTALL_BINOP (op_el_mul, octave_sparse_complex_matrix,
00179 octave_complex_matrix, el_mul);
00180 INSTALL_BINOP (op_el_div, octave_sparse_complex_matrix,
00181 octave_complex_matrix, el_div);
00182 INSTALL_BINOP (op_el_pow, octave_sparse_complex_matrix,
00183 octave_complex_matrix, el_pow);
00184 INSTALL_BINOP (op_el_ldiv, octave_sparse_complex_matrix,
00185 octave_complex_matrix, el_ldiv);
00186 INSTALL_BINOP (op_el_and, octave_sparse_complex_matrix,
00187 octave_complex_matrix, el_and);
00188 INSTALL_BINOP (op_el_or, octave_sparse_complex_matrix,
00189 octave_complex_matrix, el_or);
00190
00191 INSTALL_CATOP (octave_sparse_complex_matrix,
00192 octave_complex_matrix, scm_cm);
00193
00194 INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_complex_matrix,
00195 octave_complex_matrix, assign);
00196 }