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