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