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