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