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