op-scm-scm.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-null-mat.h"
00033 #include "ops.h"
00034 
00035 #include "sparse-xdiv.h"
00036 #include "sparse-xpow.h"
00037 #include "ov-re-sparse.h"
00038 #include "ov-cx-sparse.h"
00039 
00040 #ifdef HAVE_CONFIG_H
00041 #include <config.h>
00042 #endif
00043 
00044 #include "gripes.h"
00045 #include "oct-obj.h"
00046 #include "ov.h"
00047 #include "ov-cx-mat.h"
00048 #include "ov-typeinfo.h"
00049 #include "ops.h"
00050 #include "xdiv.h"
00051 #include "xpow.h"
00052 
00053 // unary sparse complex matrix ops.
00054 
00055 DEFUNOP_OP (not, sparse_complex_matrix, !)
00056 DEFUNOP_OP (uplus, sparse_complex_matrix, /* no-op */)
00057 DEFUNOP_OP (uminus, sparse_complex_matrix, -)
00058 
00059 DEFUNOP (transpose, sparse_complex_matrix)
00060 {
00061   CAST_UNOP_ARG (const octave_sparse_complex_matrix&);
00062   return octave_value
00063     (v.sparse_complex_matrix_value().transpose (),
00064      v.matrix_type ().transpose ());
00065 }
00066 
00067 DEFUNOP (hermitian, sparse_complex_matrix)
00068 {
00069   CAST_UNOP_ARG (const octave_sparse_complex_matrix&);
00070   return octave_value
00071     (v.sparse_complex_matrix_value().hermitian (),
00072      v.matrix_type ().transpose ());
00073 }
00074 
00075 #if 0
00076 DEFUNOP (incr, sparse_complex_matrix)
00077 {
00078   CAST_UNOP_ARG (const octave_sparse_complex_matrix&);
00079 
00080   return octave_value (v.complex_matrix_value () .increment ());
00081 }
00082 
00083 DEFUNOP (decr, sparse_complex_matrix)
00084 {
00085   CAST_UNOP_ARG (const octave_sparse_complex_matrix&);
00086 
00087   return octave_value (v.complex_matrix_value () .decrement ());
00088 }
00089 #endif
00090 
00091 // complex matrix by complex matrix ops.
00092 
00093 DEFBINOP_OP (add, sparse_complex_matrix, sparse_complex_matrix, +)
00094 DEFBINOP_OP (sub, sparse_complex_matrix, sparse_complex_matrix, -)
00095 
00096 DEFBINOP_OP (mul, sparse_complex_matrix, sparse_complex_matrix, *)
00097 
00098 DEFBINOP (div, sparse_complex_matrix, sparse_complex_matrix)
00099 {
00100   CAST_BINOP_ARGS (const octave_sparse_complex_matrix&,
00101                    const octave_sparse_complex_matrix&);
00102 
00103   if (v2.rows() == 1 && v2.columns() == 1)
00104     {
00105       Complex d = v2.complex_value ();
00106 
00107       if (d == 0.0)
00108         gripe_divide_by_zero ();
00109 
00110       return octave_value (v1.sparse_complex_matrix_value () / d);
00111     }
00112   else
00113     {
00114       MatrixType typ = v2.matrix_type ();
00115       SparseComplexMatrix ret = xdiv (v1.sparse_complex_matrix_value (),
00116                                       v2.sparse_complex_matrix_value (), typ);
00117 
00118       v2.matrix_type (typ);
00119       return ret;
00120     }
00121 }
00122 
00123 DEFBINOPX (pow, sparse_complex_matrix, sparse_complex_matrix)
00124 {
00125   error ("can't do A ^ B for A and B both matrices");
00126   return octave_value ();
00127 }
00128 
00129 DEFBINOP (ldiv, sparse_complex_matrix, sparse_complex_matrix)
00130 {
00131   CAST_BINOP_ARGS (const octave_sparse_complex_matrix&,
00132                    const octave_sparse_complex_matrix&);
00133 
00134   if (v1.rows() == 1 && v1.columns() == 1)
00135     {
00136       Complex d = v1.complex_value ();
00137 
00138       if (d == 0.0)
00139         gripe_divide_by_zero ();
00140 
00141       return octave_value (v2.sparse_complex_matrix_value () / d);
00142     }
00143   else
00144     {
00145       MatrixType typ = v1.matrix_type ();
00146 
00147       SparseComplexMatrix ret =
00148         xleftdiv (v1.sparse_complex_matrix_value (),
00149                   v2.sparse_complex_matrix_value (), typ);
00150 
00151       v1.matrix_type (typ);
00152       return ret;
00153     }
00154 }
00155 
00156 DEFBINOP_FN (lt, sparse_complex_matrix, sparse_complex_matrix, mx_el_lt)
00157 DEFBINOP_FN (le, sparse_complex_matrix, sparse_complex_matrix, mx_el_le)
00158 DEFBINOP_FN (eq, sparse_complex_matrix, sparse_complex_matrix, mx_el_eq)
00159 DEFBINOP_FN (ge, sparse_complex_matrix, sparse_complex_matrix, mx_el_ge)
00160 DEFBINOP_FN (gt, sparse_complex_matrix, sparse_complex_matrix, mx_el_gt)
00161 DEFBINOP_FN (ne, sparse_complex_matrix, sparse_complex_matrix, mx_el_ne)
00162 
00163 DEFBINOP_FN (el_mul, sparse_complex_matrix, sparse_complex_matrix, product)
00164 DEFBINOP_FN (el_div, sparse_complex_matrix, sparse_complex_matrix, quotient)
00165 DEFBINOP_FN (el_pow, sparse_complex_matrix, sparse_complex_matrix, elem_xpow)
00166 
00167 DEFBINOP (el_ldiv, sparse_complex_matrix, sparse_complex_matrix)
00168 {
00169   CAST_BINOP_ARGS (const octave_sparse_complex_matrix&,
00170                    const octave_sparse_complex_matrix&);
00171 
00172   return octave_value (quotient (v2.sparse_complex_matrix_value (),
00173                                  v1.sparse_complex_matrix_value ()));
00174 }
00175 
00176 DEFBINOP_FN (el_and, sparse_complex_matrix, sparse_complex_matrix, mx_el_and)
00177 DEFBINOP_FN (el_or,  sparse_complex_matrix, sparse_complex_matrix, mx_el_or)
00178 
00179 DEFCATOP_FN (scm_scm, sparse_complex_matrix, sparse_complex_matrix, concat)
00180 
00181 DEFASSIGNOP_FN (assign, sparse_complex_matrix, sparse_complex_matrix, assign)
00182 
00183 DEFNULLASSIGNOP_FN (null_assign, sparse_complex_matrix, delete_elements)
00184 
00185 void
00186 install_scm_scm_ops (void)
00187 {
00188   INSTALL_UNOP (op_not, octave_sparse_complex_matrix, not);
00189   INSTALL_UNOP (op_uplus, octave_sparse_complex_matrix, uplus);
00190   INSTALL_UNOP (op_uminus, octave_sparse_complex_matrix, uminus);
00191   INSTALL_UNOP (op_transpose, octave_sparse_complex_matrix, transpose);
00192   INSTALL_UNOP (op_hermitian, octave_sparse_complex_matrix, hermitian);
00193 
00194 #if 0
00195   INSTALL_NCUNOP (op_incr, octave_sparse_complex_matrix, incr);
00196   INSTALL_NCUNOP (op_decr, octave_sparse_complex_matrix, decr);
00197 #endif
00198 
00199   INSTALL_BINOP (op_add, octave_sparse_complex_matrix,
00200                  octave_sparse_complex_matrix, add);
00201   INSTALL_BINOP (op_sub, octave_sparse_complex_matrix,
00202                  octave_sparse_complex_matrix, sub);
00203   INSTALL_BINOP (op_mul, octave_sparse_complex_matrix,
00204                  octave_sparse_complex_matrix, mul);
00205   INSTALL_BINOP (op_div, octave_sparse_complex_matrix,
00206                  octave_sparse_complex_matrix, div);
00207   INSTALL_BINOP (op_pow, octave_sparse_complex_matrix,
00208                  octave_sparse_complex_matrix, pow);
00209   INSTALL_BINOP (op_ldiv, octave_sparse_complex_matrix,
00210                  octave_sparse_complex_matrix, ldiv);
00211   INSTALL_BINOP (op_lt, octave_sparse_complex_matrix,
00212                  octave_sparse_complex_matrix, lt);
00213   INSTALL_BINOP (op_le, octave_sparse_complex_matrix,
00214                  octave_sparse_complex_matrix, le);
00215   INSTALL_BINOP (op_eq, octave_sparse_complex_matrix,
00216                  octave_sparse_complex_matrix, eq);
00217   INSTALL_BINOP (op_ge, octave_sparse_complex_matrix,
00218                  octave_sparse_complex_matrix, ge);
00219   INSTALL_BINOP (op_gt, octave_sparse_complex_matrix,
00220                  octave_sparse_complex_matrix, gt);
00221   INSTALL_BINOP (op_ne, octave_sparse_complex_matrix,
00222                  octave_sparse_complex_matrix, ne);
00223   INSTALL_BINOP (op_el_mul, octave_sparse_complex_matrix,
00224                  octave_sparse_complex_matrix, el_mul);
00225   INSTALL_BINOP (op_el_div, octave_sparse_complex_matrix,
00226                  octave_sparse_complex_matrix, el_div);
00227   INSTALL_BINOP (op_el_pow, octave_sparse_complex_matrix,
00228                  octave_sparse_complex_matrix, el_pow);
00229   INSTALL_BINOP (op_el_ldiv, octave_sparse_complex_matrix,
00230                  octave_sparse_complex_matrix, el_ldiv);
00231   INSTALL_BINOP (op_el_and, octave_sparse_complex_matrix,
00232                  octave_sparse_complex_matrix, el_and);
00233   INSTALL_BINOP (op_el_or, octave_sparse_complex_matrix,
00234                  octave_sparse_complex_matrix, el_or);
00235 
00236   INSTALL_CATOP (octave_sparse_complex_matrix,
00237                  octave_sparse_complex_matrix, scm_scm);
00238 
00239   INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_complex_matrix,
00240                     octave_sparse_complex_matrix, assign);
00241 
00242   INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_complex_matrix,
00243                     octave_null_matrix, null_assign);
00244   INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_complex_matrix,
00245                     octave_null_str, null_assign);
00246   INSTALL_ASSIGNOP (op_asn_eq, octave_sparse_complex_matrix,
00247                     octave_null_sq_str, null_assign);
00248 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines