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