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