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