op-pm-scm.cc

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 2009-2012 Jason Riedy
00004 
00005 This file is part of Octave.
00006 
00007 Octave is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 3 of the License, or (at your
00010 option) any later version.
00011 
00012 Octave is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Octave; see the file COPYING.  If not, see
00019 <http://www.gnu.org/licenses/>.
00020 
00021 */
00022 
00023 #ifdef HAVE_CONFIG_H
00024 #include <config.h>
00025 #endif
00026 
00027 #include "gripes.h"
00028 #include "oct-obj.h"
00029 #include "ov.h"
00030 #include "ov-typeinfo.h"
00031 #include "ops.h"
00032 
00033 #include "ov-perm.h"
00034 #include "ov-cx-sparse.h"
00035 
00036 // permutation matrix by sparse matrix ops
00037 
00038 DEFBINOP (mul_pm_scm, perm_matrix, sparse_complex_matrix)
00039 {
00040   CAST_BINOP_ARGS (const octave_perm_matrix&, const octave_sparse_complex_matrix&);
00041 
00042   if (v2.rows() == 1 && v2.columns() == 1)
00043     {
00044       std::complex<double> d = v2.complex_value ();
00045 
00046       return octave_value (v1.sparse_matrix_value () * d);
00047     }
00048   else if (v1.rows() == 1 && v1.columns() == 1)
00049     return octave_value (v2.sparse_complex_matrix_value ());
00050   else
00051     return v1.perm_matrix_value  () * v2.sparse_complex_matrix_value ();
00052 }
00053 
00054 DEFBINOP (ldiv_pm_scm, perm_matrix, sparse_complex_matrix)
00055 {
00056   CAST_BINOP_ARGS (const octave_perm_matrix&, const octave_sparse_complex_matrix&);
00057 
00058   return v1.perm_matrix_value ().inverse () * v2.sparse_complex_matrix_value ();
00059 }
00060 
00061 // sparse matrix by diagonal matrix ops
00062 
00063 DEFBINOP (mul_scm_pm, sparse_complex_matrix, perm_matrix)
00064 {
00065   CAST_BINOP_ARGS (const octave_sparse_complex_matrix&, const octave_perm_matrix&);
00066 
00067   if (v1.rows() == 1 && v1.columns() == 1)
00068     {
00069       std::complex<double> d = v1.scalar_value ();
00070 
00071       return octave_value (d * v2.sparse_matrix_value ());
00072     }
00073   else if (v2.rows() == 1 && v2.columns() == 1)
00074     return octave_value (v1.sparse_complex_matrix_value ());
00075   else
00076     return v1.sparse_complex_matrix_value  () * v2.perm_matrix_value ();
00077 }
00078 
00079 DEFBINOP (div_scm_pm, sparse_complex_matrix, perm_matrix)
00080 {
00081   CAST_BINOP_ARGS (const octave_sparse_complex_matrix&, const octave_perm_matrix&);
00082 
00083   return v1.sparse_complex_matrix_value () * v2.perm_matrix_value ().inverse ();
00084 }
00085 
00086 void
00087 install_pm_scm_ops (void)
00088 {
00089   INSTALL_BINOP (op_mul, octave_perm_matrix, octave_sparse_complex_matrix,
00090                  mul_pm_scm);
00091   INSTALL_BINOP (op_ldiv, octave_perm_matrix, octave_sparse_complex_matrix,
00092                  ldiv_pm_scm);
00093   INSTALL_BINOP (op_mul, octave_sparse_complex_matrix, octave_perm_matrix,
00094                  mul_scm_pm);
00095   INSTALL_BINOP (op_div, octave_sparse_complex_matrix, octave_perm_matrix,
00096                  div_scm_pm);
00097 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines