op-sm-cs.cc

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 2004-2012 David Bateman
00004 Copyright (C) 1998-2004 Andy Adler
00005 
00006 This file is part of Octave.
00007 
00008 Octave is free software; you can redistribute it and/or modify it
00009 under the terms of the GNU General Public License as published by the
00010 Free Software Foundation; either version 3 of the License, or (at your
00011 option) any later version.
00012 
00013 Octave is distributed in the hope that it will be useful, but WITHOUT
00014 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00015 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00016 for more details.
00017 
00018 You should have received a copy of the GNU General Public License
00019 along with Octave; see the file COPYING.  If not, see
00020 <http://www.gnu.org/licenses/>.
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-complex.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 #include "ov-cx-sparse.h"
00040 #include "smx-sm-cs.h"
00041 #include "smx-cs-sm.h"
00042 
00043 // sparse matrix by scalar ops.
00044 
00045 DEFBINOP_OP (add, sparse_matrix, complex, +)
00046 DEFBINOP_OP (sub, sparse_matrix, complex, -)
00047 DEFBINOP_OP (mul, sparse_matrix, complex, *)
00048 
00049 DEFBINOP (div, sparse_matrix, complex)
00050 {
00051   CAST_BINOP_ARGS (const octave_sparse_matrix&, const octave_complex&);
00052 
00053   Complex d = v2.complex_value ();
00054   octave_value retval;
00055 
00056   if (d == 0.0)
00057     gripe_divide_by_zero ();
00058 
00059   retval = octave_value (v1.sparse_matrix_value () / d);
00060 
00061   return retval;
00062 }
00063 
00064 DEFBINOP (pow, sparse_matrix, complex)
00065 {
00066   CAST_BINOP_ARGS (const octave_sparse_matrix&, const octave_complex&);
00067   return xpow (v1.matrix_value (), v2.complex_value ());
00068 }
00069 
00070 DEFBINOP (ldiv, sparse_matrix, complex)
00071 {
00072   CAST_BINOP_ARGS (const octave_sparse_matrix&, const octave_complex&);
00073 
00074   if (v1.rows() == 1 && v1.columns() == 1)
00075     {
00076       double d = v1.scalar_value ();
00077 
00078       if (d == 0.0)
00079         gripe_divide_by_zero ();
00080 
00081       return octave_value (SparseComplexMatrix (1, 1, v2.complex_value () / d));
00082     }
00083   else
00084     {
00085       MatrixType typ = v1.matrix_type ();
00086       SparseMatrix m1 = v1.sparse_matrix_value ();
00087       ComplexMatrix m2 = ComplexMatrix (1, 1, v2.complex_value ());
00088       ComplexMatrix ret = xleftdiv (m1, m2, typ);
00089       v1.matrix_type (typ);
00090       return ret;
00091     }
00092 }
00093 
00094 DEFBINOP_FN (lt, sparse_matrix, complex, mx_el_lt)
00095 DEFBINOP_FN (le, sparse_matrix, complex, mx_el_le)
00096 DEFBINOP_FN (eq, sparse_matrix, complex, mx_el_eq)
00097 DEFBINOP_FN (ge, sparse_matrix, complex, mx_el_ge)
00098 DEFBINOP_FN (gt, sparse_matrix, complex, mx_el_gt)
00099 DEFBINOP_FN (ne, sparse_matrix, complex, mx_el_ne)
00100 
00101 DEFBINOP_OP (el_mul, sparse_matrix, complex, *)
00102 
00103 DEFBINOP (el_div, sparse_matrix, complex)
00104 {
00105   CAST_BINOP_ARGS (const octave_sparse_matrix&, const octave_complex&);
00106 
00107   Complex d = v2.complex_value ();
00108   octave_value retval;
00109 
00110   if (d == 0.0)
00111     gripe_divide_by_zero ();
00112 
00113   retval = octave_value (v1.sparse_matrix_value () / d);
00114 
00115   return retval;
00116 }
00117 
00118 DEFBINOP_FN (el_pow, sparse_matrix, complex, elem_xpow)
00119 
00120 DEFBINOP (el_ldiv, sparse_matrix, complex)
00121 {
00122   CAST_BINOP_ARGS (const octave_sparse_matrix&, const octave_complex&);
00123 
00124   return octave_value (x_el_div (v2.complex_value (),
00125                                  v1.sparse_matrix_value ()));
00126 }
00127 
00128 DEFBINOP_FN (el_and, sparse_matrix, complex, mx_el_and)
00129 DEFBINOP_FN (el_or, sparse_matrix, complex, mx_el_or)
00130 
00131 DEFCATOP (sm_cs, sparse_matrix, complex)
00132 {
00133   CAST_BINOP_ARGS (octave_sparse_matrix&, const octave_complex&);
00134   SparseComplexMatrix tmp (1, 1, v2.complex_value ());
00135   return octave_value (v1.sparse_matrix_value (). concat (tmp, ra_idx));
00136 }
00137 
00138 void
00139 install_sm_cs_ops (void)
00140 {
00141   INSTALL_BINOP (op_add, octave_sparse_matrix, octave_complex, add);
00142   INSTALL_BINOP (op_sub, octave_sparse_matrix, octave_complex, sub);
00143   INSTALL_BINOP (op_mul, octave_sparse_matrix, octave_complex, mul);
00144   INSTALL_BINOP (op_div, octave_sparse_matrix, octave_complex, div);
00145   INSTALL_BINOP (op_pow, octave_sparse_matrix, octave_complex, pow);
00146   INSTALL_BINOP (op_ldiv, octave_sparse_matrix, octave_complex, ldiv);
00147 
00148   INSTALL_BINOP (op_lt, octave_sparse_matrix, octave_complex, lt);
00149   INSTALL_BINOP (op_le, octave_sparse_matrix, octave_complex, le);
00150   INSTALL_BINOP (op_eq, octave_sparse_matrix, octave_complex, eq);
00151   INSTALL_BINOP (op_ge, octave_sparse_matrix, octave_complex, ge);
00152   INSTALL_BINOP (op_gt, octave_sparse_matrix, octave_complex, gt);
00153   INSTALL_BINOP (op_ne, octave_sparse_matrix, octave_complex, ne);
00154   INSTALL_BINOP (op_el_mul, octave_sparse_matrix, octave_complex, el_mul);
00155   INSTALL_BINOP (op_el_div, octave_sparse_matrix, octave_complex, el_div);
00156   INSTALL_BINOP (op_el_pow, octave_sparse_matrix, octave_complex, el_pow);
00157   INSTALL_BINOP (op_el_ldiv, octave_sparse_matrix, octave_complex, el_ldiv);
00158   INSTALL_BINOP (op_el_and, octave_sparse_matrix, octave_complex, el_and);
00159   INSTALL_BINOP (op_el_or, octave_sparse_matrix, octave_complex, el_or);
00160 
00161   INSTALL_CATOP (octave_sparse_matrix, octave_complex, sm_cs);
00162 
00163   INSTALL_ASSIGNCONV (octave_sparse_matrix, octave_complex,
00164                       octave_sparse_complex_matrix);
00165 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines