op-cm-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 "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 // complex matrix by sparse complex matrix ops.
00043 
00044 DEFBINOP_OP (add, complex_matrix, sparse_complex_matrix, +)
00045 DEFBINOP_OP (sub, complex_matrix, sparse_complex_matrix, -)
00046 
00047 DEFBINOP_OP (mul, complex_matrix, sparse_complex_matrix, *)
00048 
00049 DEFBINOP (div, complex_matrix, sparse_complex_matrix)
00050 {
00051   CAST_BINOP_ARGS (const octave_complex_matrix&,
00052                    const octave_sparse_complex_matrix&);
00053 
00054   if (v2.rows() == 1 && v2.columns() == 1)
00055     {
00056       Complex d = v2.complex_value ();
00057 
00058       if (d == 0.0)
00059         gripe_divide_by_zero ();
00060 
00061       return octave_value (v1.complex_array_value () / d);
00062     }
00063   else
00064     {
00065       MatrixType typ = v2.matrix_type ();
00066 
00067       ComplexMatrix ret = xdiv (v1.complex_matrix_value (),
00068                                 v2.sparse_complex_matrix_value (), typ);
00069 
00070       v2.matrix_type (typ);
00071       return ret;
00072     }
00073 }
00074 
00075 DEFBINOPX (pow, complex_matrix, sparse_complex_matrix)
00076 {
00077   error ("can't do A ^ B for A and B both matrices");
00078   return octave_value ();
00079 }
00080 
00081 DEFBINOP (ldiv, complex_matrix, sparse_complex_matrix)
00082 {
00083   CAST_BINOP_ARGS (const octave_complex_matrix&,
00084                    const octave_sparse_complex_matrix&);
00085   MatrixType typ = v1.matrix_type ();
00086 
00087   ComplexMatrix ret = xleftdiv (v1.complex_matrix_value (),
00088                                 v2.complex_matrix_value (), typ);
00089 
00090   v1.matrix_type (typ);
00091   return ret;
00092 }
00093 
00094 DEFBINOP_FN (mul_trans, complex_matrix, sparse_complex_matrix, mul_trans);
00095 DEFBINOP_FN (mul_herm, complex_matrix, sparse_complex_matrix, mul_herm);
00096 
00097 DEFBINOP_FN (lt, complex_matrix, sparse_complex_matrix, mx_el_lt)
00098 DEFBINOP_FN (le, complex_matrix, sparse_complex_matrix, mx_el_le)
00099 DEFBINOP_FN (eq, complex_matrix, sparse_complex_matrix, mx_el_eq)
00100 DEFBINOP_FN (ge, complex_matrix, sparse_complex_matrix, mx_el_ge)
00101 DEFBINOP_FN (gt, complex_matrix, sparse_complex_matrix, mx_el_gt)
00102 DEFBINOP_FN (ne, complex_matrix, sparse_complex_matrix, mx_el_ne)
00103 
00104 DEFBINOP_FN (el_mul, complex_matrix, sparse_complex_matrix, product)
00105 DEFBINOP_FN (el_div, complex_matrix, sparse_complex_matrix, quotient)
00106 
00107 DEFBINOP (el_pow, complex_matrix, sparse_complex_matrix)
00108 {
00109   CAST_BINOP_ARGS (const octave_complex_matrix&,
00110                    const octave_sparse_complex_matrix&);
00111 
00112   return octave_value
00113     (elem_xpow (SparseComplexMatrix (v1.complex_matrix_value ()),
00114                 v2.sparse_complex_matrix_value ()));
00115 }
00116 
00117 DEFBINOP (el_ldiv, sparse_complex_matrix, matrix)
00118 {
00119   CAST_BINOP_ARGS (const octave_complex_matrix&,
00120                    const octave_sparse_complex_matrix&);
00121 
00122   return octave_value (quotient (v2.sparse_complex_matrix_value (),
00123                                  v1.complex_matrix_value ()));
00124 }
00125 
00126 DEFBINOP_FN (el_and, complex_matrix, sparse_complex_matrix, mx_el_and)
00127 DEFBINOP_FN (el_or,  complex_matrix, sparse_complex_matrix, mx_el_or)
00128 
00129 DEFCATOP (cm_scm, complex_matrix, sparse_complex_matrix)
00130 {
00131   CAST_BINOP_ARGS (octave_complex_matrix&,
00132                    const octave_sparse_complex_matrix&);
00133   SparseComplexMatrix tmp (v1.complex_matrix_value ());
00134   return octave_value (tmp. concat (v2.sparse_complex_matrix_value (),
00135                                     ra_idx));
00136 }
00137 
00138 DEFCONV (sparse_complex_matrix_conv, complex_matrix,
00139          sparse_complex_matrix)
00140 {
00141   CAST_CONV_ARG (const octave_complex_matrix&);
00142   return new octave_sparse_complex_matrix
00143     (SparseComplexMatrix (v.complex_matrix_value ()));
00144 }
00145 
00146 DEFNDASSIGNOP_FN (assign, complex_matrix, sparse_complex_matrix,
00147                   complex_array, assign)
00148 
00149 void
00150 install_cm_scm_ops (void)
00151 {
00152   INSTALL_BINOP (op_add, octave_complex_matrix,
00153                  octave_sparse_complex_matrix, add);
00154   INSTALL_BINOP (op_sub, octave_complex_matrix,
00155                  octave_sparse_complex_matrix, sub);
00156   INSTALL_BINOP (op_mul, octave_complex_matrix,
00157                  octave_sparse_complex_matrix, mul);
00158   INSTALL_BINOP (op_div, octave_complex_matrix,
00159                  octave_sparse_complex_matrix, div);
00160   INSTALL_BINOP (op_pow, octave_complex_matrix,
00161                  octave_sparse_complex_matrix, pow);
00162   INSTALL_BINOP (op_ldiv, octave_complex_matrix,
00163                  octave_sparse_complex_matrix, ldiv);
00164   INSTALL_BINOP (op_mul_trans, octave_complex_matrix,
00165                  octave_sparse_complex_matrix, mul_trans);
00166   INSTALL_BINOP (op_mul_herm, octave_complex_matrix,
00167                  octave_sparse_complex_matrix, mul_herm);
00168   INSTALL_BINOP (op_lt, octave_complex_matrix,
00169                  octave_sparse_complex_matrix, lt);
00170   INSTALL_BINOP (op_le, octave_complex_matrix,
00171                  octave_sparse_complex_matrix, le);
00172   INSTALL_BINOP (op_eq, octave_complex_matrix,
00173                  octave_sparse_complex_matrix, eq);
00174   INSTALL_BINOP (op_ge, octave_complex_matrix,
00175                  octave_sparse_complex_matrix, ge);
00176   INSTALL_BINOP (op_gt, octave_complex_matrix,
00177                  octave_sparse_complex_matrix, gt);
00178   INSTALL_BINOP (op_ne, octave_complex_matrix,
00179                  octave_sparse_complex_matrix, ne);
00180   INSTALL_BINOP (op_el_mul, octave_complex_matrix,
00181                  octave_sparse_complex_matrix, el_mul);
00182   INSTALL_BINOP (op_el_div, octave_complex_matrix,
00183                  octave_sparse_complex_matrix, el_div);
00184   INSTALL_BINOP (op_el_pow, octave_complex_matrix,
00185                  octave_sparse_complex_matrix, el_pow);
00186   INSTALL_BINOP (op_el_ldiv, octave_complex_matrix,
00187                  octave_sparse_complex_matrix, el_ldiv);
00188   INSTALL_BINOP (op_el_and, octave_complex_matrix,
00189                  octave_sparse_complex_matrix, el_and);
00190   INSTALL_BINOP (op_el_or, octave_complex_matrix,
00191                  octave_sparse_complex_matrix, el_or);
00192 
00193   INSTALL_CATOP (octave_complex_matrix,
00194                  octave_sparse_complex_matrix, cm_scm);
00195 
00196   INSTALL_ASSIGNOP (op_asn_eq, octave_complex_matrix,
00197                     octave_sparse_complex_matrix, assign)
00198   INSTALL_ASSIGNCONV (octave_complex_matrix, octave_sparse_complex_matrix,
00199                       octave_complex_matrix);
00200 
00201   INSTALL_WIDENOP (octave_complex_matrix, octave_sparse_complex_matrix,
00202                    sparse_complex_matrix_conv);
00203 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines