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