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