op-scm-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-scm-cm.h"
00039 #include "smx-cm-scm.h"
00040 #include "ov-cx-sparse.h"
00041 
00042 // sparse complex matrix by complex matrix ops.
00043 
00044 DEFBINOP_OP (add, sparse_complex_matrix, complex_matrix, +)
00045 DEFBINOP_OP (sub, sparse_complex_matrix, complex_matrix, -)
00046 
00047 DEFBINOP_OP (mul, sparse_complex_matrix, complex_matrix, *)
00048 
00049 DEFBINOP (div, sparse_complex_matrix, complex_matrix)
00050 {
00051   CAST_BINOP_ARGS (const octave_sparse_complex_matrix&,
00052                    const octave_complex_matrix&);
00053   MatrixType typ = v2.matrix_type ();
00054 
00055   ComplexMatrix ret = xdiv (v1.complex_matrix_value (),
00056                             v2.complex_matrix_value (), typ);
00057 
00058   v2.matrix_type (typ);
00059   return ret;
00060 }
00061 
00062 DEFBINOPX (pow, sparse_complex_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_complex_matrix, complex_matrix)
00069 {
00070   CAST_BINOP_ARGS (const octave_sparse_complex_matrix&, const octave_complex_matrix&);
00071 
00072   if (v1.rows() == 1 && v1.columns() == 1)
00073     {
00074       Complex d = v1.complex_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_complex_matrix_value (),
00086                       v2.complex_matrix_value (), typ);
00087 
00088       v1.matrix_type (typ);
00089       return ret;
00090     }
00091 }
00092 
00093 DEFBINOP_FN (trans_mul, sparse_complex_matrix, complex_matrix, trans_mul);
00094 DEFBINOP_FN (herm_mul, sparse_complex_matrix, complex_matrix, herm_mul);
00095 
00096 DEFBINOP_FN (lt, sparse_complex_matrix, complex_matrix, mx_el_lt)
00097 DEFBINOP_FN (le, sparse_complex_matrix, complex_matrix, mx_el_le)
00098 DEFBINOP_FN (eq, sparse_complex_matrix, complex_matrix, mx_el_eq)
00099 DEFBINOP_FN (ge, sparse_complex_matrix, complex_matrix, mx_el_ge)
00100 DEFBINOP_FN (gt, sparse_complex_matrix, complex_matrix, mx_el_gt)
00101 DEFBINOP_FN (ne, sparse_complex_matrix, complex_matrix, mx_el_ne)
00102 
00103 DEFBINOP_FN (el_mul, sparse_complex_matrix, complex_matrix, product)
00104 DEFBINOP_FN (el_div, sparse_complex_matrix, complex_matrix, quotient)
00105 
00106 DEFBINOP (el_pow, sparse_complex_matrix, complex_matrix)
00107 {
00108   CAST_BINOP_ARGS (const octave_sparse_complex_matrix&,
00109                    const octave_complex_matrix&);
00110 
00111   return octave_value
00112     (elem_xpow (v1.sparse_complex_matrix_value (), SparseComplexMatrix
00113                 (v2.complex_matrix_value ())));
00114 }
00115 
00116 DEFBINOP (el_ldiv, sparse_complex_matrix, matrix)
00117 {
00118   CAST_BINOP_ARGS (const octave_sparse_complex_matrix&,
00119                    const octave_complex_matrix&);
00120 
00121   return octave_value (quotient (v2.complex_matrix_value (),
00122                                  v1.sparse_complex_matrix_value ()));
00123 }
00124 
00125 DEFBINOP_FN (el_and, sparse_complex_matrix, complex_matrix, mx_el_and)
00126 DEFBINOP_FN (el_or,  sparse_complex_matrix, complex_matrix, mx_el_or)
00127 
00128 DEFCATOP (scm_cm, sparse_complex_matrix, complex_matrix)
00129 {
00130   CAST_BINOP_ARGS (octave_sparse_complex_matrix&,
00131                    const octave_complex_matrix&);
00132   SparseComplexMatrix tmp (v2.complex_matrix_value ());
00133   return octave_value
00134     (v1.sparse_complex_matrix_value (). concat (tmp, ra_idx));
00135 }
00136 
00137 DEFASSIGNOP (assign, sparse_complex_matrix, complex_matrix)
00138 {
00139   CAST_BINOP_ARGS (octave_sparse_complex_matrix&,
00140                    const octave_complex_matrix&);
00141 
00142   SparseComplexMatrix tmp (v2.complex_matrix_value ());
00143   v1.assign (idx, tmp);
00144   return octave_value ();
00145 }
00146 
00147 void
00148 install_scm_cm_ops (void)
00149 {
00150   INSTALL_BINOP (op_add, octave_sparse_complex_matrix,
00151                  octave_complex_matrix, add);
00152   INSTALL_BINOP (op_sub, octave_sparse_complex_matrix,
00153                  octave_complex_matrix, sub);
00154   INSTALL_BINOP (op_mul, octave_sparse_complex_matrix,
00155                  octave_complex_matrix, mul);
00156   INSTALL_BINOP (op_div, octave_sparse_complex_matrix,
00157                  octave_complex_matrix, div);
00158   INSTALL_BINOP (op_pow, octave_sparse_complex_matrix,
00159                  octave_complex_matrix, pow);
00160   INSTALL_BINOP (op_ldiv, octave_sparse_complex_matrix,
00161                  octave_complex_matrix, ldiv);
00162   INSTALL_BINOP (op_trans_mul, octave_sparse_complex_matrix,
00163                  octave_complex_matrix, trans_mul);
00164   INSTALL_BINOP (op_herm_mul, octave_sparse_complex_matrix,
00165                  octave_complex_matrix, herm_mul);
00166   INSTALL_BINOP (op_lt, octave_sparse_complex_matrix,
00167                  octave_complex_matrix, lt);
00168   INSTALL_BINOP (op_le, octave_sparse_complex_matrix,
00169                  octave_complex_matrix, le);
00170   INSTALL_BINOP (op_eq, octave_sparse_complex_matrix,
00171                  octave_complex_matrix, eq);
00172   INSTALL_BINOP (op_ge, octave_sparse_complex_matrix,
00173                  octave_complex_matrix, ge);
00174   INSTALL_BINOP (op_gt, octave_sparse_complex_matrix,
00175                  octave_complex_matrix, gt);
00176   INSTALL_BINOP (op_ne, octave_sparse_complex_matrix,
00177                  octave_complex_matrix, ne);
00178   INSTALL_BINOP (op_el_mul, octave_sparse_complex_matrix,
00179                  octave_complex_matrix, el_mul);
00180   INSTALL_BINOP (op_el_div, octave_sparse_complex_matrix,
00181                  octave_complex_matrix, el_div);
00182   INSTALL_BINOP (op_el_pow, octave_sparse_complex_matrix,
00183                  octave_complex_matrix, el_pow);
00184   INSTALL_BINOP (op_el_ldiv, octave_sparse_complex_matrix,
00185                  octave_complex_matrix, el_ldiv);
00186   INSTALL_BINOP (op_el_and, octave_sparse_complex_matrix,
00187                  octave_complex_matrix, el_and);
00188   INSTALL_BINOP (op_el_or, octave_sparse_complex_matrix,
00189                  octave_complex_matrix, el_or);
00190 
00191   INSTALL_CATOP (octave_sparse_complex_matrix,
00192                  octave_complex_matrix, scm_cm);
00193 
00194   INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_complex_matrix,
00195                     octave_complex_matrix, assign);
00196 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines